tatami_r
R bindings to tatami matrices
Loading...
Searching...
No Matches
tatami_r Namespace Reference

tatami bindings for arbitrary R matrices. More...

Classes

class  UnknownMatrix
 Unknown matrix-like object in R. More...
 
struct  UnknownMatrixOptions
 Options for data extraction from an UnknownMatrix. More...
 

Functions

manticore::Executorexecutor ()
 
void set_executor (manticore::Executor *ptr)
 
template<class Function_ , class Index_ >
void parallelize (const Function_ fun, const Index_ ntasks, int nthreads)
 
template<class Function_ >
void parse_SVT_SparseMatrix (const Rcpp::RObject &matrix, const Function_ fun)
 

Detailed Description

tatami bindings for arbitrary R matrices.

Function Documentation

◆ executor()

manticore::Executor & tatami_r::executor ( )
inline

Retrieve a global manticore::Executor object for all tatami_r applications. This function is only available if TATAMI_R_PARALLELIZE_UNKNOWN is defined.

Returns
Reference to a global manticore::Executor. If set_executor() was called with a non-NULL pointer, the provided instance will be used; otherwise, a default instance will be instantiated.

◆ parallelize()

template<class Function_ , class Index_ >
void tatami_r::parallelize ( const Function_ fun,
const Index_ ntasks,
int nthreads )
Template Parameters
Function_Function to be executed.
Index_Integer type for the task indices.
Parameters
funFunction to run in each thread. This is a lambda that should accept three arguments:
  • Integer containing the thread ID.
  • Integer specifying the index of the first task to be executed in a thread.
  • Integer specifying the number of tasks to be executed in a thread.
ntasksNumber of tasks to be executed.
nthreadsNumber of threads to parallelize over.

This function is a drop-in replacement for tatami::parallelize(). The series of integers from [0, ntasks) is split into nthreads contiguous ranges. Each range is used as input to a call to fun within a thread created by the standard <thread> library. Serialization can be achieved via <mutex> in most cases, or manticore::Executor::run() if the task must be performed on the main thread (see executor()).

This function is only available if TATAMI_R_PARALLELIZE_UNKNOWN is defined.

◆ parse_SVT_SparseMatrix()

template<class Function_ >
void tatami_r::parse_SVT_SparseMatrix ( const Rcpp::RObject & matrix,
const Function_ fun )

Parse the contents of a SVT_SparseMatrix from the DelayedArray package. This accounts for different versions of the class definition, different types of the values, and the presence of lacunar leaf nodes.

Template Parameters
Function_Function to be applied at each leaf node.
Parameters
matrixThe SVT_SparseMatrix object.
funFunction to apply to each leaf node, accepting four arguments:
  1. c, an integer specifying the index of the leaf node, i.e., the column index.
  2. indices, an Rcpp::IntegerVector containing the sorted, zero-based indices of the structural non-zero elements in this node (i.e., column).
  3. all_ones, a boolean indicating whether all values in this node/column are equal to 1.
  4. values, an Rcpp::IntegerVector, Rcpp::LogicalVector or Rcpp::NumericVector containing the values of the structural non-zeros. This should be of the same length as indices. It should be ignored if all_ones = true.
The return value of this function is ignored. Note that fun may not be called for all c - if leaf nodes do not contain any data, they will be skipped.

◆ set_executor()

void tatami_r::set_executor ( manticore::Executor * ptr)
inline

Set a global manticore::Executor object for all tatami_r applications. This function is only available if TATAMI_R_PARALLELIZE_UNKNOWN is defined. Calling this function is occasionally necessary if executor() resolves to different instances of a manticore::Executor across different libraries.

Parameters
Pointerto a global manticore::Executor, or NULL to unset this pointer.