本文整理汇总了C++中BaseArray::getDim方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseArray::getDim方法的具体用法?C++ BaseArray::getDim怎么用?C++ BaseArray::getDim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseArray
的用法示例。
在下文中一共展示了BaseArray::getDim方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertArrayDim
static void convertArrayDim(size_t dim,
const BaseArray<S> &s, vector<size_t> &sidx,
BaseArray<T> &d, vector<size_t> &didx) {
size_t ndims = s.getNumDims();
size_t size = s.getDim(dim);
for (size_t i = 1; i <= size; i++) {
didx[ndims - dim] = sidx[dim - 1] = i;
if (dim < sidx.size())
convertArrayDim(dim + 1, s, sidx, d, didx);
else
d(didx) = s(sidx);
}
}
示例2: assignRowMajorDim
static size_t assignRowMajorDim(size_t dim, const T* data,
BaseArray<T> &array, vector<size_t> &idx) {
size_t processed = 0;
size_t size = array.getDim(dim);
for (size_t i = 1; i <= size; i++) {
idx[dim - 1] = i;
if (dim < idx.size())
processed += assignRowMajorDim(dim + 1, data + processed, array, idx);
else
array(idx) = data[processed++];
}
return processed;
}
示例3: transpose_array
void transpose_array(const BaseArray<T>& x, BaseArray<T>& a)
{
size_t ndims = x.getNumDims();
if(ndims < 2 || ndims != a.getNumDims())
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Wrong dimensions in transpose_array");
vector<size_t> ex = x.getDims();
std::swap(ex[0], ex[1]);
a.setDims(ex);
vector<Slice> sx(ndims);
vector<Slice> sa(ndims);
for (int i = 1; i <= x.getDim(1); i++) {
sa[1] = sx[0] = Slice(i);
ArraySlice<T>(a, sa).assign(ArraySliceConst<T>(x, sx));
}
}
示例4: multiply_array
void multiply_array(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray)
{
size_t leftNumDims = leftArray.getNumDims();
size_t rightNumDims = rightArray.getNumDims();
size_t matchDim = rightArray.getDim(1);
resultArray.setDims(leftArray.getDims());
if (leftArray.getDim(leftNumDims) != matchDim)
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Wrong sizes in multiply_array");
if (leftNumDims == 1 && rightNumDims == 2) {
size_t rightDim = rightArray.getDim(2);
for (size_t j = 1; j <= rightDim; j++) {
T val = T();
for (size_t k = 1; k <= matchDim; k++)
val += leftArray(k) * rightArray(k, j);
resultArray(j) = val;
}
}
else if (leftNumDims == 2 && rightNumDims == 1) {
size_t leftDim = leftArray.getDim(1);
for (size_t i = 1; i <= leftDim; i++) {
T val = T();
for (size_t k = 1; k <= matchDim; k++)
val += leftArray(i, k) * rightArray(k);
resultArray(i) = val;
}
}
else if (leftNumDims == 2 && rightNumDims == 2) {
size_t leftDim = leftArray.getDim(1);
size_t rightDim = rightArray.getDim(2);
for (size_t i = 1; i <= leftDim; i++) {
for (size_t j = 1; j <= rightDim; j++) {
T val = T();
for (size_t k = 1; k <= matchDim; k++)
val += leftArray(i, k) * rightArray(k, j);
resultArray(i, j) = val;
}
}
}
else
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Unsupported dimensions in multiply_array");
}