本文整理汇总了C++中BaseArray::getNumElems方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseArray::getNumElems方法的具体用法?C++ BaseArray::getNumElems怎么用?C++ BaseArray::getNumElems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseArray
的用法示例。
在下文中一共展示了BaseArray::getNumElems方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: divide_array
void divide_array(const BaseArray<T>& inputArray, const T &b, BaseArray<T>& outputArray)
{
size_t nelems = inputArray.getNumElems();
if (outputArray.getNumElems() != nelems)
{
outputArray.setDims(inputArray.getDims());
}
const T* data = inputArray.getData();
T* aim = outputArray.getData();
std::transform(data, data + nelems, aim, std::bind2nd(std::divides<T>(), b));
}
示例2: create_array_from_shape
void create_array_from_shape(const spec_type& sp,BaseArray<T>& s,BaseArray<T>& d)
{
//alocate target array
vector<size_t> shape;
vector<size_t>::const_iterator iter;
for(iter = (sp.first).begin();iter!=(sp.first).end();++iter)
{
if(*iter!=0)
shape.push_back(*iter);
}
d.setDims(shape);
//Check if the dimension of passed indices match the dimension of target array
if(sp.second.size()!=s.getNumDims())
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match");
T* data = new T[d.getNumElems()];
idx_type::const_iterator spec_iter;
//calc number of indeces
size_t n =1;
for(spec_iter = sp.second.begin();spec_iter!=sp.second.end();++spec_iter)
{
n*=spec_iter->size();
}
size_t k =0;
size_t index=0;
vector<size_t>::const_iterator indeces_iter;
//initialize target array with elements of source array using passed indices
vector<size_t> idx;
for(int i=0;i<n;i++)
{
spec_iter = sp.second.begin();
for(int dim=0;dim<s.getNumDims();dim++)
{
size_t idx1 = getNextIndex(*spec_iter,i);
idx.push_back(idx1);
spec_iter++;
}
if(index>(d.getNumElems()-1))
{
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match");
}
data[index] = s(idx);
idx.clear();
index++;
}
//assign elemets to target array
d.assign( data );
delete [] data;
}
示例3: subtract_array_scalar
void subtract_array_scalar(const BaseArray<T>& inputArray, T b, BaseArray<T>& outputArray)
{
size_t dim = inputArray.getNumElems();
if(dim > 0)
{
outputArray.setDims(inputArray.getDims());
const T* data = inputArray.getData();
T* aim = outputArray.getData();
std::transform (data, data + inputArray.getNumElems(),
aim, std::bind2nd(std::minus<T>(), b));
}
}
示例4: pow_array_scalar
void pow_array_scalar(const BaseArray<double> &inputArray, T exponent,
BaseArray<double> &outputArray)
{
size_t nelems = inputArray.getNumElems();
if (outputArray.getNumElems() != nelems)
outputArray.setDims(inputArray.getDims());
const double *data = inputArray.getData();
double *dest = outputArray.getData();
double *end = dest + nelems;
while (dest != end)
*dest++ = pow(*data++, exponent);
}
示例5: multiply_array
void multiply_array(const BaseArray<T>& inputArray, const T &b, BaseArray<T>& outputArray)
{
size_t dim = inputArray.getNumElems();
if(dim > 0)
{
outputArray.setDims(inputArray.getDims());
const T* data = inputArray.getData();
T* aim = outputArray.getData();
std::transform (data, data + inputArray.getNumElems(),
aim, std::bind2nd(std::multiplies<T>(), b));
}
};
示例6: make_pair
std::pair<T,T> min_max(const BaseArray<T>& x)
{
const T* data = x.getData();
std::pair<const T*, const T*>
ret = minmax_element(data, data + x.getNumElems());
return std::make_pair(*(ret.first), *(ret.second));
}
示例7: add_array
void add_array(const BaseArray<T>& leftArray, const BaseArray<T>& rightArray, BaseArray<T>& resultArray)
{
size_t dimLeft = leftArray.getNumElems();
size_t dimRight = rightArray.getNumElems();
if(dimLeft != dimRight)
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Right and left array must have the same size for element wise addition");
resultArray.setDims(leftArray.getDims());
const T* data1 = leftArray.getData();
const T* data2 = rightArray.getData();
T* aim = resultArray.getData();
std::transform(data1, data1 + leftArray.getNumElems(), data2, aim, std::plus<T>());
}
示例8: multiply_array_elem_wise
void multiply_array_elem_wise(const BaseArray<T> &leftArray, const BaseArray<T> &rightArray, BaseArray<T> &resultArray)
{
size_t dimLeft = leftArray.getNumElems();
size_t dimRight = rightArray.getNumElems();
if(dimLeft != dimRight)
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Right and left array must have the same size for element wise multiplication");
resultArray.setDims(leftArray.getDims());
const T* leftData = leftArray.getData();
const T* rightData = rightArray.getData();
T* aim = resultArray.getData();
std::transform (leftData, leftData + leftArray.getNumElems(), rightData, aim, std::multiplies<T>());
}
示例9: cast_array
void cast_array(const BaseArray<S>& a, BaseArray<T>& b)
{
b.setDims(a.getDims());
int numElems = a.getNumElems();
const S* src_data = a.getData();
T* dst_data = b.getData();
for (int i = 0; i < numElems; i++)
*dst_data++ = (T)(*src_data++);
}
示例10: usub_array
void usub_array(const BaseArray<T>& a, BaseArray<T>& b)
{
b.setDims(a.getDims());
size_t numEle = a.getNumElems();
for (size_t i = 1; i <= numEle; i++)
{
b(i) = -a(i);
}
}
示例11: dot_array
T dot_array(const BaseArray<T>& a, const BaseArray<T>& b)
{
if(a.getNumDims() != 1 || b.getNumDims() != 1)
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"error in dot array function. Wrong dimension");
const T* data1 = a.getData();
const T* data2 = b.getData();
T r = std::inner_product(data1, data1 + a.getNumElems(), data2, 0.0);
return r;
}
示例12: sum_array
T sum_array (const BaseArray<T>& x)
{
const T* data = x.getData();
T val = std::accumulate(data, data + x.getNumElems(), T());
return val;
}
示例13: fill_array
void fill_array(BaseArray<T>& inputArray, T b)
{
T* data = inputArray.getData();
std::fill(data, data + inputArray.getNumElems(), b);
}