当前位置: 首页>>代码示例>>C++>>正文


C++ AbstractMatrix::readVariableAs方法代码示例

本文整理汇总了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;
}
开发者ID:rforge,项目名称:genabel,代码行数:37,代码来源:CorrectnessTest.cpp

示例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;
	}
开发者ID:rforge,项目名称:genabel,代码行数:76,代码来源:AbstractMatrix_R.cpp


注:本文中的AbstractMatrix::readVariableAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。