本文整理汇总了C++中AbstractMatrix::saveAs方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractMatrix::saveAs方法的具体用法?C++ AbstractMatrix::saveAs怎么用?C++ AbstractMatrix::saveAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractMatrix
的用法示例。
在下文中一共展示了AbstractMatrix::saveAs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save_R
//virtual void save(string new_file_name, unsigned long int nvars, unsigned long int nobss, unsigned long int * varindexes, unsigned long int * obsindexes)
SEXP save_R(SEXP New_file_name, SEXP IntPars, SEXP s) {
CHECK_PTR(s);
AbstractMatrix * p = (AbstractMatrix*) R_ExternalPtrAddr(s);
if (p == NULL) {
error_R("pointer is NULL\n");
return R_NilValue;
}
std::string new_file_name = CHAR(STRING_ELT(New_file_name, 0));
unsigned long int nvars = (unsigned long int) INTEGER(IntPars)[0];
unsigned long int nobss = (unsigned long int) INTEGER(IntPars)[1];
unsigned long int varindexes[nvars];
unsigned long int obsindexes[nobss];
for (unsigned long int i = 0; i < nvars; i++)
varindexes[i] = (unsigned long int) INTEGER(IntPars)[i + 2];
for (unsigned long int i = 0; i < nobss; i++)
obsindexes[i] = (unsigned long int) INTEGER(IntPars)[i + 2 + nvars];
try {
p->saveAs(new_file_name, nvars, nobss, varindexes, obsindexes);
} catch (int errcode) {
error_R("can not save data to file %s\n", new_file_name.c_str());
return R_NilValue;
}
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 1));
LOGICAL(ret)[0] = TRUE;
UNPROTECT(1);
return ret;
}
示例2: save_R
//virtual void save(string newFilename, unsigned long nvars, unsigned long nobss, unsigned long * varindexes, unsigned long * obsindexes)
SEXP save_R(SEXP New_file_name, SEXP IntPars, SEXP s)
{
// dbg<<"save_R"<<endl;
AbstractMatrix * p = getAbstractMatrixFromSEXP(s);
if (p == NULL) {
error_R("pointer is NULL\n");
return R_NilValue;
}
string newFilename = CHAR(STRING_ELT(New_file_name,0));
unsigned long nvars = (unsigned long) INTEGER(IntPars)[0];
unsigned long nobss = (unsigned long) INTEGER(IntPars)[1];
unsigned long * varindexes = new (std::nothrow) unsigned long [nvars];
if (varindexes == NULL) {
error_R("pointer is NULL\n");
return R_NilValue;
}
unsigned long * obsindexes = new (std::nothrow) unsigned long [nobss];
if (obsindexes == NULL) {
error_R("pointer is NULL\n");
delete [] varindexes;
return R_NilValue;
}
for (unsigned long i = 0; i < nvars; i++)
varindexes[i] = (unsigned long) INTEGER(IntPars)[i+2];
for (unsigned long i = 0; i < nobss; i++) {
obsindexes[i] = (unsigned long) INTEGER(IntPars)[i+2+nvars];
}
try {
p->saveAs(newFilename,nvars,nobss,varindexes,obsindexes);
} catch (int errcode) {
error_R("can not save data to file %s\n",newFilename.c_str());
delete [] obsindexes;
delete [] varindexes;
return R_NilValue;
}
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 1));
LOGICAL(ret)[0] = TRUE;
delete [] obsindexes;
delete [] varindexes;
UNPROTECT(1);
return ret;
}
示例3: saveAsText
SEXP saveAsText(SEXP s, SEXP New_file_name, SEXP IntPars, SEXP NANString ) {
AbstractMatrix * p = getAbstractMatrixFromSEXP(s);
if (p == NULL) {
error_R("pointer is NULL\n");
return R_NilValue;
}
string newFilename = CHAR(STRING_ELT(New_file_name,0));
string nanString = CHAR(STRING_ELT(NANString,0));
bool showVarNames = LOGICAL(IntPars)[0];
bool showObsNames = LOGICAL(IntPars)[1];
bool transpose = LOGICAL(IntPars)[2];
AbstractMatrix *transposed = p;
string tmpFileName,tmpFileName2;
if (!transpose){
Transposer transposer;
tmpFileName= p->getFileName() + string("_saveAsText_tmp");
tmpFileName2= p->getFileName() + string("_saveAsText_tmp2");
p->saveAs(tmpFileName);
transposer.process(tmpFileName, tmpFileName2, true);
transposed = new FileVector(tmpFileName2, p->getCacheSizeInMb());
}
try {
transposed->saveAsText(newFilename, showVarNames, showObsNames, nanString);
} catch (int errcode) {
error_R("can not save data to file %s\n",newFilename.c_str());
return R_NilValue;
}
if (!transpose){
delete transposed;
unlink(tmpFileName.c_str());
unlink(tmpFileName2.c_str());
}
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 1));
LOGICAL(ret)[0] = TRUE;
UNPROTECT(1);
return ret;
}