本文整理汇总了C++中ArrayHandle::dims方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayHandle::dims方法的具体用法?C++ ArrayHandle::dims怎么用?C++ ArrayHandle::dims使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHandle
的用法示例。
在下文中一共展示了ArrayHandle::dims方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
/**
* @brief This function transposes a matrix represented by a 2-D array
* @param args[0] The input matrix
* return The transposed matrix
**/
AnyType lda_transpose::run(AnyType & args)
{
ArrayHandle<int64_t> matrix = args[0].getAs<ArrayHandle<int64_t> >();
if(matrix.dims() != 2)
throw std::domain_error("invalid dimension");
int32_t row_num = static_cast<int32_t>(matrix.sizeOfDim(0));
int32_t col_num = static_cast<int32_t>(matrix.sizeOfDim(1));
int dims[2] = {col_num, row_num};
int lbs[2] = {1, 1};
MutableArrayHandle<int64_t> transposed(
madlib_construct_md_array(
NULL, NULL, 2, dims, lbs, INT8TI.oid, INT8TI.len, INT8TI.byval,
INT8TI.align));
for(int32_t i = 0; i < row_num; i++){
int32_t index = i * col_num;
for(int32_t j = 0; j < col_num; j++){
transposed[j * row_num + i] = matrix[index];
index++;
}
}
return transposed;
}
示例2: run
AnyType matrix_mem_trans::run(AnyType & args)
{
ArrayHandle<double> m = args[0].getAs<ArrayHandle<double> >();
if (m.dims() != 2){
throw std::invalid_argument(
"invalid argument - 2-d array expected");
}
int row_m = static_cast<int>(m.sizeOfDim(0));
int col_m = static_cast<int>(m.sizeOfDim(1));
int dims[2] = {col_m, row_m};
int lbs[2] = {1, 1};
MutableArrayHandle<double> r = madlib_construct_md_array(
NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
for (int i = 0; i < row_m; i++){
for(int j = 0; j < col_m; j++){
*(r.ptr() + j * row_m + i) = *(m.ptr() + i * col_m + j);
}
}
return r;
}
示例3: invalid_argument
/**
* @brief The function is used for the initlization of the SRF. The SRF unnests
* a 2-D array into a set of 1-D arrays.
**/
void * lda_unnest::SRF_init(AnyType &args)
{
ArrayHandle<int64_t> inarray = args[0].getAs<ArrayHandle<int64_t> >();
if(inarray.dims() != 2)
throw std::invalid_argument("invalid dimension");
sr_ctx * ctx = new sr_ctx;
ctx->inarray = inarray.ptr();
ctx->maxcall = static_cast<int32_t>(inarray.sizeOfDim(0));
ctx->dim = static_cast<int32_t>(inarray.sizeOfDim(1));
ctx->curcall = 0;
return ctx;
}