Commit ff04c296 authored by David Moxey's avatar David Moxey

Merge branch 'fix/python3' into 'master'

python: format tabs to spaces

See merge request !989
parents 0044af2b 4700e650
Pipeline #525 passed with stage
in 0 seconds
......@@ -6,27 +6,27 @@ import gc
import sys
def main():
session_name = ["memory-test-python-to-c-address.py", "newsquare_2x2.xml"]
session_name = ["memory-test-python-to-c-address.py", "newsquare_2x2.xml"]
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
coords = exp.GetCoords()
coords = coords[0]
coords = exp.GetCoords()
coords = coords[0]
coords_data_address = str(hex(coords.ctypes.data)).rstrip('L')
coords_data_address = str(hex(coords.ctypes.data)).rstrip('L')
print "The memory address of data is: {}\n".format(coords_data_address)
print( "The memory address of data is: {}\n".format(coords_data_address))
exp.SetPhysArray(coords)
phys_data_address = exp.GetPhysAddress()
print "The memory address of array data is: {}\n".format(phys_data_address)
exp.SetPhysArray(coords)
phys_data_address = exp.GetPhysAddress()
print( "The memory address of array data is: {}\n".format(phys_data_address))
if coords_data_address == phys_data_address:
print("Test successful!")
else:
print("Test unsuccessful")
if coords_data_address == phys_data_address:
print("Test successful!")
else:
print("Test unsuccessful")
if __name__ == '__main__':
main()
......@@ -7,51 +7,51 @@ import sys
import numpy as np
def get_refcount(coords_address):
gc.collect()
return ctypes.c_long.from_address(coords_address).value
gc.collect()
return ctypes.c_long.from_address(coords_address).value
def main():
session_name = ["memory-test-python-to-c-address.py", "newsquare_2x2.xml"]
expected_test_outcome = [1, 2, 1, -9.187094450483263e-15]
actual_test_outcome = []
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d\n" % graph.GetMeshDimension())
print("Retrieving coordinates...")
coords = exp.GetCoords()
coords_subs = coords[1]
coords = coords[0]
coords_address = id(coords)
print("Retrieved coordinates.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Setting PhysArray (exp.SetPhysArray())...")
exp.SetPhysArray(coords)
print("exp.SetPhysArray() completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Substituting the coordinates in m_phys...")
exp.SetPhysArray(coords_subs)
print("Substitution completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Attempting to access the coordinates in Python...")
print("The sum of coordinates array entires is: %r" % sum(coords))
actual_test_outcome.append(sum(coords))
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
session_name = ["memory-test-python-to-c-address.py", "newsquare_2x2.xml"]
expected_test_outcome = [1, 2, 1, -9.187094450483263e-15]
actual_test_outcome = []
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d\n" % graph.GetMeshDimension())
print("Retrieving coordinates...")
coords = exp.GetCoords()
coords_subs = coords[1]
coords = coords[0]
coords_address = id(coords)
print("Retrieved coordinates.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Setting PhysArray (exp.SetPhysArray())...")
exp.SetPhysArray(coords)
print("exp.SetPhysArray() completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Substituting the coordinates in m_phys...")
exp.SetPhysArray(coords_subs)
print("Substitution completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Attempting to access the coordinates in Python...")
print("The sum of coordinates array entires is: %r" % sum(coords))
actual_test_outcome.append(sum(coords))
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
if __name__ == '__main__':
main()
......@@ -7,54 +7,54 @@ import sys
import numpy as np
def get_refcount(coords_address):
gc.collect()
return ctypes.c_long.from_address(coords_address).value
gc.collect()
return ctypes.c_long.from_address(coords_address).value
def main():
session_name = ["NekPy_ReferenceTest_PythonDeleteFirst.py", "newsquare_2x2.xml"]
expected_test_outcome = [1, 2, 1, 3.469446951953614e-17]
actual_test_outcome = []
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d\n" % graph.GetMeshDimension())
print("Retrieving coordinates...")
coords = exp.GetCoords()
coords = coords[0]
coords_address = id(coords)
print("Retrieved coordinates.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Setting PhysArray (exp.SetPhysArray())...")
exp.SetPhysArray(coords)
print("exp.SetPhysArray() completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Deleting coordinates in Python...")
del coords
print("Coordinates deleted in Python.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
# Ensure we are in PhysState to avoid ASSERT inside ExpList.
exp.SetPhysState(True)
print("Attempting to calculate the integral...")
print("Integral calculated to be: %r" % exp.PhysIntegral())
actual_test_outcome.append(exp.PhysIntegral())
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
session_name = ["NekPy_ReferenceTest_PythonDeleteFirst.py", "newsquare_2x2.xml"]
expected_test_outcome = [1, 2, 1, 3.469446951953614e-17]
actual_test_outcome = []
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d\n" % graph.GetMeshDimension())
print("Retrieving coordinates...")
coords = exp.GetCoords()
coords = coords[0]
coords_address = id(coords)
print("Retrieved coordinates.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Setting PhysArray (exp.SetPhysArray())...")
exp.SetPhysArray(coords)
print("exp.SetPhysArray() completed.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
print("Deleting coordinates in Python...")
del coords
print("Coordinates deleted in Python.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
# Ensure we are in PhysState to avoid ASSERT inside ExpList.
exp.SetPhysState(True)
print("Attempting to calculate the integral...")
print("Integral calculated to be: %r" % exp.PhysIntegral())
actual_test_outcome.append(exp.PhysIntegral())
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment