Skip to content

Accessing low-level API from other packages #1469

Description

@Enchufa2

Developing a package that plugs into torch is a big problem that you solved via lantern, so it would be nice to export that solution for other packages. In fact, you partially did, putting the API in inst/include, but it's not currently usable.

Basically I have an algorithm in C++, so going through the R API is not an option, and it would be great to have access to torch directly, same access as e.g. RcppEigen or RcppArmadillo provide. In other words, it would be nice to be able to do something like

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcp::depends(torch)]]
#include <torch.h>

// [[Rcpp::export]]
torch::Tensor zeros(int rows, int cols) {
  int64_t sizes[2] = {rows, cols};
  torch::IntArrayRef sizes_ref = torch::IntArrayRef(sizes);
  torch::TensorOptions options = lantern_TensorOptions();
  torch::Dtype dtype = lantern_Dtype_float64();
  options = lantern_TensorOptions_dtype(options.get(), dtype.get());
  return lantern_zeros_intarrayref_tensoroptions(sizes_ref.get(), options.get());
}

/*** R
zeros(5, 3)
*/

If this worked, we could basically embed access to torch in C++ code without routing anything through R. AFAICT, to provide this, torch would need to:

  • Provide the mechanism to inject the includes into CPPFLAGS.
  • Provide a low-level API point to start lantern.
  • Register a bunch of functions like deleters and so on, so that objects in the torch namespace work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions