Matrix3 operator*(const Matrix3& a, const float fScalar) { Matrix3 mResult(a); for (unsigned char uRow = 0; uRow < 3; ++uRow) for (unsigned char uColumn = 0; uColumn < 3; ++uColumn) mResult[uRow][uColumn] *= fScalar; return mResult; }
// [[Rcpp::export]] RcppExport SEXP get_Distance_Matrix(SEXP newData, SEXP refData, SEXP weights) { Rcpp::NumericVector vWeights(weights); Rcpp::NumericMatrix mNew(newData); Rcpp::NumericMatrix mRef(refData); // number of variables in model int nVars = mRef.ncol(); // n new cases int nNewCases = mNew.nrow(); // allocate result matrix Rcpp::NumericMatrix mResult(mRef.nrow(), nNewCases); for (int i=0; i<nVars; ++i) { // loop over variables for (int j=0; j<nNewCases; ++j) { // loop over new cases mResult(Rcpp::_, j) = mResult(Rcpp::_, j) + abs(vWeights(i) * (mRef(Rcpp::_, i) - mNew(j, i))); } // end loop new cases } // end loop variables return Rcpp::wrap(mResult); }
void Hw6CompItemfhebert::RecomputeData(const DataBoxAccess& box) const { const MyVector<DataMesh>& Coords = box.Get<MyVector<DataMesh> >("GlobalCoords"); // convert from x,y,z to r DataMesh RSqrd(Coords[0], 0.0); for (int dim=0; dim<Coords.Size(); ++dim) { RSqrd += Coords[dim]*Coords[dim]; } const DataMesh R=sqrt(RSqrd); // give output on the same Mesh as the GlobalCoords: mResult.assign(Coords[0].Dim(), "a", Coords[0]); for (int dim=0; dim<Coords.Size(); ++dim) { mResult(dim) = Coords[dim] / (R*R*R); } }