本文整理汇总了C++中NDArray::dim1方法的典型用法代码示例。如果您正苦于以下问题:C++ NDArray::dim1方法的具体用法?C++ NDArray::dim1怎么用?C++ NDArray::dim1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NDArray
的用法示例。
在下文中一共展示了NDArray::dim1方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wrap
/**
* Converts an Octave numeric NDArray into a double R array.
*
* Currently only 3D arrays are supported.
*/
inline SEXP wrap(const NDArray& x){
int nd = x.ndims();
VERBOSE_LOG("(%iD-NDArray)", nd);
if( nd > 3 ){
std::ostringstream err;
err << "<NDArray> - Could not convert NDArray[" << x.ndims() << "]: only up to 3 dimensions are supported";
WRAP_ERROR(err.str().c_str());
}else if( nd == 2 ){// safe-guard in case of a 2D-NDArray (i.e. a Matrix object)
VERBOSE_LOG(" = ");
return wrap(x.as_matrix()) ;
}
// copy values from the outer to inner dimensions
int n = x.dim1();
int p = x.dim2();
int q = x.dim3();
VERBOSE_LOG("[%i x %i x %i]", n, p, q);
Rcpp::NumericVector res( Rcpp::Dimension(n, p, q) );
Rcpp::NumericVector::iterator z = res.begin();
for(int k=0; k<q; k++){
for(int j=0; j<p; j++){
for(int i=0; i<n; i++){
*z = x.elem(i,j,k);
z++;
}
}
}
return res;
}
示例2: wrap
/**
* Converts an Octave numeric NDArray into a double R array.
*
* Currently only 3D arrays are supported.
*/
inline SEXP wrap(const NDArray& x){
VERBOSE_LOG("(NDArray) -> Array");
if( x.ndims() > 3 ){
std::ostringstream err;
err << "<NDArray> - Could not convert NDArray[" << x.ndims() << "]: only up to 3 dimensions are supported";
WRAP_ERROR(err.str().c_str());
}
// copy values from the outer to inner dimensions
int n = x.dim1();
int p = x.dim2();
int q = x.dim3();
Rcpp::NumericVector res( Rcpp::Dimension(n, p, q) );
Rcpp::NumericVector::iterator z = res.begin();
for(int k=0; k<q; k++){
for(int j=0; j<p; j++){
for(int i=0; i<n; i++){
*z = x.elem(i,j,k);
z++;
}
}
}
return res;
}