Example #1
0
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));
}
Example #2
0
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());
}
Example #3
0
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++);
}
Example #4
0
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;
}
Example #5
0
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);
  }
}
Example #6
0
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;
}
Example #7
0
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);
}
Example #8
0
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);
  }
}
Example #9
0
void MarkToBaseLookup1::apply (OpenTypeText::iterator begin, OpenTypeText::iterator &mark,
							   OpenTypeText::iterator scopeEnd, OpenTypeText::iterator end) const
{
	// We should never use the first character as a mark because there
	// is nothing in front of it.
	if (mark != begin) {
		UShort markIndex;
		if (markCoverage->isCovered ((*mark)->getGlyphId(), &markIndex)) {
			OpenTypeText::iterator base = mark;
			do {
				base --;
			} while (base != begin &&
				(!markToMark && (*base)->getGlyphClass() == OpenTypeChar::gcMark));

			UShort baseIndex;
			if (baseCoverage->isCovered ((*base)->getGlyphId(), &baseIndex)) {
				// Found mark and base
				const MarkRecord &markRecord = markArray.at (markIndex);
				AnchorPtr baseAnchor = (baseArray.at (baseIndex)).at (markRecord.markClass);
				(*mark)->attach (*markRecord.markAnchor, base, *baseAnchor);
			}
		}
	}
	mark ++;
}
Example #10
0
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));
  }
}
Example #11
0
//-----------------------------------------------------------------------------
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);
  };
Example #12
0
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");
}
Example #13
0
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;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) {
    BaseArray<UIObject *> objects;
    getObjects(objects, true);

    if (objects.size() == 0) {
        return nullptr;
    } else {
        if (currObject != nullptr) {
            for (uint32 i = 0; i < objects.size(); i++) {
                if (objects[i] == currObject) {
                    if (i < objects.size() - 1) {
                        return objects[i + 1];
                    } else {
                        break;
                    }
                }
            }
        }
        return objects[0];
    }
    return nullptr;
}
Example #17
0
BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) {
    BaseArray<UIObject *> objects;
    getObjects(objects, true);

    if (objects.size() == 0) {
        return nullptr;
    } else {
        if (currObject != nullptr) {
            for (int i = objects.size() - 1; i >= 0; i--) {
                if (objects[i] == currObject) {
                    if (i > 0) {
                        return objects[i - 1];
                    } else {
                        break;
                    }
                }
            }
        }
        return objects[objects.size() - 1];
    }
    return nullptr;
}
Example #18
0
//-----------------------------------------------------------------------------
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);
  };
Example #19
0
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>());
}
Example #20
0
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>());
}
Example #21
0
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));
}
Example #22
0
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));
  }
}
Example #23
0
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));
  }
};
Example #24
0
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);
}
Example #25
0
void fill_array(BaseArray<T>& inputArray, T b)
{
  T* data = inputArray.getData();
  std::fill(data, data + inputArray.getNumElems(), b);
}
Example #26
0
void assignRowMajorData(const T *data, BaseArray<T> &array) {
  vector<size_t> idx(array.getNumDims());
  assignRowMajorDim(1, data, array, idx);
}
Example #27
0
void cat_array(int k, const vector<const BaseArray<T>*>& x, BaseArray<T>& a)
{
    unsigned int new_k_dim_size = 0;
    unsigned int n = x.size();
    /* check dim sizes of all inputs */
    if(n<1)
      throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"No input arrays");

    if(x[0]->getDims().size() < k)
     throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong dimension for input array");

    new_k_dim_size = x[0]->getDims()[k-1];
    for(int i = 1; i < n; i++)
    {
        //arrays must have same number of dimensions
		if(x[0]->getDims().size() != x[i]->getDims().size())
           throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong dimension for input array");
        //Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
		for(int j = 0; j < (k - 1); j++)
        {
            if (x[0]->getDims()[j] != x[i]->getDims()[j])
                throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
        }
		//calculate new size of dimension k
        new_k_dim_size += x[i]->getDims()[k-1];
         //Size matching: Arrays must have identical array sizes with the exception of the size of dimension k
		for(int j = k; j < x[0]->getDims().size(); j++)
        {
          if (x[0]->getDims()[j] != x[i]->getDims()[j])
            throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
        }
    }
    /* calculate size of sub and super structure in 1-dim data representation */
    unsigned int n_sub = 1;
    unsigned int n_super = 1;
    for (int i = 0; i < (k - 1); i++)
    {
        n_super *= x[0]->getDims()[i];
    }
    for (int i = k; i < x[0]->getDims().size(); i++)
    {
        n_sub *= x[0]->getDims()[i];
    }
    /* allocate output array */
    vector<size_t> ex = x[0]->getDims();
    ex[k-1] = new_k_dim_size;
    if(ex.size()<k)
     throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Error resizing concatenate array");
    a.setDims( ex );

  /* concatenation along k-th dimension */
  T* a_data = a.getData();
  int j = 0;
  for (int i = 0; i < n_super; i++)
  {
    for (int c = 0; c < n; c++)
    {
      int n_sub_k = n_sub * x[c]->getDims()[k-1];
      const T* x_data = x[c]->getData();
      for (int r = 0; r < n_sub_k; r++)
      {
        a_data[j] = x_data[r + (i * n_sub_k)];
        j++;
      }
    }
  }
}
Example #28
0
T sum_array (const BaseArray<T>& x)
{
  const T* data = x.getData();
  T val = std::accumulate(data, data + x.getNumElems(), T());
  return val;
}
Example #29
0
// This function demonstrates the basic methods of our arrays and lists.
// To keep it simple it does not check for errors. For real-life code
// you have to check the return value of Append() or Insert() before you
// access the memory.
static void	BaseArrayDemo()
{
	BaseArray<VLONG>	test;																		// this could be BlockArray, PointerArray, SortedArray or BaseList
	VLONG							copyMe = 42;
	VLONG							i;
	
	test.Append();																						// append an element with default value
	test.Append(copyMe);																			// append a copy of copyMe
	test.Insert(1);																						// insert an element with default value at index 1
	test.Insert(2, copyMe);																		// insert a copy of copyMe at index 2
	test.Erase(0);																						// erase element at index 0
	test[2] = 12345;																					// assign a value to the element at index 2

	// iterate over all elements, assign value
	for (i = 0; i < test.GetCount(); i++)
		test[i] = i;

	test.Resize(27);																					// the array has now 27 elements
	test.Erase(10, 15);																				// erase 15 elements from index 10 on
	test.Append(9876);
	test.Append(54321);

	// iterate over all elements, check for some value
	for (AutoIterator<BaseArray<VLONG> > it(test); it; ++it)
	{
		if (*it == 9876)
			break;																								// BTW: the index of this element is it - test.Begin();
	}
}