An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit f25f6927 authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

ENH: Add Python test for new multidimensional array handling. Add typemap for...

ENH: Add Python test for new multidimensional array handling. Add typemap for swig for the std::vector<unsigned int> necessary for dimensions.
parent e5f0a642
......@@ -349,4 +349,5 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
%template(UIntVector) std::vector<unsigned int>;
%template(ItemVector) std::vector<boost::shared_ptr<XdmfItem> >;
......@@ -23,6 +23,7 @@ ADD_TEST_PYTHON_PATH("${LIBXML2_BINARY_DIRS}")
# Read UsePythonTest.cmake for more information
# ---------------------
ADD_TEST_PYTHON(TestXdmfArray)
ADD_TEST_PYTHON(TestXdmfArrayMultidimensional)
ADD_TEST_PYTHON(TestXdmfEquals)
ADD_TEST_PYTHON(TestXdmfVersion)
......@@ -32,6 +33,7 @@ ADD_TEST_PYTHON(TestXdmfVersion)
# Read UseCxxTest.cmake for more information
# ---------------------------------------
CLEAN_TEST_PYTHON(TestXdmfArray)
CLEAN_TEST_PYTHON(TestXdmfArrayMultidimensional)
CLEAN_TEST_PYTHON(TestXdmfEquals)
CLEAN_TEST_PYTHON(TestXdmfVersion)
......
from XdmfCore import *
if __name__ == "__main__":
#
# Create 1D arrays
#
array1 = XdmfArray.New()
array1.initialize(XdmfArrayType.UInt32(), 2)
assert array1.getArrayType() == XdmfArrayType.UInt32()
assert array1.getSize() == 2
dimensions = array1.getDimensions()
assert dimensions.size() == 1
assert dimensions[0] == 2
dimensionsString = array1.getDimensionsString()
assert dimensionsString == "2"
array1.resizeAsInt32(3)
assert array1.getSize() == 3
dimensions = array1.getDimensions()
assert dimensions.size() == 1
assert dimensions[0] == 3
#
# Create 2D arrays
#
array2 = XdmfArray.New()
newDimensions = UIntVector(2, 2)
array2.initialize(XdmfArrayType.UInt16(), newDimensions)
assert array2.getArrayType() == XdmfArrayType.UInt16()
assert array2.getSize() == 4
dimensions = array2.getDimensions()
assert dimensions.size() == 2
assert dimensions[0] == 2 and dimensions[1] == 2
dimensionsString = array2.getDimensionsString()
assert dimensionsString == "2 2"
newDimensions = UIntVector(3, 3)
array2.resizeAsUInt16(newDimensions)
assert array2.getSize() == 27
dimensions = array2.getDimensions()
assert dimensions.size() == 3
assert dimensions[0] == 3 and dimensions[1] == 3 and dimensions[2] == 3
dimensionsString = array2.getDimensionsString()
assert dimensionsString == "3 3 3"
values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
array2.insertAsUInt16(0, values)
assert array2.getSize() == 27
dimensions = array2.getDimensions()
assert dimensions.size() == 3
assert dimensions[0] == 3 and dimensions[1] == 3 and dimensions[2] == 3
array2.pushBackAsInt16(10)
assert array2.getSize() == 28
dimensions = array2.getDimensions()
assert dimensions.size() == 1
assert dimensions[0] == 28
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