void RequestParser::parseRetrySpecification(const Item& aItem, RetrySpecification& aRetrySpec)
{
  Item lDelay;
  Item lStatuses;

  aRetrySpec.theRetry = true;

  getArray(aItem, "delay", true, lDelay);
  uint64_t lDelaySize = lDelay.getArraySize();
  if (lDelaySize == 0)
    theThrower->raiseException("REQUEST", "The specified request is not valid. The delay array is empty.");
  for(uint32_t i = 1; i <= lDelaySize; ++i)
  {
    Item lMember = lDelay.getArrayValue(i);
    int lValue = parseInteger(lMember, "entry of delay");
    if (lValue <= 0)
      theThrower->raiseException("REQUEST", "The specified delays are not valid: they must all be greater than 0.");
    aRetrySpec.theRetryDelays.push_back(lValue);
  }

  getBoolean(aItem, "on-connection-error", false, aRetrySpec.theRetryOnConnectionError);
  getArray(aItem, "on-statuses", true, lDelay);
  uint64_t lStatusesSize = lDelay.getArraySize();
  if (!aRetrySpec.theRetryOnConnectionError && lStatusesSize == 0)
    theThrower->raiseException("REQUEST", "The specified request is not valid. Retry on connection error is false, and the on-status array is empty.");
  for(uint32_t i = 1; i <= lStatusesSize; ++i)
  {
    Item lMember = lDelay.getArrayValue(i);
    aRetrySpec.theRetryStatuses.push_back(parseInteger(lMember, "entry of statuses"));
  }
}
// compute final result of responding postfix 
ElementType compute_postfix()
{
	Stack output;
	int i;
	ElementType *p;
	int value;
	int operand1;
	int operand2;
	 
	output = createStack(Size); // create stack with length Size
	i = 0;
	p = getArray(operand); // get operand->array

	while(i < getTopOfStack(operand))
	{
		value = *(p+i++);
		if(value == ' ')
			continue;
		if(isOperator(value))
		{
			operand1 = top(output);
			pop(output);

			operand2 = top(output);
			pop(output);

			value = computeResult(operand1, operand2, value);
			push(value, output);
			continue;
		}
		push(value - 48, output);
	}
	return getArray(output)[0];
}
Beispiel #3
0
void RuleParser::parse() {
	sweet::jsonparser jp(str);

	std::string tokStr("Token");
	if(jp.getRoot()->pathExists(tokStr)) {
		auto tok = jp.getRoot()->access(tokStr);
		auto tokType = tok->getType();
		ASSERT_EQ(tokType, sweet::value::type_array);

		for(auto& it : tok->getArray()) {
			std::string name = it->getObject()->access("Name")->getString();
			std::string regex = it->getObject()->access("Regex")->getString();
			std::string convertFunc;
			if(it->getObject()->pathExists("ConvertFunction")) {
				convertFunc = it->getObject()->access("ConvertFunction")->getString();
			}
			token.insert(std::make_pair(name,
				Token(name, regex, convertFunc)
			));
		}
	}

	std::string ruleStr("Rules");
	if(jp.getRoot()->pathExists(ruleStr)) {
		auto rls = jp.getRoot()->access(ruleStr);
		auto rlsType = rls->getType();
		ASSERT_EQ(rlsType, sweet::value::type_array);
		for(auto& it : rls->getArray()) {

			std::string ruleName = it->getObject()->access("Name")->getString();
			auto& entry = it->getObject()->access("Expression")->getArray();
			for(auto& jt : entry) {
				RuleVector rv;
				auto semiSplit = split(jt->getObject()->access("Rule")->getString(), ';');
				std::string ruleEnd = jt->getObject()->get<std::string>("Id", "");
				for(auto& ht : semiSplit) {
					std::string type = trim(ht.substr(0, ht.find('(')));
					size_t lParen = ht.find('(');
					size_t rParen = ht.find(')');
					std::string saveName;
					if(lParen != std::string::npos && rParen != std::string::npos) {
						saveName = trim(ht.substr(lParen+1, rParen), "\t ()");
					}

					rv.push_back(RulePart(type, saveName, ruleEnd));
				}

				ruleMap.insert(std::make_pair(ruleName, Expr(rv)));
			}

		}
	}
}
Beispiel #4
0
Array<var>* var::convertToArray()
{
    if (auto* array = getArray())
        return array;

    Array<var> tempVar;
    if (! isVoid())
        tempVar.add (*this);

    *this = tempVar;
    return getArray();
}
void PVArray::checkLength(size_t len)
{
    Array::ArraySizeType type = getArray()->getArraySizeType();
    if (type != Array::variable)
    {
        size_t size = getArray()->getMaximumCapacity();
        if (type == Array::fixed && len != size)
            throw std::invalid_argument("invalid length for a fixed size array");
        else if (type == Array::bounded && len > size)
            throw std::invalid_argument("new array capacity too large for a bounded size array");
    }
}
Beispiel #6
0
OpenClKernel::OpenClKernel(const std::string &deviceId, const std::string &portMarkup):
    _localSize(1),
    _globalFactor(1.0),
    _productionFactor(1.0)
{
    const auto colon = deviceId.find(":");
    const auto platformIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(0, colon));
    const auto deviceIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(colon+1));

    /* Identify a platform */
    cl_int err = 0;
    cl_uint num_platforms = 0;
    cl_platform_id platforms[64];
    err = clGetPlatformIDs(64, platforms, &num_platforms);
    if (err < 0) throw Pothos::Exception("OpenClKernel::clGetPlatformIDs()", clErrToStr(err));
    if (platformIndex >= num_platforms) throw Pothos::Exception("OpenClKernel()", "platform index does not exist");
    _platform = platforms[platformIndex];

    /* Access a device */
    cl_uint num_devices = 0;
    cl_device_id devices[64];
    err = clGetDeviceIDs(_platform, CL_DEVICE_TYPE_ALL, 64, devices, &num_devices);
    if (err < 0) throw Pothos::Exception("OpenClKernel::clGetDeviceIDs()", clErrToStr(err));
    if (deviceIndex >= num_devices) throw Pothos::Exception("OpenClKernel()", "device index does not exist");
    _device = devices[deviceIndex];

    /* Create context */
    _context = lookupContextCache(_device);

    /* Create ports */
    _myDomain = "OpenCl_"+std::to_string(size_t(_device));
    Poco::JSON::Parser p; p.parse(portMarkup);
    const auto ports = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
    const auto inputs = ports->getArray(0);
    const auto outputs = ports->getArray(1);
    for (size_t i = 0; i < inputs->size(); i++)
    {
        this->setupInput(i, Pothos::DType("custom", inputs->getElement<int>(i)), _myDomain);
    }
    for (size_t i = 0; i < outputs->size(); i++)
    {
        this->setupOutput(i, Pothos::DType("custom", outputs->getElement<int>(i)), _myDomain);
    }

    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setSource));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setLocalSize));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getLocalSize));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setGlobalFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getGlobalFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setProductionFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getProductionFactor));
}
void VectorMatrix::normalize(const Matrix &len)
{
	if (isUniform() && len.isUniform()) {
		Vector3d uni = getUniformValue();
		uni.normalize(len.getUniformValue());
		fill(uni);
	} else {
		const int dev = computeStrategy2(len);
		writeLock(dev); len.readLock(dev);
		getDevice(dev)->normalize3(getArray(dev, 0), getArray(dev, 1), getArray(dev, 2), len.getArray(dev));
		len.readUnlock(dev); writeUnlock(dev); 
	}
}
Beispiel #8
0
int QS::partition(int left, int right, int pivotIndex){
    //detect errors
    if((elements == NULL)
            || !(left < right) || (left < 0) || (left >= element_cnt) 
            || (right >= element_cnt) || (right < 0) 
            || (pivotIndex < left) || (pivotIndex > right)){
        return -1;
    }
#if DEBUG && PART_DEBUG
    cout << "input array:  " << getArray() << endl;
    cout << "left = " << left << " pivotIndex = " << pivotIndex 
        << " right = " << right << endl;
#endif
    int pivotVal = elements[pivotIndex];
    //swap pivot with first
    elements[pivotIndex] = elements[left];
    elements[left] = pivotVal;
    int i = left + 1;
    int j = right;
    while( 1 ){
        while(j > left){
            if(elements[j] < pivotVal){
                break;
            }
            j--;
        } 
        while(i < right){
            if(elements[i] >= pivotVal){
                break;
            }
            i++;
        }
        //if they cross
        if(j <= i){
            //swap the pivot value back into the new pivot position
            pivotIndex = j;
            elements[left] = elements[pivotIndex];
            elements[pivotIndex] = pivotVal;
            break;
        }
        //swap the i and j location values
        int tmp = elements[i];
        elements[i] = elements[j];
        elements[j] = tmp;
    }
#if DEBUG && PART_DEBUG
    cout << "output array: " << getArray() << endl;
    cout << " pivotIndex = " << pivotIndex << endl;
#endif
    return pivotIndex;
}
Beispiel #9
0
QStringList QDropboxJson::getArray()
{
	if(!isAnonymousArray())
		return QStringList();

	return getArray("_anonArray");
}
void DynProgProbLim::reserve (size_t arrayCapacity_) // new array capacity
// reduces capacity of and copies d_array_p from its begin
{
    if (arrayCapacity_ == getArrayCapacity ()) return;

    if (getArrayCapacity () < arrayCapacity_) 
    {
        DynProgProb::reserve (arrayCapacity_);
        return;
    }

    assert (arrayCapacity_ < getArrayCapacity ());

    double *array = new double [getArrayCapacity ()];

    for (size_t i = 0; i < 2; i++) 
    {
        MemUtil::memCpy (array, getArray () [i], sizeof (double) * arrayCapacity_);
        delete [] lgetArray () [i]; lgetArray () [i] = 0;

        lgetArray () [i] = new double [arrayCapacity_];
        MemUtil::memCpy (lgetArray () [i], array, sizeof (double) * arrayCapacity_);
    }

    lgetArrayCapacity () = arrayCapacity_;

    delete [] array; array = 0;
}
// =============================================================================
Epetra_NumPyIntSerialDenseMatrix::Epetra_NumPyIntSerialDenseMatrix(PyObject * pyObject):
  Epetra_IntSerialDenseMatrix(View, getArray(pyObject), getNumRows(pyObject),
			      getNumRows(pyObject), getNumCols(pyObject))
{
  // Synchronize the PyArrayObject with the Epetra_IntSerialDenseMatrix
  setArray();
}
Beispiel #12
0
Object::operator const Poco::DynamicStruct& () const
{
	if (!_pStruct)
	{
		ValueMap::const_iterator it = _values.begin();
		ValueMap::const_iterator end = _values.end();
		_pStruct = new Poco::DynamicStruct;
		for (; it != end; ++it)
		{
			if (isObject(it))
			{
				_pStruct->insert(it->first, makeStruct(getObject(it->first)));
			}
			else if (isArray(it))
			{
				_pStruct->insert(it->first, Poco::JSON::Array::makeArray(getArray(it->first)));
			}
			else
			{
				_pStruct->insert(it->first, it->second);
			}
		}
	}

	return *_pStruct;
}
void DynProgProbLim::setValueBegin (Int4 valueBegin_)
// resets the offset d_valueBegin
// assert (offSet < getArrayCapacity ());
// if (getValueBegin () < valueBegin_) the caller must ensure consistency 
{
    if (valueBegin_ <= getValueBegin ()) 
    {
        DynProgProb::setValueBegin (valueBegin_);
        return;
    }

    assert (getValueBegin () < valueBegin_);
    size_t offSet = static_cast <size_t> (valueBegin_ - getValueBegin ());

    double *array = new double [getArrayCapacity ()];

    for (size_t i = 0; i < 2; i++) 
    {
        MemUtil::memCpy (array, getArray () [i], sizeof (double) * getArrayCapacity ());
        MemUtil::memZero (lgetArray () [i], sizeof (double) * getArrayCapacity ());
        
        if (offSet < getArrayCapacity ()) 
        {
            MemUtil::memCpy (lgetArray () [i], array + offSet, sizeof (double) * (getArrayCapacity () - offSet));
        }
    }

    delete [] array; array = 0;

    lgetValueBegin () = valueBegin_;
}
//==============================================================================
int var::size() const
{
    if (const Array<var>* const array = getArray())
        return array->size();

    return 0;
}
Beispiel #15
0
/* getArrayElement: puts pointer to array element on stack */
void getArrayElement( Symbol *s )
{
    int         index;
    Array       *array;
    Variant     *v;

    eMemTest( "getArrayElement: symbol", s );
    array = getArray( s );

    /* dynamic or static? */
    if (array->isDynamic) {
        getDynamicValue( array, s );

    } else {
        /* static array */

        index = getStaticIndex( array, s );
        v = array->data.item+index;
        eMemTest( "getArrayElement: array element", v );

        tos++;
        stack[tos].datatype = DATA_REF;
        stack[tos].value.ref = v;

    }

}
Beispiel #16
0
void Pothos::Util::BlockDescriptionParser::feedStream(std::istream &is)
{
    for (const auto &contiguousBlock : extractContiguousBlocks(is))
    {
        const auto obj = parseCommentBlockForMarkup(contiguousBlock);
        if (not obj) continue;

        //store into the array of all description objects
        _impl->array->add(obj);

        //get a list of all paths including aliases
        std::vector<std::string> paths;
        paths.push_back(obj->getValue<std::string>("path"));
        if (obj->has("aliases")) for (const auto &alias : *obj->getArray("aliases"))
        {
            paths.push_back(alias.toString());
        }

        //store mapping for each factory path
        for (const auto &path : paths)
        {
            _impl->factories.push_back(path);
            _impl->objects[path] = obj;
        }
    }
}
void VectorMatrix::scale(const Vector3d &factors)
{
	if (factors == Vector3d(0.0, 0.0, 0.0)) {
		fill(Vector3d(0.0, 0.0, 0.0));
	} else if (isUniform()) {
		const Vector3d uni = getUniformValue();
		fill(Vector3d(uni.x*factors.x, uni.y*factors.y, uni.z*factors.z));
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		matty::getDevice(dev)->scale(getArray(dev, 0), factors.x);
		matty::getDevice(dev)->scale(getArray(dev, 1), factors.y);
		matty::getDevice(dev)->scale(getArray(dev, 2), factors.z);
		readUnlock(dev);
	}
}
Beispiel #18
0
void QS::sortAll(){
    //sorts the array, calling rec_sort
#if DEBUG && SORT_DEBUG
    cout << "input array:  " << getArray() << endl;
#endif
    rec_sort(0, element_cnt - 1);
}
Beispiel #19
0
bool MatrixOpData::isMatrixIdentity() const
{
    // Now check the diagonal elements.
    const double scaleFactor
        = (double)GetBitDepthMaxValue(getOutputBitDepth())
        / (double)GetBitDepthMaxValue(getInputBitDepth());

    const double maxDiff = scaleFactor * 1e-6;

    const ArrayDouble & a = getArray();
    const ArrayDouble::Values & m = a.getValues();
    const unsigned long dim = a.getLength();

    for (unsigned long i = 0; i<dim; ++i)
    {
        for (unsigned long j = 0; j<dim; ++j)
        {
            if (i == j)
            {
                if (!EqualWithAbsError(m[i*dim + j],
                                       scaleFactor,
                                       maxDiff))
                {
                    return false;
                }
            }
        }
    }

    return true;
}
Beispiel #20
0
bool SiconosMatrix::fillTriplet(CSparseMatrix* triplet, size_t row_off, size_t col_off, double tol)
{
  assert(triplet);
  size_t nrow = size(0);
  size_t ncol = size(1);

  if (_num == 1) //dense
  {
    double* arr = getArray();
    for (size_t j = 0; j < ncol; ++j)
    {
      for (size_t i = 0; i < nrow; ++i)
      {
        // col-major

        CSparseMatrix_zentry(triplet, i + row_off, j + col_off, arr[i + j*nrow] );
      }
    }
  }
  else
  {
     SiconosMatrixException::selfThrow("SiconosMatrix::fillCSC not implemented for the given matrix type");
  }

  return true;
}
Beispiel #21
0
//==============================================================================
int var::size() const
{
    if (auto* array = getArray())
        return array->size();

    return 0;
}
Beispiel #22
0
Array::operator const Poco::Dynamic::Array& () const
{
	if (!_pArray)
	{
		ValueVec::const_iterator it = _values.begin();
		ValueVec::const_iterator end = _values.end();
		_pArray = new Poco::Dynamic::Array;
		int index = 0;
		for (; it != end; ++it, ++index)
		{
			if (isObject(it))
			{
				_pArray->insert(_pArray->end(), Poco::JSON::Object::makeStruct(getObject(index)));
			}
			else if (isArray(it))
			{
				_pArray->insert(_pArray->end(), makeArray(getArray(index)));
			}
			else
			{
				_pArray->insert(_pArray->end(), *it);
			}
		}
	}

	return *_pArray;
}
Beispiel #23
0
void PVUnionArray::compress() {
    if (getArray()->getArraySizeType() == Array::fixed)
            return;

    svector vec(reuse()); // TODO: check for first NULL before realloc

    size_t length = vec.size();
    size_t newLength = 0;

    for(size_t i=0; i<length; i++) {
        if(vec[i].get()!=NULL) {
            newLength++;
            continue;
        }
        // find first non 0
        size_t notNull = 0;
        for(size_t j=i+1;j<length;j++) {
            if(vec[j].get()!=NULL) {
                notNull = j;
                break;
            }
        }
        if(notNull!=0) {
            vec[i] = vec[notNull];
            vec[notNull].reset();
            newLength++;
            continue;
         }
         break;
    }

    vec.resize(newLength);
    const_svector cdata(freeze(vec));
    swap(cdata);
}
Vector3d VectorMatrix::maximum() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d max(
			matty::getDevice(dev)->maximum(getArray(dev, 0)),
			matty::getDevice(dev)->maximum(getArray(dev, 1)),
			matty::getDevice(dev)->maximum(getArray(dev, 2))
		);
		readUnlock(dev);
		return max;
	}
}
Beispiel #25
0
Layout::Layout() :
    LayoutCell(),
    mComputed(false)
{
    getArray();
    setPadding(6);
}
Vector3d VectorMatrix::average() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d avg(
			matty::getDevice(dev)->average(getArray(dev, 0)),
			matty::getDevice(dev)->average(getArray(dev, 1)),
			matty::getDevice(dev)->average(getArray(dev, 2))
		);
		readUnlock(dev);
		return avg;
	}
}
int var::indexOf (const var& n) const
{
    if (const Array<var>* const array = getArray())
        return array->indexOf (n);

    return -1;
}
Beispiel #28
0
/* inArray: Returns true if key is in array */
int inArray( Symbol *s )
{
    int         index;
    char        *key;
    Array       *array;

    /* get the array */
    array = getArray( s );

    eMemTest( "inArray: array", array );

    if (!array->isDynamic) {
        ePrintf( Runtime, "%s is a static array", s->name );
    }

    /* get key */
    key = popString();
    index = findKey( array, s, key );
    eFree( key );

    /* found key? */
    if (index == -1) {
        return 0;
    } else {
        return 1;
    }

}
Beispiel #29
0
bool MatrixOpData::hasAlpha() const
{
    const ArrayDouble & a = getArray();
    const ArrayDouble::Values & m = a.getValues();

    // Now check the diagonal elements.
    const double scaleFactor
        = (double)GetBitDepthMaxValue(getOutputBitDepth())
        / (double)GetBitDepthMaxValue(getInputBitDepth());
    const double maxDiff = scaleFactor * 1e-6;

    return

        // Last column.
        (m[3] != 0.0) || // Strict comparison intended
        (m[7] != 0.0) ||
        (m[11] != 0.0) ||

        // Diagonal.
        !EqualWithAbsError(m[15], scaleFactor, maxDiff) ||

        // Bottom row.
        (m[12] != 0.0) || // Strict comparison intended
        (m[13] != 0.0) ||
        (m[14] != 0.0);
}
void var::remove (const int index)
{
    Array<var>* const array = getArray();

    if (array != nullptr)
        array->remove (index);
}