本文整理汇总了C++中DataArray::appendData方法的典型用法代码示例。如果您正苦于以下问题:C++ DataArray::appendData方法的具体用法?C++ DataArray::appendData怎么用?C++ DataArray::appendData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataArray
的用法示例。
在下文中一共展示了DataArray::appendData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testData
//.........这里部分代码省略.........
array2.setData(D, nix::NDSize({ 20, 20 }));
array2D_type E(boost::extents[1][1]);
array2.getData(E, nix::NDSize({ 5, 5 }), nix::NDSize({ 20, 20 }));
for(index i = 0; i != 5; ++i)
for(index j = 0; j != 5; ++j)
CPPUNIT_ASSERT_DOUBLES_EQUAL(D[i][j], E[i][j],
std::numeric_limits<double>::epsilon());
array2D_type F(boost::extents[5][5]);
array2.getData(F, nix::NDSize({ 20, 20 }));
for(index i = 0; i != 5; ++i)
for(index j = 0; j != 5; ++j)
CPPUNIT_ASSERT_DOUBLES_EQUAL(D[i][j], F[i][j],
std::numeric_limits<double>::epsilon());
nix::DataArray da3 = block.createDataArray("direct-vector",
"double",
nix::DataType::Double,
nix::NDSize({5}));
CPPUNIT_ASSERT(da3.dataExtent() == nix::NDSize{5});
CPPUNIT_ASSERT(da3.getDimension(1) == false);
std::vector<double> dv = {1.0, 2.0, 3.0, 4.0, 5.0};
da3.setData(nix::DataType::Double, dv.data(), nix::NDSize({ 5 }), nix::NDSize({ 0 }));
std::vector<double> dvin;
dvin.resize(5);
da3.getData(nix::DataType::Double, dvin.data(), nix::NDSize({ 5 }), nix::NDSize({ 0 }));
for(size_t i = 0; i < dvin.size(); i++) {
CPPUNIT_ASSERT_DOUBLES_EQUAL(dv[i], dvin[i],
std::numeric_limits<double>::epsilon());
}
// test IO of a scalar
double scalar = -1.0;
//value + offset + count
// nix::NDSize({}) indicates a scalar
scalar = -1.0;
da3.getData(scalar, nix::NDSize({}), nix::NDSize({0}));
CPPUNIT_ASSERT_DOUBLES_EQUAL(dv[0], scalar,
std::numeric_limits<double>::epsilon());
// nix::NDSize({1, 1, ..., 1}) has a number of elemts == 1
// so that should work too
scalar = -1.0;
da3.getData(scalar, nix::NDSize({1}), nix::NDSize({0}));
CPPUNIT_ASSERT_DOUBLES_EQUAL(dv[0], scalar,
std::numeric_limits<double>::epsilon());
scalar = -1.0;
da3.getData(scalar, nix::NDSize({1, 1}), nix::NDSize({0}));
CPPUNIT_ASSERT_DOUBLES_EQUAL(dv[0], scalar,
std::numeric_limits<double>::epsilon());
//value + offset
scalar = -1.0;
da3.getData(scalar, nix::NDSize({0}));
CPPUNIT_ASSERT_DOUBLES_EQUAL(dv[0], scalar,
std::numeric_limits<double>::epsilon());
//TODO: setData(scalar) + getData(scalar)
DataArray daA = block.createDataArray("append", "double", DataType::Double , NDSize({0, 4, 5}));
CPPUNIT_ASSERT_THROW(daA.appendData(DataType::Double, nullptr, NDSize({2, 4, 5}), 3), InvalidRank);
CPPUNIT_ASSERT_THROW(daA.appendData(DataType::Double, nullptr, NDSize({2, 4, 5, 6}), 0), IncompatibleDimensions);
CPPUNIT_ASSERT_THROW(daA.appendData(DataType::Double, nullptr, NDSize({4, 4, 6}), 0), IncompatibleDimensions);
std::vector<double> append_data(3*4*5, 1);
daA.appendData(DataType::Double, append_data.data(), {3, 4, 5}, 0);
CPPUNIT_ASSERT_EQUAL(NDSize({3, 4, 5}), daA.dataExtent());
std::fill(append_data.begin(), append_data.end(), 2);
daA.appendData(DataType::Double, append_data.data(), {3, 4, 5}, 0);
CPPUNIT_ASSERT_EQUAL(NDSize({6, 4, 5}), daA.dataExtent());
std::vector<double> append_check(6*4*5, 0);
daA.getData(DataType::Double, append_check.data(), {6, 4, 5}, {});
for(size_t i = 0; i < 6*4*5; i++) {
CPPUNIT_ASSERT_EQUAL(i > 3*4*5-1 ? 2.0 : 1.0, append_check[i]);
}
}