本文整理汇总了C++中ARRAY::shape方法的典型用法代码示例。如果您正苦于以下问题:C++ ARRAY::shape方法的具体用法?C++ ARRAY::shape怎么用?C++ ARRAY::shape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARRAY
的用法示例。
在下文中一共展示了ARRAY::shape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printArray
void printArray(const ARRAY& a, std::string indent="") {
std::ostringstream out(std::ostringstream::out);
StringStyle style = MatrixStyle;
typedef int coordinate_type;
typedef typename ARRAY::const_iterator const_iterator;
if(style == MatrixStyle) {
if(a.actual_dimension == 0) {
// scalar
out << "A = " << a(0) << std::endl;
}
else if(a.actual_dimension == 1) {
// vector
out << "A = (";
for(size_t j=0; j<a.size(); ++j) {
out << a(j) << ", ";
}
out << "\b\b)" << std::endl;
}
else if(a.actual_dimension == 2) {
// matrix
if(true /* coordinateOrder_ == FirstMajorOrder */) {
out << "A(r,c) =" << std::endl;
for(size_t y=0; y<a.shape(0); ++y) {
for(size_t x=0; x<a.shape(1); ++x) {
out << a(y, x) << ' ';
}
out << std::endl;
}
}
else {
out << "A(c,r) =" << std::endl;
for(size_t y=0; y<a.shape(1); ++y) {
for(size_t x=0; x<a.shape(0); ++x) {
out << a(x, y) << ' ';
}
out << std::endl;
}
}
}
else {
// higher dimensional
typename ARRAY::difference_type c1;
unsigned short q = 2;
if(true /* coordinateOrder_ == FirstMajorOrder */) {
q = a.actual_dimension-3;
}
int i = 0;
for(const_iterator it = a.begin(); it != a.end(); ++it, ++i) {
typename ARRAY::difference_type c2 = a.scanOrderIndexToCoordinate(i);
if(i == 0 || c2[q] != c1[q]) {
if(i != 0) {
out << std::endl << std::endl;
}
if(true /* coordinateOrder_ == FirstMajorOrder */) {
out << "A(";
for(size_t j=0; j<static_cast<size_t>(a.actual_dimension-2); ++j) {
out << c2[j] << ",";
}
}
else {
out << "A(c,r,";
for(size_t j=2; j<a.actual_dimension; ++j) {
out << c2[j] << ",";
}
}
out << '\b';
if(true /* coordinateOrder_ == FirstMajorOrder */) {
out << ",r,c";
}
out << ") =" << std::endl;
}
else if(c2[1] != c1[1]) {
out << std::endl;
}
out << *it << " ";
c1 = c2;
}
out << std::endl;
}
out << std::endl;
}
else if(style == TableStyle) {
if(a.actual_dimension == 0) {
// scalar
out << "A = " << a(0) << std::endl;
}
else {
// non-scalar
int j = 0;
for(const_iterator it = a.begin(); it != a.end(); ++it, ++j) {
out << "A(";
typename ARRAY::difference_type c = a.scanOrderIndexToCoordinate(j);
for(size_t j=0; j<c.size(); ++j) {
out << c[j] << ',';
}
out << "\b) = " << *it << std::endl;
}
//.........这里部分代码省略.........