本文整理汇总了C++中DataArray::dataType方法的典型用法代码示例。如果您正苦于以下问题:C++ DataArray::dataType方法的具体用法?C++ DataArray::dataType怎么用?C++ DataArray::dataType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataArray
的用法示例。
在下文中一共展示了DataArray::dataType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testData
void BaseTestDataArray::testData() {
typedef boost::multi_array<double, 3> array_type;
typedef array_type::index index;
array_type A(boost::extents[3][4][2]);
int values = 0;
for(index i = 0; i != 3; ++i)
for(index j = 0; j != 4; ++j)
for(index k = 0; k != 2; ++k)
A[i][j][k] = values++;
CPPUNIT_ASSERT_EQUAL(array1.dataType(), nix::DataType::Double);
CPPUNIT_ASSERT_EQUAL(array1.dataExtent(), nix::NDSize({0, 0, 0}));
CPPUNIT_ASSERT(array1.getDimension(1) == false);
array1.setData(A);
array_type B(boost::extents[1][1][1]);
array1.getData(B);
int verify = 0;
int errors = 0;
for(index i = 0; i != 3; ++i) {
for(index j = 0; j != 4; ++j) {
for(index k = 0; k != 2; ++k) {
int v = verify++;
errors += B[i][j][k] != v;
}
}
}
CPPUNIT_ASSERT_EQUAL(errors, 0);
DataArray direct = block.createDataArray("da_direct", "double", A);
array_type Adirect(boost::extents[3][4][2]);
direct.getData(Adirect);
errors = 0;
verify = 0;
for(index i = 0; i != 3; ++i) {
for(index j = 0; j != 4; ++j) {
for(index k = 0; k != 2; ++k) {
int v = verify++;
errors += Adirect[i][j][k] != v;
}
}
}
CPPUNIT_ASSERT_EQUAL(0, errors);
//test createDataArray overload that takes data but specify an storage datat type
DataArray directFloat = block.createDataArray("da_direct_int", "int", A, DataType::Int32);
CPPUNIT_ASSERT_EQUAL(DataType::Int32, directFloat.dataType());
boost::multi_array<int, 3> AdirectFloat(boost::extents[3][4][2]);
direct.getData(AdirectFloat);
errors = 0;
verify = 0;
for(index i = 0; i != 3; ++i) {
for(index j = 0; j != 4; ++j) {
for(index k = 0; k != 2; ++k) {
int v = verify++;
errors += AdirectFloat[i][j][k] != v;
}
}
}
CPPUNIT_ASSERT_EQUAL(0, errors);
typedef boost::multi_array<double, 2> array2D_type;
typedef array_type::index index;
array2D_type C(boost::extents[5][5]);
for(index i = 0; i != 5; ++i)
for(index j = 0; j != 5; ++j)
C[i][j] = 42.0;
CPPUNIT_ASSERT_EQUAL(array2.dataExtent(), nix::NDSize({20, 20}));
array2.setData(C, nix::NDSize({0, 0}));
array2.dataExtent(nix::NDSize({40, 40}));
CPPUNIT_ASSERT_EQUAL(array2.dataExtent(), nix::NDSize({40, 40}));
array2D_type D(boost::extents[5][5]);
for(index i = 0; i != 5; ++i)
for(index j = 0; j != 5; ++j)
D[i][j] = 42.0;
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());
//.........这里部分代码省略.........