tatami_chunked
Helpers to create custom chunked tatami matrices
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
tatami_chunked::MockSubsettedSparseChunk Class Reference

Mock a subsettable sparse chunk for a CustomSparseChunkedMatrix. More...

#include <mock_sparse_chunk.hpp>

Classes

struct  Workspace
 

Public Types

typedef double value_type
 

Public Member Functions

template<typename Index_ >
void extract (bool row, Index_ target_start, Index_ target_length, Index_ non_target_start, Index_ non_target_length, Workspace &work, const std::vector< value_type * > &output_values, const std::vector< Index_ * > &output_indices, Index_ *output_number, Index_ shift) const
 
template<typename Index_ >
void extract (bool row, Index_ target_start, Index_ target_length, const std::vector< Index_ > &non_target_indices, Workspace &work, const std::vector< value_type * > &output_values, const std::vector< Index_ * > &output_indices, Index_ *output_number, Index_ shift) const
 
template<typename Index_ >
void extract (bool row, const std::vector< Index_ > &target_indices, Index_ non_target_start, Index_ non_target_length, Workspace &work, const std::vector< value_type * > &output_values, const std::vector< Index_ * > &output_indices, Index_ *output_number, Index_ shift) const
 
template<typename Index_ >
void extract (bool row, const std::vector< Index_ > &target_indices, const std::vector< Index_ > &non_target_indices, Workspace &work, const std::vector< value_type * > &output_values, const std::vector< Index_ * > &output_indices, Index_ *output_number, Index_ shift) const
 

Static Public Attributes

static constexpr bool use_subset = true
 

Detailed Description

Mock a subsettable sparse chunk for a CustomSparseChunkedMatrix.

Mock a subsettable sparse chunk for use inside a CustomSparseChunkedMatrix. Each chunk should represent a (possible compressed) 2-dimensional array of numeric values. The interface is smarter as it only extracts elements of interest along the target dimension. The elements of interest may be either a contiguous block or a indexed subset, as predicted for each chunk from the OracularSubsettedSlabCache. This provides some opportunities for optimization if the chunk supports partial reads.

Member Typedef Documentation

◆ value_type

Type of the value stored in this chunk. Implementations can use any numeric type.

Member Function Documentation

◆ extract() [1/4]

template<typename Index_ >
void tatami_chunked::MockSubsettedSparseChunk::extract ( bool  row,
Index_  target_start,
Index_  target_length,
Index_  non_target_start,
Index_  non_target_length,
Workspace work,
const std::vector< value_type * > &  output_values,
const std::vector< Index_ * > &  output_indices,
Index_ output_number,
Index_  shift 
) const
inline

Extract a contiguous block of the target dimension into an output buffer. For each element, this method will only extract a contiguous block of the non-target dimension.

Template Parameters
Index_Integer type for the row/column indices of the CustomSparseChunkedMatrix.
Parameters
rowWhether to extract rows from the chunk, i.e., the rows are the target dimension.
target_startIndex of the start of a contiguous block of the target dimension to be extracted. If row = true, this is the first row, otherwise it is the first column.
target_lengthLength of the contiguous block of the target dimension to be extracted. If row = true, this is the number of rows, otherwise it is the number of columns. This is guaranteed to be positive.
non_target_startIndex of the start of a contiguous block of the non-target dimension to be extracted. If row = true, this is the first column, otherwise it is the first row.
non_target_lengthLength of the contiguous block of the non-target dimension to be extracted. If row = true, this is the number of columns, otherwise it is the number of rows. This is guaranteed to be positive.
workRe-usable workspace for extraction from one or more chunks.
[out]output_valuesVector of pointers in which to store the values of non-zero elements. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no values should be stored.
[out]output_indicesVector of vectors in which to store the indices of the non-zero elements along the non-target dimension. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no indices should be stored.
[in,out]output_numberPointer to an array of length equal to the extent of the target dimension. Each entry i specifies the number of non-zero elements that are already present in output_values[i] and output_indices[i].
shiftShift to be added to the chunk's reported indices when storing them in output_indices.

If row = true, we would extract a block of rows [target_start, target_start + length) and a block of columns [non_target_start, non_target_start + non_target_length); conversely, if row = false, we would extract a block of columns from the target_* arguments and the block of rows from the non_target_*arguments. Given a target dimension element p, the values of non-zero elements from the requested non-target block should be stored at output_values[p] + output_number[p]. The non-target indices for those non-zero elements should be increased by shift and stored at output_indices[p] + output_number[p] in ascending order. output_number[p] should then be increased by the number of non-zero entries stored in this manner. This layout allows concatenation of multiple sparse chunks into a single set of vectors for easier fetching in the CustomSparseChunkedMatrix.

Note that implementions of this method do not need to have the exact same template arguments as shown here, as long as the types can be deduced.

◆ extract() [2/4]

template<typename Index_ >
void tatami_chunked::MockSubsettedSparseChunk::extract ( bool  row,
Index_  target_start,
Index_  target_length,
const std::vector< Index_ > &  non_target_indices,
Workspace work,
const std::vector< value_type * > &  output_values,
const std::vector< Index_ * > &  output_indices,
Index_ output_number,
Index_  shift 
) const
inline

Extract a contiguous block of the target dimension into an output buffer. For each element, this method will only extract an indexed subset of the non-target dimension.

Template Parameters
Index_Integer type for the row/column indices of the CustomSparseChunkedMatrix.
Parameters
rowWhether to extract rows from the chunk, i.e., the rows are the target dimension.
target_startIndex of the start of a contiguous block of the target dimension to be extracted. If row = true, this is the first row, otherwise it is the first column.
target_lengthLength of the contiguous block of the target dimension to be extracted. If row = true, this is the number of rows, otherwise it is the number of columns. This is guaranteed to be positive.
non_target_indicesIndices of the elements on the non-target dimension to be extracted. If row = true, these are column indices, otherwise these are row indices. This is guaranteed to be non-empty with unique and sorted indices.
workRe-usable workspace for extraction from one or more chunks.
[out]output_valuesVector of pointers in which to store the values of non-zero elements. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no values should be stored.
[out]output_indicesVector of vectors in which to store the indices of the non-zero elements along the non-target dimension. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no indices should be stored.
[in,out]output_numberPointer to an array of length equal to the extent of the target dimension. Each entry i specifies the number of non-zero elements that are already present in output_values[i] and output_indices[i].
shiftShift to be added to the chunk's reported indices when storing them in output_indices.

If row = true, we would extract a block of rows [target_start, target_start + length) and a subset of columns in non_target_indices; conversely, if row = false, we would extract a block of columns from the target_* arguments and a subset of rows from non_target_indices. Given a target dimension element p, the values of non-zero elements from the requested non-target subset should be stored at output_values[p] + output_number[p]. The non-target indices for those non-zero elements should be increased by shift and stored at output_indices[p] + output_number[p] in ascending order. output_number[p] should then be increased by the number of non-zero entries stored in this manner. This layout allows concatenation of multiple sparse chunks into a single set of vectors for easier fetching in the CustomSparseChunkedMatrix.

Note that implementions of this method do not need to have the exact same template arguments as shown here, as long as the types can be deduced.

◆ extract() [3/4]

template<typename Index_ >
void tatami_chunked::MockSubsettedSparseChunk::extract ( bool  row,
const std::vector< Index_ > &  target_indices,
Index_  non_target_start,
Index_  non_target_length,
Workspace work,
const std::vector< value_type * > &  output_values,
const std::vector< Index_ * > &  output_indices,
Index_ output_number,
Index_  shift 
) const
inline

Extract an indexed subset of the target dimension into an output buffer. For each element, this method will only extract a contiguous block of the non-target dimension.

Template Parameters
Index_Integer type for the row/column indices of the CustomSparseChunkedMatrix.
Parameters
rowWhether to extract rows from the chunk, i.e., the rows are the target dimension.
target_indicesIndices of the elements on the target dimension to be extracted. If row = true, these are row indices, otherwise these are column indices. This is guaranteed to be non-empty with unique and sorted indices.
non_target_startIndex of the start of a contiguous block of the non-target dimension to be extracted. If row = true, this is the first column, otherwise it is the first row.
non_target_lengthLength of the contiguous block of the non-target dimension to be extracted. If row = true, this is the number of columns, otherwise it is the number of rows. This is guaranteed to be positive.
workRe-usable workspace for extraction from one or more chunks.
[out]output_valuesVector of pointers in which to store the values of non-zero elements. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no values should be stored.
[out]output_indicesVector of vectors in which to store the indices of the non-zero elements along the non-target dimension. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no indices should be stored.
[in,out]output_numberPointer to an array of length equal to the extent of the target dimension. Each entry i specifies the number of non-zero elements that are already present in output_values[i] and output_indices[i].
shiftShift to be added to the chunk's reported indices when storing them in output_indices.

If row = true, we would extract a subset of rows in target_indices and a block of columns [non_target_start, non_target_start + non_target_length), conversely, if row = false, we would extract a subset of columns from the target_* arguments and the block of rows from the non_target_* arguments. Given a target dimension element p, the values of non-zero elements from the requested non-target block should be stored at output_values[p] + output_number[p]. The non-target indices for those non-zero elements should be increased by shift and stored at output_indices[p] + output_number[p] in ascending order. output_number[p] should then be increased by the number of non-zero entries stored in this manner. This layout allows concatenation of multiple sparse chunks into a single set of vectors for easier fetching in the CustomSparseChunkedMatrix.

Note that implementions of this method do not need to have the exact same template arguments as shown here, as long as the types can be deduced.

◆ extract() [4/4]

template<typename Index_ >
void tatami_chunked::MockSubsettedSparseChunk::extract ( bool  row,
const std::vector< Index_ > &  target_indices,
const std::vector< Index_ > &  non_target_indices,
Workspace work,
const std::vector< value_type * > &  output_values,
const std::vector< Index_ * > &  output_indices,
Index_ output_number,
Index_  shift 
) const
inline

Extract an indexed subset of the target dimension into an output buffer. For each element, this method will only extract an indexed subset of the non-target dimension.

Template Parameters
Index_Integer type for the row/column indices of the CustomSparseChunkedMatrix.
Parameters
rowWhether to extract rows from the chunk, i.e., the rows are the target dimension.
target_indicesIndices of the elements on the target dimension to be extracted. If row = true, these are row indices, otherwise these are column indices. This is guaranteed to be non-empty with unique and sorted indices.
non_target_indicesIndices of the elements on the non-target dimension to be extracted. If row = true, these are column indices, otherwise these are row indices. This is guaranteed to be non-empty with unique and sorted indices.
workRe-usable workspace for extraction from one or more chunks.
[out]output_valuesVector of pointers in which to store the values of non-zero elements. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no values should be stored.
[out]output_indicesVector of vectors in which to store the indices of the non-zero elements along the non-target dimension. This has length equal to the extent of the target dimension for this chunk. Each pointer corresponds to an element of the target dimension and refers to an array of length no less than the extent of the non-target dimension of the chunk. Alternatively, this vector may be empty, in which case no indices should be stored.
[in,out]output_numberPointer to an array of length equal to the extent of the target dimension. Each entry i specifies the number of non-zero elements that are already present in output_values[i] and output_indices[i].
shiftShift to be added to the chunk's reported indices when storing them in output_indices.

If row = true, we would extract a subset of rows in target_indices and a subset of columns in non_target_indices. conversely, if row = false, we would extract a subset of columns in target_indices and the subset of rows in non_target_indices. Given a target dimension element p, the values of non-zero elements from the requested non-target subset should be stored at output_values[p] + output_number[p]. The non-target indices for those non-zero elements should be increased by shift and stored at output_indices[p] + output_number[p] in ascending order. output_number[p] should then be increased by the number of non-zero entries stored in this manner. This layout allows concatenation of multiple sparse chunks into a single set of vectors for easier fetching in the CustomSparseChunkedMatrix.

Note that implementions of this method do not need to have the exact same template arguments as shown here, as long as the types can be deduced.

Member Data Documentation

◆ use_subset

constexpr bool tatami_chunked::MockSubsettedSparseChunk::use_subset = true
staticconstexpr

Whether to extract a subset of elements on the target dimension. This should be set to true, otherwise a MockSimpleSparseChunk is expected.


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