本文整理汇总了C++中BaseArray类的典型用法代码示例。如果您正苦于以下问题:C++ BaseArray类的具体用法?C++ BaseArray怎么用?C++ BaseArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: min_max
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));
}
示例2: 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());
}
示例3: 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++);
}
示例4: BaseSprite
BaseSprite *AdActor::getTalkStance(const char *stance) {
// forced stance?
if (_forcedTalkAnimName && !_forcedTalkAnimUsed) {
_forcedTalkAnimUsed = true;
delete _animSprite;
_animSprite = new BaseSprite(_gameRef, this);
if (_animSprite) {
bool res = _animSprite->loadFile(_forcedTalkAnimName);
if (DID_FAIL(res)) {
_gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName);
delete _animSprite;
_animSprite = nullptr;
} else {
return _animSprite;
}
}
}
// old way
if (_talkSprites.size() > 0 || _talkSpritesEx.size() > 0) {
return getTalkStanceOld(stance);
}
// new way
BaseSprite *ret = nullptr;
// do we have an animation with this name?
AdSpriteSet *anim = getAnimByName(stance);
if (anim) {
ret = anim->getSprite(_dir);
}
// not - get a random talk
if (!ret) {
BaseArray<AdSpriteSet *> talkAnims;
for (uint32 i = 0; i < _anims.size(); i++) {
if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) {
talkAnims.add(_anims[i]);
}
}
if (talkAnims.size() > 0) {
int rnd = BaseEngine::instance().randInt(0, talkAnims.size() - 1);
ret = talkAnims[rnd]->getSprite(_dir);
} else {
if (_standSprite) {
ret = _standSprite->getSprite(_dir);
} else {
anim = getAnimByName(_idleAnimName);
if (anim) {
ret = anim->getSprite(_dir);
}
}
}
}
return ret;
}
示例5: 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);
}
}
示例6: 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;
}
示例7: convertArrayLayout
void convertArrayLayout(const BaseArray<S> &s, BaseArray<T> &d) {
size_t ndims = s.getNumDims();
if (ndims != d.getNumDims())
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,
"Wrong dimensions in convertArrayLayout");
vector<size_t> sdims = s.getDims();
vector<size_t> ddims(ndims);
for (size_t dim = 1; dim <= ndims; dim++)
ddims[ndims - dim] = sdims[dim - 1];
d.resize(ddims);
convertArrayDim(1, s, sdims, d, ddims);
}
示例8: 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);
}
}
示例9: 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));
}
}
示例10: RemoveSequentialValues
//-----------------------------------------------------------------------------
EStatus BaseArray::Remove (INT iStartIndex,
INT iNumToRemove)
{
if (iLength == 0) return (EStatus::kFailure);
RemoveSequentialValues (iStartIndex, iNumToRemove);
// update siblings
BaseArray * pCurr = pNext;
while (pCurr != this)
{
pCurr->Remove (iStartIndex, iNumToRemove);
pCurr = pCurr->pNext;
};
return (EStatus::kSuccess);
};
示例11: 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");
}
示例12: getObjects
bool AdResponseBox::getObjects(BaseArray<UIObject *> &objects, bool interactiveOnly) {
for (uint32 i = 0; i < _respButtons.size(); i++) {
objects.add(_respButtons[i]);
}
if (_window) {
_window->getWindowObjects(objects, interactiveOnly);
}
return STATUS_OK;
}
示例13: fill_array_from_shape
void fill_array_from_shape(const spec_type& sp,BaseArray<T>& s,BaseArray<T>& d)
{
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;
}
示例14: 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;
}
示例15: DBG_INFO
//-----------------------------------------------------------------------------
EStatus BaseArray::Insert (INT iStartIndex,
INT iNumToInsert,
BOOL bDebug)
{
// This routine inserts new entries before the iStartIndex.
INT iStartIndexActual = iStartIndex;
// perform the insertion on the actual sequential data
INT iOldLength = iLength;
if (iStartIndexActual > iLength) return (EStatus::kFailure);
if (SetLength (iOldLength + iNumToInsert) == EStatus::kFailure) {return EStatus::kFailure;};
if (Length () < (iOldLength + iNumToInsert) ) {return EStatus::kFailure;};
if (bDebug)
{
DBG_INFO ("BA:Ins %d old:%d cur:%d\n", iStartIndexActual, iOldLength, Length ());
};
//printf ("start index %d old length %d\n", iStartIndexActual,iOldLength);
if ((iStartIndexActual != iLength) && (iOldLength - iStartIndexActual > 0))
{
//DBG_INFO ("Copy values rev %d %d %d\n", iStartIndexActual, iStartIndexActual + iNumToInsert, iOldLength - iStartIndexActual);
CopyValuesRev (pArray, iStartIndexActual, iStartIndexActual + iNumToInsert, iOldLength - iStartIndexActual);
};
// update siblings
BaseArray * pCurr = pNext;
while (pCurr != this)
{
pCurr->Insert (iStartIndex, iNumToInsert);
pCurr = pCurr->pNext;
};
return (EStatus::kSuccess);
};