本文整理汇总了C++中BaseArray::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseArray::assign方法的具体用法?C++ BaseArray::assign怎么用?C++ BaseArray::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseArray
的用法示例。
在下文中一共展示了BaseArray::assign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: promote_array
void promote_array(size_t n, const BaseArray<T>& s, BaseArray<T>& d)
{
vector<size_t> ex = s.getDims();
for (int i=0; i<n; i++)
ex.push_back(1);
d.setDims(ex);
d.assign(s.getData());
}
示例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;
}