本文整理汇总了C++中BigMatrix::ncol方法的典型用法代码示例。如果您正苦于以下问题:C++ BigMatrix::ncol方法的具体用法?C++ BigMatrix::ncol怎么用?C++ BigMatrix::ncol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigMatrix
的用法示例。
在下文中一共展示了BigMatrix::ncol方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moda
/* Prepares the a matrix based on random sample of examples for modelling. For
each continuous variable, copies only the in-sample indices from asave to a.
Data for categorical variables are not copied, as they are stored in x.
This function should only be called if there are any continuous variables. */
SEXP moda(SEXP asaveP, SEXP aP, SEXP insampP) {
// Initialize function arguments.
BigMatrix *asave = (BigMatrix*)R_ExternalPtrAddr(asaveP);
BigMatrix *a = (BigMatrix*)R_ExternalPtrAddr(aP);
MatrixAccessor<int> asaveAcc(*asave);
MatrixAccessor<int> aAcc(*a);
int *asaveCol, *aCol;
int *insamp = INTEGER(insampP);
// Set up working variables.
index_type nCols = asave->ncol();
index_type nRows = asave->nrow();
index_type i, ja, jb;
// For each numerical variable, move all the in-sample data to the top rows
// of a.
for (i = 0; i < nCols; i++) {
asaveCol = asaveAcc[i];
aCol = aAcc[i];
for (ja = 0, jb = 0; ja < nRows; ja++) {
if (insamp[asaveCol[ja] - 1] >= 1) {
aCol[jb++] = asaveCol[ja];
}
}
}
return R_NilValue;
}
示例2: install
/* Pointer utility, returns a double pointer for either a BigMatrix or a
* standard R matrix.
*/
double *
make_double_ptr (SEXP matrix, SEXP isBigMatrix)
{
double *matrix_ptr;
if (LOGICAL_VALUE (isBigMatrix) == (Rboolean) TRUE) // Big Matrix
{
SEXP address = GET_SLOT (matrix, install ("address"));
BigMatrix *pbm =
reinterpret_cast < BigMatrix * >(R_ExternalPtrAddr (address));
if (!pbm)
return (NULL);
// Check that have acceptable big.matrix
if (pbm->row_offset () > 0 && pbm->ncol () > 1)
{
std::string errMsg =
string ("sub.big.matrix objects cannoth have row ") +
string
("offset greater than zero and number of columns greater than 1");
Rf_error (errMsg.c_str ());
return (NULL);
}
index_type offset = pbm->nrow () * pbm->col_offset ();
matrix_ptr = reinterpret_cast < double *>(pbm->matrix ()) + offset;
}
else // Regular R Matrix
{
matrix_ptr = NUMERIC_DATA (matrix);
}
return (matrix_ptr);
};
示例3: SepMatrixAccessor
SepMatrixAccessor( BigMatrix &bm)
{
_ppMat = reinterpret_cast<T**>(bm.matrix());
_rowOffset = bm.row_offset();
_colOffset = bm.col_offset();
_totalRows = bm.nrow();
_totalCols = bm.ncol();
}
示例4: ComputePvalsMain
SEXP ComputePvalsMain(SEXP Rinmat, SEXP Routmat, SEXP Routcol) {
BigMatrix *inMat = reinterpret_cast<BigMatrix*>(R_ExternalPtrAddr(Rinmat));
BigMatrix *outMat = reinterpret_cast<BigMatrix*>(R_ExternalPtrAddr(Routmat));
double outCol = NUMERIC_DATA(Routcol)[0];
if (inMat->separated_columns() != outMat->separated_columns())
Rf_error("all big matrices are not the same column separated type");
if (inMat->matrix_type() != outMat->matrix_type())
Rf_error("all big matrices are not the same matrix type");
if (inMat->ncol() != outMat->nrow())
Rf_error("inMat # of cols must be the same as outMat # of rows");
CALL_BIGFUNCTION_ARGS_THREE(ComputePvals, inMat, outMat, outCol)
return(ret);
}
示例5: kmeansBigMatrix
SEXP kmeansBigMatrix(SEXP x, SEXP cen, SEXP clust, SEXP clustsizes,
SEXP wss, SEXP itermax, SEXP dist)
{
BigMatrix *pMat = reinterpret_cast<BigMatrix*>(R_ExternalPtrAddr(x));
int dist_calc = INTEGER(dist)[0];
if (dist_calc == 0)
{
if (pMat->separated_columns())
{
switch (pMat->matrix_type())
{
case 1:
return kmeansMatrixEuclid<char>(SepMatrixAccessor<char>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 2:
return kmeansMatrixEuclid<short>(SepMatrixAccessor<short>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 4:
return kmeansMatrixEuclid<int>(SepMatrixAccessor<int>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 8:
return kmeansMatrixEuclid<double>(SepMatrixAccessor<double>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
}
}
else
{
switch (pMat->matrix_type())
{
case 1:
return kmeansMatrixEuclid<char>(MatrixAccessor<char>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 2:
return kmeansMatrixEuclid<short>(MatrixAccessor<short>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 4:
return kmeansMatrixEuclid<int>(MatrixAccessor<int>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 8:
return kmeansMatrixEuclid<double>(MatrixAccessor<double>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
}
}
}
else
{
if (pMat->separated_columns())
{
switch (pMat->matrix_type())
{
case 1:
return kmeansMatrixCosine<char>(SepMatrixAccessor<char>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 2:
return kmeansMatrixCosine<short>(SepMatrixAccessor<short>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 4:
return kmeansMatrixCosine<int>(SepMatrixAccessor<int>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 8:
return kmeansMatrixCosine<double>(SepMatrixAccessor<double>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
}
}
else
{
switch (pMat->matrix_type())
{
case 1:
return kmeansMatrixCosine<char>(MatrixAccessor<char>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 2:
return kmeansMatrixCosine<short>(MatrixAccessor<short>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 4:
return kmeansMatrixCosine<int>(MatrixAccessor<int>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
case 8:
return kmeansMatrixCosine<double>(MatrixAccessor<double>(*pMat),
pMat->nrow(), pMat->ncol(), cen, clust, clustsizes, wss, itermax);
}
}
}
return R_NilValue;
}