Example #1
0
  SEXP MakeFill(SEXP coord,SEXP obs,SEXP h,SEXP p){
    covafill<double>* cfp = new covafill<double>(asMatrix(coord),
						       asVector(obs),
						       asVector(h),
						       asInteger(p));

    if(cfp == NULL){
      return R_NilValue;
    }
    SEXP val = R_MakeExternalPtr(cfp, install("covafillPointer"), R_NilValue);
    return val;
  }
Example #2
0
  SEXP MakeTree(SEXP coord,SEXP obs,SEXP h,SEXP p, SEXP d){


    covafill<double>* cfp = new covafill<double>(asMatrix(coord),
						       asVector(obs),
						       asVector(h),
						       asInteger(p));
    covatree<double>* ctp = new covatree<double>(asDouble(d),cfp);

    if(ctp == NULL){
      return R_NilValue;
    }
    SEXP val = R_MakeExternalPtr(ctp, install("covatreePointer"), R_NilValue);
    return val;
  }
Example #3
0
void print(const ConvertibleToArray& object, std::ostream& os = std::cerr)
{
   typedef typename ConvertibleToArray::value_type value_type;
   std::vector<value_type> asVector(object.begin(), object.end());
   json::writeFormatted(json::toJsonArray(asVector), os);
   os << std::endl;
}
Example #4
0
Status AbstractIndexAccessMethod::update(OperationContext* opCtx,
                                         const UpdateTicket& ticket,
                                         int64_t* numInserted,
                                         int64_t* numDeleted) {
    invariant(!_btreeState->isBuilding());
    invariant(ticket.newKeys.size() ==
              ticket.oldKeys.size() + ticket.added.size() - ticket.removed.size());
    invariant(numInserted);
    invariant(numDeleted);

    *numInserted = 0;
    *numDeleted = 0;

    if (!ticket._isValid) {
        return Status(ErrorCodes::InternalError, "Invalid UpdateTicket in update");
    }

    for (const auto& remKey : ticket.removed) {
        _newInterface->unindex(opCtx, remKey, ticket.loc, ticket.dupsAllowed);
    }

    bool checkIndexKeySize = shouldCheckIndexKeySize(opCtx);

    // Add all new data keys, and all new multikey metadata keys, into the index. When iterating
    // over the data keys, each of them should point to the doc's RecordId. When iterating over
    // the multikey metadata keys, they should point to the reserved 'kMultikeyMetadataKeyId'.
    const auto newMultikeyMetadataKeys = asVector(ticket.newMultikeyMetadataKeys);
    for (const auto keySet : {&ticket.added, &newMultikeyMetadataKeys}) {
        const auto& recordId = (keySet == &ticket.added ? ticket.loc : kMultikeyMetadataKeyId);
        for (const auto& key : *keySet) {
            Status status = checkIndexKeySize ? checkKeySize(key) : Status::OK();
            if (status.isOK()) {
                StatusWith<SpecialFormatInserted> ret =
                    _newInterface->insert(opCtx, key, recordId, ticket.dupsAllowed);
                status = ret.getStatus();
                if (status.isOK() && ret.getValue() == SpecialFormatInserted::LongTypeBitsInserted)
                    _btreeState->setIndexKeyStringWithLongTypeBitsExistsOnDisk(opCtx);
            }
            if (isFatalError(opCtx, status, key)) {
                return status;
            }
        }
    }

    if (shouldMarkIndexAsMultikey(
            ticket.newKeys, ticket.newMultikeyMetadataKeys, ticket.newMultikeyPaths)) {
        _btreeState->setMultikey(opCtx, ticket.newMultikeyPaths);
    }

    *numDeleted = ticket.removed.size();
    *numInserted = ticket.added.size();

    return Status::OK();
}
Example #5
0
void Vector::print(std::ostream &os) const {
    std::vector<double> values = asVector();
    os << "(";
    for (std::vector<double>::const_iterator it = values.begin();
            it < values.end(); it++) {
        os << *it;
        if (it + 1 != values.end()) {
            os << ",";
        }
    }
    os << ")";
}
PropertyMap FileProperties::asMap() const
{
    PropertyMap dataMap;

    PropertyVector dataVector(asVector());
    for(PropertyVector::const_iterator it = dataVector.begin(); it != dataVector.end(); ++it)
    {
        dataMap.insert(std::make_pair(it->first, it->second));
    }

    return dataMap;
}
Example #7
0
 SEXP setFillBandwith(SEXP sp, SEXP h){
   
   if(R_ExternalPtrTag(sp) != install("covafillPointer"))
     Rf_error("The pointer must be to a covafill object");   
   covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp);
   if(LENGTH(h) == 1){
     ptr->setH(asDouble(h));
   }else{
     ptr->setH(asVector(h));
   }
   int res = 1;
   return asSEXP(res);
 }
Example #8
0
  SEXP predictTree(SEXP sp, SEXP x){
    if(R_ExternalPtrTag(sp) != install("covatreePointer"))
      Rf_error("The pointer must be to a covatree object");
 
    covatree<double>* ptr=(covatree<double>*)R_ExternalPtrAddr(sp);
    int dim = ptr->getDim();
    
    if(isMatrix(x)){
      MatrixXd res(nrows(x),1 + dim);
      MatrixXd x0 = asMatrix(x);
      for(int i = 0; i < nrows(x); ++i)
	res.row(i) = ptr->operator()((vector)x0.row(i));
      return asSEXP(res);
    }else if(isNumeric(x)){
      return asSEXP(ptr->operator()(asVector(x)));
    }else{
      Rf_error("Element must be a matrix or numeric vector");
    }
    return R_NilValue;
  }
Example #9
0
  SEXP predictFill(SEXP sp, SEXP x){
    if(R_ExternalPtrTag(sp) != install("covafillPointer"))
      Rf_error("The pointer must be to a covafill object");   
    covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp);

    if(isMatrix(x)){
      int lsdim = 1 + ptr->getDim();
      if(ptr->p >= 2)
	lsdim += 0.5 * ptr->getDim() * (ptr->getDim() + 1);
      if(ptr->p >= 3)
	lsdim += (ptr->p - 2) * ptr->getDim();
      MatrixXd res(nrows(x),lsdim);
      MatrixXd x0 = asMatrix(x);
      for(int i = 0; i < nrows(x); ++i)
	res.row(i) = ptr->operator()((vector)x0.row(i), true);
      return asSEXP(res);
    }else if(isNumeric(x)){
      return asSEXP(ptr->operator()(asVector(x), true));
    }else{
      error("Element must be a matrix or numeric vector");
    }
    return R_NilValue;
  }
 inline
 Vector3d
 UnitVector3d::cross(const Vector3d& vector) const {
     return asVector().cross(vector);
 }
 inline
 bool
 UnitVector2d::equals(const Vector2d& vector, double precision) const {
     return asVector().equals(vector, precision);
 }
 inline
 IntervalVector2d
 UnitVector2d::bounds() const {
     return asVector().bounds();
 }
 inline
 UnitVector2d::operator const Vector2d&() const {
     return asVector();
 }
 inline
 bool
 UnitVector2d::operator!=(const Vector2d& vector) const {
     return asVector() != vector;
 }
 inline
 Vector2d
 UnitVector3d::projectedInto(const Plane3d& plane) const {
     return asVector().projectedInto(plane);
 }
 inline
 Vector3d
 UnitVector3d::projectedOnto(const Axis<3>& axis) const {
     return asVector().projectedOnto(axis);
 }
 inline    
 Vector2d
 UnitVector2d::projectedOnto(const Axis2d& axis) const {
     return asVector().projectedOnto(axis);
 }
 inline
 bool
 UnitVector3d::operator==(const Vector3d& vector) const {
     return asVector() == vector;
 }
 inline
 double
 UnitVector3d::dot(const Vector3d& vector) const {
     return asVector().dot(vector);
 }
Example #20
0
bool GenericExpression::equal(const GenericExpression &other) const
{
	if (eqv(other))
	{
		return true;
	}

	{
		const StringExpression *strA = asString();
		const StringExpression *strB = other.asString();

		if (strA && strB)
		{
			// Simple case sensitive, binary safe compare
			return (strA->length() == strB->length()) &&
					 (memcmp(strA->data(), strB->data(), strA->length()) == 0);
		}
	}
	
	{
		const VectorExpression *vecA = asVector();
		const VectorExpression *vecB = other.asVector();

		if (vecA && vecB)
		{
			if (vecA->size() != vecB->size())
			{
				return false;
			}

			for(unsigned int i = 0; i < vecA->size(); i++)
			{
				if (!vecA->item(i)->equal(*vecB->item(i)))
				{
					return false;
				}
			}

			return true;
		}
	}

	{
		const PairExpression *pairA = asPair();
		const PairExpression *pairB = other.asPair();

		if (pairA && pairB)
		{
			if (!pairA->car()->equal(*pairB->car()))
			{
				return false;
			}
			
			// Compare the rest of the list
			// This probably isn't properly tail recursive but I'm writing a Scheme
			// compiler in Scala so this seems incredibly natural right now
			return pairA->cdr()->equal(*pairB->cdr());
		}
	}

	return false;
}
 inline
 UnitVector3d
 UnitVector3d::unitOrthogonal() const {
     return asVector().unitOrthogonal();
 }