tatami_chunked
Helpers to create custom chunked tatami matrices
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tatami_chunked::OracularSubsettedSlabCache< Id_, Index_, Slab_ > Class Template Reference

Oracle-aware cache for slabs, plus subsets. More...

#include <OracularSubsettedSlabCache.hpp>

Public Member Functions

 OracularSubsettedSlabCache (std::shared_ptr< const tatami::Oracle< Index_ > > oracle, size_t max_slabs)
 
 OracularSubsettedSlabCache (const OracularSubsettedSlabCache &)=delete
 
OracularSubsettedSlabCacheoperator= (const OracularSubsettedSlabCache &)=delete
 
Index_ next ()
 
template<class Ifunction_ , class Cfunction_ , class Pfunction_ >
std::pair< const Slab_ *, Index_next (Ifunction_ identify, Cfunction_ create, Pfunction_ populate)
 
size_t get_max_slabs () const
 
size_t get_num_slabs () const
 

Detailed Description

template<typename Id_, typename Index_, class Slab_>
class tatami_chunked::OracularSubsettedSlabCache< Id_, Index_, Slab_ >

Oracle-aware cache for slabs, plus subsets.

Template Parameters
Id_Type of slab identifier, typically integer.
Index_Type of row/column index produced by the oracle.
Slab_Class for a single slab.

Implement an oracle-aware cache for slab subsets. Each slab is defined as the set of chunks required to read an element of the target dimension (or a contiguous block/indexed subset thereof) from a tatami::Matrix. This cache is similar to the OracularSlabCache except that it remembers the subset of elements on the target dimension that were requested for each slab. Slab extractors can use this information to optimize slab loading by ignoring unneeded elements.

Constructor & Destructor Documentation

◆ OracularSubsettedSlabCache() [1/2]

tatami_chunked::OracularSubsettedSlabCache< Id_, Index_, Slab_ >::OracularSubsettedSlabCache ( std::shared_ptr< const tatami::Oracle< Index_ > >  oracle,
size_t  max_slabs 
)
inline
Parameters
oraclePointer to an tatami::Oracle to be used for predictions.
max_slabsMaximum number of slabs to store.

◆ OracularSubsettedSlabCache() [2/2]

Deleted as the cache holds persistent pointers.

Member Function Documentation

◆ operator=()

Deleted as the cache holds persistent pointers.

◆ next() [1/2]

This method is intended to be called when num_slabs = 0, to provide callers with the oracle predictions for non-cached extraction of data. Calls to this method should not be intermingled with calls to its overload below; the latter should only be called when max_slabs > 0.

Returns
The next prediction from the oracle.

◆ next() [2/2]

std::pair< const Slab_ *, Index_ > tatami_chunked::OracularSubsettedSlabCache< Id_, Index_, Slab_ >::next ( Ifunction_  identify,
Cfunction_  create,
Pfunction_  populate 
)
inline

Fetch the next slab according to the stream of predictions provided by the tatami::Oracle. This method should only be called if num_slabs > 0 in the constructor; otherwise, no slabs are actually available and cannot be returned.

Template Parameters
Ifunction_Function to identify the slab containing each predicted row/column.
Cfunction_Function to create a new slab.
Pfunction_Function to populate zero, one or more slabs with their contents.
Parameters
identifyFunction that accepts an i, an Index_ containing the predicted index of a single element on the target dimension. This should return a pair containing:
  1. An Id_, the identifier of the slab containing i. This is typically defined as the index of the slab on the target dimension. For example, if each chunk takes up 10 rows, attempting to access row 21 would require retrieval of slab 2.
  2. An Index_, the index of row/column i inside that slab. For example, if each chunk takes up 10 rows, attempting to access row 21 would yield an offset of 1.
createFunction that accepts no arguments and returns a Slab_ object with sufficient memory to hold a slab's contents when used in populate(). This may also return a default-constructed Slab_ object if the allocation is done dynamically per slab in populate().
populateFunction that accepts a std::vector<std::tuple<Id_, Slab_*, const OracularSubsettedSlabCacheSelectionDetails<Index_>*> >& specifying the slabs to be populated. The first Id_ element of each tuple contains the slab identifier, i.e., the first element returned by the identify function. The second Slab_* element specifies the object which to store the contents of the slab. The third OracularSubsettedSlabCacheSelectionDetails<Index_>* element contains information about the desired subset of elements on the target dimension of the slab. This function should iterate over the vector and populate the desired subset of each slab. The vector is guaranteed to be non-empty but is not guaranteed to be sorted.
Returns
Pair containing (1) a pointer to a cached slab and (2) the index of the next predicted row/column inside the retrieved slab.

◆ get_max_slabs()

Returns
Maximum number of slabs in the cache.

◆ get_num_slabs()

Returns
Number of slabs currently in the cache.

The documentation for this class was generated from the following file: