Commit 98c7f465 authored by Kenneth Leiter's avatar Kenneth Leiter

BUG: Fix insert stride issue with XdmfArray found by Andrew.

XdmfArray stride was used incorrectly to calculate new size of array when
stride was larger than 1.
Add test to ensure that this will continue to work.
parent 4f7ac2f6
......@@ -368,10 +368,8 @@ public:
void
operator()(const shared_ptr<std::vector<T> > & array) const
{
unsigned int size = mStartIndex + mNumValues;
if(mArrayStride > 1) {
size = mStartIndex + mNumValues * mArrayStride - 1;
}
const unsigned int size =
mStartIndex + (mNumValues - 1) * mArrayStride + 1;
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......
......@@ -263,10 +263,8 @@ public:
void
operator()(shared_ptr<std::vector<std::string> > & array) const
{
unsigned int size = mStartIndex + mNumValues;
if(mArrayStride > 1) {
size = mStartIndex + mNumValues * mArrayStride - 1;
}
const unsigned int size =
mStartIndex + (mNumValues - 1) * mArrayStride + 1;
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......@@ -282,10 +280,8 @@ public:
void
operator()(shared_ptr<std::vector<U> > & array) const
{
unsigned int size = mStartIndex + mNumValues;
if(mArrayStride > 1) {
size = mStartIndex + mNumValues * mArrayStride - 1;
}
const unsigned int size =
mStartIndex + (mNumValues - 1) * mArrayStride + 1;
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......@@ -348,10 +344,8 @@ public:
void
operator()(shared_ptr<std::vector<std::string> > & array) const
{
unsigned int size = mStartIndex + mNumValues;
if(mArrayStride > 1) {
size = mStartIndex + mNumValues * mArrayStride - 1;
}
const unsigned int size =
mStartIndex + (mNumValues - 1) * mArrayStride + 1;
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......@@ -366,10 +360,8 @@ public:
void
operator()(shared_ptr<std::vector<U> > & array) const
{
unsigned int size = mStartIndex + mNumValues;
if(mArrayStride > 1) {
size = mStartIndex + mNumValues * mArrayStride - 1;
}
const unsigned int size =
mStartIndex + (mNumValues - 1) * mArrayStride + 1;
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......
......@@ -19,6 +19,7 @@ ADD_TEST_CXX_PATH("${XDMF_BINARIES}")
# Read UseCxxTest.cmake for more information
# ---------------------------------------
ADD_TEST_CXX(TestXdmfArray)
ADD_TEST_CXX(TestXdmfArrayInsert)
ADD_TEST_CXX(TestXdmfArrayMultidimensional)
ADD_TEST_CXX(TestXdmfArrayWriteRead)
ADD_TEST_CXX(TestXdmfArrayWriteReadHyperSlabs)
......@@ -37,6 +38,7 @@ ADD_TEST_CXX(TestXdmfVersion)
# Read UseCxxTest.cmake for more information
# ---------------------------------------
CLEAN_TEST_CXX(TestXdmfArray)
CLEAN_TEST_CXX(TestXdmfArrayInsert)
CLEAN_TEST_CXX(TestXdmfArrayMultidimensional)
CLEAN_TEST_CXX(TestXdmfArrayWriteRead
test.h5,
......
#include "XdmfArray.hpp"
int main(int, char **)
{
// Insert from another array
shared_ptr<XdmfArray> array1 = XdmfArray::New();
shared_ptr<XdmfArray> insertArray1 = XdmfArray::New();
shared_ptr<XdmfArray> insertArray2 = XdmfArray::New();
shared_ptr<XdmfArray> insertArray3 = XdmfArray::New();
shared_ptr<XdmfArray> insertArray4 = XdmfArray::New();
insertArray1->resize<int>(10, 1);
insertArray2->resize<int>(10, 2);
insertArray3->resize<int>(10, 3);
insertArray4->resize<int>(10, 4);
array1->insert(0, insertArray1, 0, 10, 4, 1);
array1->insert(1, insertArray2, 0, 10, 4, 1);
array1->insert(2, insertArray3, 0, 10, 4, 1);
array1->insert(3, insertArray4, 0, 10, 4, 1);
assert(array1->getValuesString().compare("1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 "
"2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 "
"3 4 1 2 3 4") == 0);
// Insert from vector
std::vector<int> insertArray5(10, 1);
std::vector<int> insertArray6(10, 2);
std::vector<int> insertArray7(10, 3);
std::vector<int> insertArray8(10, 4);
shared_ptr<XdmfArray> array2 = XdmfArray::New();
array2->insert(0, &(insertArray5[0]), 10, 4, 1);
array2->insert(1, &(insertArray6[0]), 10, 4, 1);
array2->insert(2, &(insertArray7[0]), 10, 4, 1);
array2->insert(3, &(insertArray8[0]), 10, 4, 1);
assert(array2->getValuesString().compare("1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 "
"2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 "
"3 4 1 2 3 4") == 0);
// Insert from vector string
std::vector<std::string> insertArray9(10, "1");
std::vector<std::string> insertArray10(10, "2");
std::vector<std::string> insertArray11(10, "3");
std::vector<std::string> insertArray12(10, "4");
shared_ptr<XdmfArray> array3 = XdmfArray::New();
array3->insert(0, &(insertArray9[0]), 10, 4, 1);
array3->insert(1, &(insertArray10[0]), 10, 4, 1);
array3->insert(2, &(insertArray11[0]), 10, 4, 1);
array3->insert(3, &(insertArray12[0]), 10, 4, 1);
assert(array3->getValuesString().compare("1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 "
"2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 "
"3 4 1 2 3 4") == 0);
return 0;
}
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