本文整理汇总了C++中AbstractMatrix::readVariableAs方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractMatrix::readVariableAs方法的具体用法?C++ AbstractMatrix::readVariableAs怎么用?C++ AbstractMatrix::readVariableAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractMatrix
的用法示例。
在下文中一共展示了AbstractMatrix::readVariableAs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testReadVariable
void CorrectnessTest::testReadVariable() {
string inputFile = getInputFileName();
AbstractMatrix *data = new FileVector( inputFile, 64 );
testDbg << "Reading file:" << inputFile << endl;
unsigned long numVariables = data->getNumVariables();
unsigned long numObservations = data->getNumObservations();
testDbg << "Size is " << numVariables << " x " << numObservations << endl;
double* tmpdat = new( nothrow ) double[numObservations];
string sumFileName = inputFile + string(".fvf_varsum");
ifstream sums(sumFileName.c_str());
testDbg << "Reading file: " << sumFileName << endl;
CPPUNIT_ASSERT(sums.good());
unsigned long i;
for ( i = 0 ; i < numVariables ; i++ )
{
if (i%1000 == 0)
testDbg << i << endl;
data->readVariableAs(i, tmpdat);
double calcSumm, realSumm;
sums >> realSumm;
calcSumm = summData(tmpdat,numObservations);
CPPUNIT_ASSERT(TestUtil::relativeDifference(calcSumm,realSumm)<1E-4);
}
delete[] tmpdat;
delete data;
testDbg << "Finished" << endl;
}
示例2: assignDoubleMatrix
/**
* direction: 0 -- copy values from @values to @ptr,
* 1 -- copy values from @ptr to @values...
*/
SEXP assignDoubleMatrix(SEXP ptr, SEXP obsIndexes, SEXP varIndexes, SEXP values, SEXP direction){
//flush(cout);
unsigned long varNum, obsNum, obsIndexNum, varIndexNum;
AbstractMatrix * p = getAbstractMatrixFromSEXP(ptr);
double coeff = 1. * length(obsIndexes) / p->getNumObservations();
unsigned long dir = (unsigned long) INTEGER(direction)[0];
double *currentValues = 0;
if (!(coeff < WRITE_SPEED_PROPORTION)) {
currentValues = new double[p->getNumObservations()];
}
unsigned long varIndexesLength = length(varIndexes);
unsigned long obsIndexesLength = length(obsIndexes);
for(varIndexNum = 0; varIndexNum < varIndexesLength; varIndexNum ++){
varNum = (unsigned long)INTEGER(varIndexes)[varIndexNum]-1;
if ( coeff < WRITE_SPEED_PROPORTION) {
for(obsIndexNum = 0; obsIndexNum < obsIndexesLength; obsIndexNum ++){
obsNum = (unsigned long)INTEGER(obsIndexes)[obsIndexNum]-1;
try {
if (dir==0) {
double value = REAL(values)[varIndexNum *obsIndexesLength + obsIndexNum];
p->writeElementAs(varNum, obsNum,value);
} else {
double value;
p->readElementAs(varNum, obsNum,value);
REAL(values)[varIndexNum *obsIndexesLength + obsIndexNum] = value;
}
} catch(int errorCode) {
return R_NilValue;
}
}
} else {
try {
if (dir==0) {
p->readVariableAs(varNum, currentValues);
for(obsIndexNum = 0; obsIndexNum < obsIndexesLength; obsIndexNum ++){
obsNum = (unsigned long)INTEGER(obsIndexes)[obsIndexNum] - 1;
currentValues[obsNum] = REAL(values)[varIndexNum*obsIndexesLength+obsIndexNum];
}
p->writeVariableAs(varNum, currentValues);
} else {
p->readVariableAs(varNum, currentValues);
for(obsIndexNum = 0; obsIndexNum < obsIndexesLength; obsIndexNum ++){
obsNum = (unsigned long)INTEGER(obsIndexes)[obsIndexNum] - 1;
REAL(values)[varIndexNum*obsIndexesLength+obsIndexNum] = currentValues[obsNum];
}
}
} catch(int errorCode){
delete [] currentValues;
return R_NilValue;
}
}
}
if (!(coeff < WRITE_SPEED_PROPORTION)) {
delete [] currentValues;
}
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 1));
LOGICAL(ret)[0] = TRUE;
UNPROTECT(1);
//flush(cout);
return ret;
}