Compressed Sparse Rows (CSR) Table¶
Refer to API Reference: Compressed Sparse Rows Table to learn more.
Programming Interface¶
All types and functions in this section are declared in the
oneapi::dal
namespace and available via the inclusion of the
oneapi/dal/table/csr.hpp
header file.
-
class csr_table¶
Public Static Methods
-
static std::int64_t kind()¶
Returns the unique id of csr_table class.
-
template<typename Data>
static csr_table wrap(const Data *data_pointer, const std::int64_t *column_indices_pointer, const std::int64_t *row_offsets_pointer, std::int64_t row_count, std::int64_t column_count, sparse_indexing indexing = sparse_indexing::one_based)¶ Creates a new csr_table instance from externally-defined data, columns indices and row offsets memory blocks. Table object refers to the memory blocks but does not own them. The responsibility to free the memory blocks remains on the user side. The
data
should point to the data_pointer memory block. Thecolumns_indices
should point to the column_indices_pointer memory block. Therow_offsets
should point to the row_offsets_pointer memory block.- Template Parameters
Data – The type of elements in the data block that will be stored into the table. The table initializes data types of metadata with this data type. The feature types should be set to default values for
Data
type: contiguous for floating-point, ordinal for integer types. TheData
type should be at least float, double or std::int32_t.- Parameters
data_pointer – The pointer to values block in the CSR layout.
column_indices_pointer – The pointer to column indices block in the CSR layout.
row_offsets_pointer – The pointer to row offsets block in CSR layout.
row_count – The number of rows in the table.
column_count – The number of columns in the table.
indexing – The indexing scheme used to access data in the CSR layout. Should be
sparse_indexing::zero_based
orsparse_indexing::one_based
.
-
template<typename Data>
static csr_table wrap(const dal::array<Data> &data, const dal::array<std::int64_t> &column_indices, const dal::array<std::int64_t> &row_offsets, std::int64_t column_count, sparse_indexing indexing = sparse_indexing::one_based)¶ Creates a new csr_table instance from arrays of data, column indices and row offsets. The created table shares data ownership with the given arrays.
- Template Parameters
Data – The type of elements in the data block that will be stored into the table. The table initializes data types of metadata with this data type. The feature types should be set to default values for
Data
type: contiguous for floating-point, ordinal for integer types. TheData
type should be at least float, double or std::int32_t.- Parameters
data – The array that stores values block in the CSR layout.
column_indices – The array that stores column indices block in the CSR layout.
row_offsets – The array that stores row offsets block in the CSR layout.
column_count – The number of columns in the table.
indexing – The indexing scheme used to access data in the CSR layout. Should be
sparse_indexing::zero_based
orsparse_indexing::one_based
.
Constructors
-
csr_table()¶
Creates a new csr_table instance with zero number of rows and columns. The kind is set to`csr_table::kind()`. All the properties should be set to default values (see the Properties section).
-
csr_table(const table &other)¶
Casts an object of the base table type to a CSR table. If cast is not possible, the operation is equivalent to a default constructor call.
-
template<typename Data>
csr_table(const dal::array<Data> &data, const dal::array<std::int64_t> &column_indices, const dal::array<std::int64_t> &row_offsets, std::int64_t column_count, sparse_indexing indexing = sparse_indexing::one_based)¶ Creates a new csr_table instance from externally-defined data blocks. Table object owns the data, row indices and column indices pointers.
- Template Parameters
Data – The type of elements in the data block that will be stored into the table. The
Data
type should be at least float, double or std::int32_t.- Parameters
data – The array of values in the CSR layout.
column_indices – The array of column indices in the CSR layout.
row_offsets – The array of row offsets in the CSR layout.
column_count – The number of columns in the corresponding dense table.
indexing – The indexing scheme used to access data in the CSR layout. Should be
sparse_indexing::zero_based
orsparse_indexing::one_based
.
-
template<typename Data, typename ConstDataDeleter, typename ConstColumnIndicesDeleter, typename ConstRowOffsetsDeleter>
csr_table(const Data *data_pointer, const std::int64_t *column_indices_pointer, const std::int64_t *row_offsets_pointer, std::int64_t row_count, std::int64_t column_count, ConstDataDeleter &&data_deleter, ConstColumnIndicesDeleter &&column_indices_deleter, ConstRowOffsetsDeleter &&row_offsets_deleter, sparse_indexing indexing = sparse_indexing::one_based)¶ Creates a new csr_table instance from externally-defined data blocks. Table object owns the data, column indices and row offsets pointers. The
data
should point to the data_pointer memory block. Thecolumn_indices
should point to the column_indices_pointer memory block. Therow_offsets
should point to the row_offsets_pointer memory block.- Template Parameters
Data – The type of elements in the data block that will be stored into the table. The
Data
type should be at least float, double or std::int32_t.ConstDataDeleter – The type of a deleter called on data_pointer when the last table that refers it is out of the scope.
ConstColumnIndicesDeleter – The type of a deleter called on column_indices_pointer when the last table that refers it is out of the scope.
ConstRowOffsetsDeleter – The type of a deleter called on row_offsets_pointer when the last table that refers it is out of the scope.
- Parameters
data_pointer – The pointer to values block in the CSR layout.
column_indices_pointer – The pointer to column indices block in the CSR layout.
row_offsets_pointer – The pointer to row offsets block in the CSR layout.
row_count – The number of rows in the table.
column_count – The number of columns in the table.
data_deleter – The deleter that is called on the data_pointer when the last table that refers it is out of the scope.
column_indices_deleter – The deleter that is called on the column_indices_pointer when the last table that refers it is out of the scope.
row_offsets_deleter – The deleter that is called on the row_offsets_pointer when the last table that refers it is out of the scope.
indexing – The indexing scheme used to access data in the CSR layout. Should be
sparse_indexing::zero_based
orsparse_indexing::one_based
.
Public Methods
-
std::int64_t get_kind() const¶
The unique id of the csr table type.
-
std::int64_t get_non_zero_count() const¶
The number of non-zero elements in the table.
-
sparse_indexing get_indexing() const¶
The indexing scheme used to access data in the CSR layout.
-
template<typename Data>
const Data *get_data() const¶ Returns the
data
pointer cast to theData
type. No checks are performed that this type is the actual type of the data within the table.
-
const void *get_data() const¶
The pointer to the data block within the table. Should be equal to nullptr when row_count == 0 and column_count == 0.
-
const std::int64_t *get_column_indices() const¶
Returns the
column_indices
pointer.
-
const std::int64_t *get_row_offsets() const¶
Returns the
row_offsets
pointer.
-
static std::int64_t kind()¶