Giter Site home page Giter Site logo

Comments (8)

YaohuiZeng avatar YaohuiZeng commented on June 6, 2024

Hi Florian,

Thank you very much for taking a look. I just committed the changes. I suspect the error is due to the behavior of "XPtr", since there are some key words "PreserveStorage", "standard_delete_finalizer", etc.

__Z11get_elem_bmIdEdN4Rcpp4XPtrI9BigMatrixNS0_15PreserveStorageEXadL_ZNS0_25standard_delete_finalizerIS2_EEvPT_EEEEddii

from biglasso.

privefl avatar privefl commented on June 6, 2024

You don't have any R/RcppExports.R and src/RcppExports.cpp?

It seems you're making your package "the old way". How do you compile and install your package?

from biglasso.

YaohuiZeng avatar YaohuiZeng commented on June 6, 2024

No, I don't. I used to have RcppExports.cpp, but later combined them into .cpp files. RcppExports.R file just include wrapper R functions for .Call(). The previous version (before adding templates) works well. So I am not sure whether having those RcppExports files make a difference.

I compile and install the package using R CMD commands.

from biglasso.

privefl avatar privefl commented on June 6, 2024

I've tried to pass the accessor with the pointer as argument as it is done there.
You can compare the codes there.
But it doesn't seem to change a thing.

One thing I don't understand is why your utilities.cpp has

// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

while it seems to be modified by hand.

Moreover, I'm currently on Windows, which doesn't help with the debugging.

from biglasso.

YaohuiZeng avatar YaohuiZeng commented on June 6, 2024

Thanks for giving a try! I just did exactly the same thing, and failed too.

I think the return type of functions like cd_gaussian_fit_cpp() should be Rcpp::List, not SEXP. So I changed that, but didn't help.

I also followed the link you pointed out but NOT passing matrix accessor as an argument, instead calling function like BigColSums(xpMat) and it WORKED! (See code below, that code works!!!!!!!)

So really confused about where the bug is!!!!!!!!!

// Logic for BigColSums.
template <typename T>
vector<int> BigColSums2(XPtr<BigMatrix> pMat) {

  // Create the vector we'll store the column sums in.
  MatrixAccessor<T> mat(*pMat);
  vector<int> colSums(pMat->ncol());
  for (size_t i=0; i < pMat->ncol(); i++) {
    for (size_t j=0; j < pMat->ncol(); j++) {
      colSums[i] += mat[i][j];
    }
  }
  return colSums;
}

// Dispatch function for BigColSums
//
// [[Rcpp::export]]
NumericVector BigColSums(SEXP pBigMat) {
  // First we have to tell Rcpp what class to use for big.matrix objects.
  // This object stores the attributes of the big.matrix object passed to it
  // by R.
  XPtr<BigMatrix> xpMat(pBigMat);

  // To access values in the big.matrix, we need to create a MatrixAccessor
  // object of the appropriate type. Note that in every case we are still
  // returning a NumericVector: this is because big.matrix objects only store
  // numeric values in R, even if their type is set to 'char'. The types
  // simply correspond to the number of bytes used for each element.
  switch(xpMat->matrix_type()) {
  case 1:
    return Rcpp::wrap(BigColSums2<char>(xpMat));
  case 2:
    return Rcpp::wrap(BigColSums2<short>(xpMat));
  case 4:
    return Rcpp::wrap(BigColSums2<int>(xpMat));
  case 8:
    return Rcpp::wrap(BigColSums2<double>(xpMat));
  // case 1:
  //   return BigColSums<char>(xpMat);
  // case 2:
  //   return BigColSums<short>(xpMat);
  // case 4:
  //   return BigColSums<int>(xpMat);
  // case 8:
  //   return BigColSums<double>(xpMat);
  default:
    // This case should never be encountered unless the implementation of
    // big.matrix changes, but is necessary to implement shut up compiler
    // warnings.
    throw Rcpp::exception("unknown type detected for big.matrix object!");
  }
}

from biglasso.

YaohuiZeng avatar YaohuiZeng commented on June 6, 2024

BTW, I removed the header lines in utilities.cpp as you pointed out. Sorry for the confusion. As you know, this file was previously automatically generated, but later I decided not to have RcppExports and just made manually changes in this file.

from biglasso.

privefl avatar privefl commented on June 6, 2024

Last guess for me.
Do the functions in utilities.cpp need dispatchers too?

from biglasso.

YaohuiZeng avatar YaohuiZeng commented on June 6, 2024

I don't think so. See here https://github.com/aloysius-lim/bigrf/blob/master/src/growtree.cpp

from biglasso.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.