Attention

The vector search and clustering algorithms in RAFT are being migrated to a new library dedicated to vector search called cuVS. We will continue to support the vector search algorithms in RAFT during this move, but will no longer update them after the RAPIDS 24.06 (June) release. We plan to complete the migration by RAPIDS 24.10 (October) release and they will be removed from RAFT altogether in the 24.12 (December) release.

CSR Matrix#

Basic Vocabulary#

#include <raft/core/csr_matrix.hpp>

template<typename IndptrType, typename IndicesType, typename NZType, int is_device>
class compressed_structure_t : public raft::sparse_structure<IndptrType, IndicesType, NZType, is_device>#
#include <csr_matrix.hpp>

Subclassed by raft::compressed_structure< IndptrType, IndicesType, NZType, is_device, ContainerPolicy >, raft::compressed_structure_view< IndptrType, IndicesType, NZType, is_device >

Public Functions

inline compressed_structure_t(IndptrType n_rows, IndicesType n_cols, NZType nnz)#

Constructor when sparsity is already known

Parameters:
  • n_rows – total number of rows in matrix

  • n_cols – total number of columns in matrix

  • nnz – sparsity of matrix

virtual span<IndptrType, is_device> get_indptr() = 0#

Return span containing underlying indptr array

Returns:

span containing underlying indptr array

virtual span<IndicesType, is_device> get_indices() = 0#

Return span containing underlying indices array

Returns:

span containing underlying indices array

template<typename IndptrType, typename IndicesType, typename NZType, bool is_device>
class compressed_structure_view : public raft::compressed_structure_t<IndptrType, IndicesType, NZType, is_device>#
#include <csr_matrix.hpp>

A non-owning view into a compressed sparse structure

The structure representation does not have a value/weight component so that its const-ness can be varied from it.

Template Parameters:
  • IndptrType

  • IndicesType

Public Functions

inline virtual span<indptr_type, is_device> get_indptr() override#

Return span containing underlying indptr array

Returns:

span containing underlying indptr array

inline virtual span<indices_type, is_device> get_indices() override#

Return span containing underlying indices array

Returns:

span containing underlying indices array

template<typename IndptrType, typename IndicesType, typename NZType, bool is_device, template<typename T> typename ContainerPolicy>
class compressed_structure : public raft::compressed_structure_t<IndptrType, IndicesType, NZType, is_device>#
#include <csr_matrix.hpp>

Represents a sparse compressed structure (or adjacency list) which can be used to model both a CSR and CSC matrix.

The structure representation does not have a value/weight component so that its const-ness can be varied from it.

Template Parameters:
  • IndptrType

  • IndicesType

  • ContainerPolicy

Public Functions

inline virtual span<IndptrType, is_device> get_indptr() override#

Return span containing underlying indptr array

Returns:

span containing underlying indptr array

inline virtual span<IndicesType, is_device> get_indices() override#

Return span containing underlying indices array

Returns:

span containing underlying indices array

inline view_type view()#

Return a view of the compressed structure. Structural views are sparsity-preserving so while the structural elements can be updated in a non-const view, the sparsity itself (number of nonzeros) cannot be changed.

Returns:

compressed structure view

inline virtual void initialize_sparsity(NZType nnz) override#

Change the sparsity of the current compressed structure. This will resize the underlying data arrays.

Parameters:

nnz – new sparsity

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, bool is_device>
class csr_matrix_view : public raft::sparse_matrix_view<ElementType, compressed_structure_view<IndptrType, IndicesType, NZType, is_device>, is_device>#
#include <csr_matrix.hpp>
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, bool is_device, template<typename T> typename ContainerPolicy, SparsityType sparsity_type = SparsityType::OWNING, typename structure_type = std::conditional_t<sparsity_type == SparsityType::OWNING, compressed_structure<IndptrType, IndicesType, NZType, is_device, ContainerPolicy>, compressed_structure_view<IndptrType, IndicesType, NZType, is_device>>>
class csr_matrix : public sparse_matrix<ElementType, std::conditional_t<SparsityType::OWNING == SparsityType::OWNING, compressed_structure<IndptrType, IndicesType, NZType, is_device, ContainerPolicy>, compressed_structure_view<IndptrType, IndicesType, NZType, is_device>>, csr_matrix_view<ElementType, IndptrType, IndicesType, NZType, is_device>, is_device, ContainerPolicy>#
#include <csr_matrix.hpp>

Public Functions

template<typename = std::enable_if<sparsity_type == SparsityType::OWNING>>
inline void initialize_sparsity(NZType nnz)#

Initialize the sparsity on this instance if it was not known upon construction Please note this will resize the underlying memory buffers

Parameters:

nnz – new sparsity to initialize.

inline structure_view_type structure_view()#

Return a view of the structure underlying this matrix

Returns:

Device CSR Matrix#

#include <raft/core/device_csr_matrix.hpp>

template<typename IndptrType, typename IndicesType, typename NZType>
using device_compressed_structure_view = compressed_structure_view<IndptrType, IndicesType, NZType, true>#

Specialization for a sparsity-preserving compressed structure view which uses device memory

template<typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = device_uvector_policy>
using device_compressed_structure = compressed_structure<IndptrType, IndicesType, NZType, true, ContainerPolicy>#

Specialization for a sparsity-owning compressed structure which uses device memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType>
using device_csr_matrix_view = csr_matrix_view<ElementType, IndptrType, IndicesType, NZType, true>#

Specialization for a csr matrix view which uses device memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = device_uvector_policy, SparsityType sparsity_type = SparsityType::OWNING>
using device_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, true, ContainerPolicy, sparsity_type>#
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = device_uvector_policy>
using device_sparsity_owning_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, true, ContainerPolicy>#

Specialization for a sparsity-owning csr matrix which uses device memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = device_uvector_policy>
using device_sparsity_preserving_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, true, ContainerPolicy, SparsityType::PRESERVING>#

Specialization for a sparsity-preserving csr matrix which uses device memory

template<typename T>
constexpr bool is_device_csr_matrix_view_v = is_device_csr_matrix_view<T>::value#
template<typename T>
constexpr bool is_device_csr_matrix_v = is_device_csr_matrix<T>::value#
template<typename T>
constexpr bool is_device_csr_sparsity_owning_v = is_device_csr_matrix<T>::value and T::get_sparsity_type() == OWNING#
template<typename T>
constexpr bool is_device_csr_sparsity_preserving_v = is_device_csr_matrix<T>::value and T::get_sparsity_type() == PRESERVING#
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_csr_matrix(raft::resources const &handle, IndptrType n_rows, IndicesType n_cols, NZType nnz = 0)#

Create a sparsity-owning sparse matrix in the compressed-sparse row format. sparsity-owning means that all of the underlying vectors (data, indptr, indices) are owned by the csr_matrix instance. If not known up front, the sparsity can be ignored in this factory function and resize() invoked on the instance once the sparsity is known.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;

raft::resources handle;
csr_matrix = raft::make_device_csr_matrix(handle, n_rows, n_cols);
...
// compute expected sparsity
...
int nnz = 5000;
csr_matrix.initialize_sparsity(nnz);
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] a raft handle for managing expensive device resources

  • n_rows[in] total number of rows in the matrix

  • n_cols[in] total number of columns in the matrix

  • nnz[in] number of non-zeros in the matrix if known [optional]

Returns:

a sparsity-owning sparse matrix in compressed (csr) format

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_csr_matrix(raft::resources const &handle, device_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a sparsity-preserving sparse matrix in the compressed-sparse row format. sparsity-preserving means that a view of the csr sparsity is supplied, allowing the values in the sparsity to change but not the sparsity itself. The csr_matrix instance does not own the sparsity, the sparsity must be known up front, and cannot be resized later.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;

raft::resources handle;
coo_structure = raft::make_device_compressed_structure(handle, n_rows, n_cols);
...
// compute expected sparsity
...
csr_structure.initialize_sparsity(nnz);
csr_matrix = raft::make_device_csr_matrix(handle, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] raft handle for managing expensive device resources

  • structure[in] a sparsity-preserving compressed structural view

Returns:

a sparsity-preserving sparse matrix in compressed (csr) format

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_csr_matrix_view(ElementType *ptr, device_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a non-owning sparse matrix view in the coordinate format. This is sparsity-preserving, meaning that the underlying sparsity is known and cannot be changed. Use the sparsity-owning coo_matrix if sparsity needs to be mutable.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following pointer is assumed to reference device memory for a size of nnz
float* d_elm_ptr = ...;

raft::resources handle;
csr_structure = raft::make_device_compressed_structure(handle, n_rows, n_cols, nnz);
csr_matrix_view = raft::make_device_csr_matrix_view(handle, d_elm_ptr, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • ptr[in] a pointer to array of nonzero matrix elements on device (size nnz)

  • structure[in] a sparsity-preserving compressed sparse structural view

Returns:

a sparsity-preserving csr matrix view

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_csr_matrix_view(raft::device_span<ElementType> elements, device_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a non-owning sparse matrix view in the compressed-sparse row format. This is sparsity-preserving, meaning that the underlying sparsity is known and cannot be changed. Use the sparsity-owning coo_matrix if sparsity needs to be mutable.

#include <raft/core/resources.hpp>
#include <raft/core/device_span.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following span is assumed to be of size nnz
raft::device_span<float> d_elm_ptr;

raft::resources handle;
csr_structure = raft::make_device_compressed_structure(handle, n_rows, n_cols, nnz);
csr_matrix_view = raft::make_device_csr_matrix_view(handle, d_elm_ptr, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • elements[in] device span containing array of matrix elements (size nnz)

  • structure[in] a sparsity-preserving structural view

Returns:

a sparsity-preserving csr matrix view

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_compressed_structure(raft::resources const &handle, IndptrType n_rows, IndicesType n_cols, NZType nnz = 0)#

Create a sparsity-owning compressed structure. This is not sparsity-preserving, meaning that the underlying sparsity does not need to be known upon construction. When not known up front, the allocation of the underlying indices array is delayed until resize(nnz) is invoked.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

raft::resources handle;
csr_structure = raft::make_device_compressed_structure(handle, n_rows, n_cols, nnz);
...
// compute expected sparsity
...
csr_structure.initialize_sparsity(nnz);
Template Parameters:
  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] raft handle for managing expensive device resources

  • n_rows[in] total number of rows

  • n_cols[in] total number of cols

  • nnz[in] total number of nonzeros, if known

Returns:

a sparsity-owning compressed structure instance

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_compressed_structure_view(IndptrType *indptr, IndicesType *indices, IndptrType n_rows, IndicesType n_cols, NZType nnz)#

Create a non-owning sparsity-preserved compressed structure view. Sparsity-preserving means that the underlying sparsity is known and cannot be changed. Use the sparsity-owning version if the sparsity is not known up front.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following pointer is assumed to reference device memory of size n_rows+1
int *indptr = ...;

// The following pointer is assumed to reference device memory of size nnz
int *indices = ...;

raft::resources handle;
csr_structure = raft::make_device_compressed_structure_view(handle, indptr, indices, n_rows,
n_cols, nnz);
*

Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • indptr[in] structural indptr (size n_rows+1)

  • indices[in] structural indices (size nnz)

  • n_rows[in] total number of rows

  • n_cols[in] total number of columns

  • nnz[in] number of non-zeros

Returns:

a sparsity-preserving compressed structural view

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_device_compressed_structure_view(raft::device_span<IndptrType> indptr, raft::device_span<IndicesType> indices, IndicesType n_cols)#

Create a non-owning sparsity-preserved compressed structure view. Sparsity-preserving means that the underlying sparsity is known and cannot be changed. Use the sparsity-owning version if the sparsity is not known up front.

#include <raft/core/resources.hpp>
#include <raft/core/device_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following device spans is assumed to be of size n_rows+1
raft::device_span<int> indptr;

// The following device span is assumed to be of size nnz
raft::device_span<int> indices;

raft::resources handle;
csr_structure = raft::make_device_compressed_structure_view(handle, indptr, indices, n_rows,
n_cols);
Template Parameters:
  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • indptr[in] structural indptr (size n_rows+1)

  • indices[in] structural indices (size nnz)

  • n_cols[in] total number of columns

Returns:

a sparsity-preserving compressed structural view

template<typename T>
struct is_device_csr_matrix_view : public std::false_type#
#include <device_csr_matrix.hpp>
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType>
struct is_device_csr_matrix_view<device_csr_matrix_view<ElementType, IndptrType, IndicesType, NZType>> : public std::true_type#
#include <device_csr_matrix.hpp>
template<typename T>
struct is_device_csr_matrix : public std::false_type#
#include <device_csr_matrix.hpp>
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy, SparsityType sparsity_type>
struct is_device_csr_matrix<device_csr_matrix<ElementType, IndptrType, IndicesType, NZType, ContainerPolicy, sparsity_type>> : public std::true_type#
#include <device_csr_matrix.hpp>

Host CSR Matrix#

#include <raft/core/host_csr_matrix.hpp>

template<typename IndptrType, typename IndicesType, typename NZType>
using host_compressed_structure_view = compressed_structure_view<IndptrType, IndicesType, NZType, false>#

Specialization for a sparsity-preserving compressed structure view which uses host memory

template<typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = host_vector_policy>
using host_compressed_structure = compressed_structure<IndptrType, IndicesType, NZType, false, ContainerPolicy>#

Specialization for a sparsity-owning compressed structure which uses host memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType>
using host_csr_matrix_view = csr_matrix_view<ElementType, IndptrType, IndicesType, NZType, false>#

Specialization for a csr matrix view which uses host memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = host_vector_policy, SparsityType sparsity_type = SparsityType::OWNING>
using host_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, false, ContainerPolicy, sparsity_type>#
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = host_vector_policy>
using host_sparsity_owning_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, false, ContainerPolicy>#

Specialization for a sparsity-owning csr matrix which uses host memory

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy = host_vector_policy>
using host_sparsity_preserving_csr_matrix = csr_matrix<ElementType, IndptrType, IndicesType, NZType, false, ContainerPolicy, SparsityType::PRESERVING>#

Specialization for a sparsity-preserving csr matrix which uses host memory

template<typename T>
constexpr bool is_host_csr_matrix_view_v = is_host_csr_matrix_view<T>::value#
template<typename T>
constexpr bool is_host_csr_matrix_v = is_host_csr_matrix<T>::value#
template<typename T>
constexpr bool is_host_csr_sparsity_owning_v = is_host_csr_matrix<T>::value and T::get_sparsity_type() == OWNING#
template<typename T>
constexpr bool is_host_csr_sparsity_preserving_v = std::disjunction_v<is_host_csr_matrix_view<T>, std::bool_constant<is_host_csr_matrix<T>::value and T::get_sparsity_type() == PRESERVING>>#
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_csr_matrix(raft::resources const &handle, IndptrType n_rows, IndicesType n_cols, NZType nnz = 0)#

Create a sparsity-owning sparse matrix in the compressed-sparse row format. sparsity-owning means that all of the underlying vectors (data, indptr, indices) are owned by the csr_matrix instance. If not known up front, the sparsity can be ignored in this factory function and resize() invoked on the instance once the sparsity is known.

#include <raft/core/host_resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;

raft::resources handle;
csr_matrix = raft::make_host_csr_matrix(handle, n_rows, n_cols);
...
// compute expected sparsity
...
int nnz = 5000;
csr_matrix.initialize_sparsity(nnz);
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] raft handle for managing expensive resources

  • n_rows[in] total number of rows in the matrix

  • n_cols[in] total number of columns in the matrix

  • nnz[in] number of non-zeros in the matrix if known [optional]

Returns:

a sparsity-owning sparse matrix in compressed (csr) format

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_csr_matrix(raft::resources const &handle, host_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a sparsity-preserving sparse matrix in the compressed-sparse row format. sparsity-preserving means that a view of the csr sparsity is supplied, allowing the values in the sparsity to change but not the sparsity itself. The csr_matrix instance does not own the sparsity, the sparsity must be known up front, and cannot be resized later.

#include <raft/core/resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;

raft::resources handle;
coo_structure = raft::make_host_compressed_structure(handle, n_rows, n_cols);
...
// compute expected sparsity
...
csr_structure.initialize_sparsity(nnz);
csr_matrix = raft::make_host_csr_matrix(handle, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] raft handle for managing expensive resources

  • structure[in] a sparsity-preserving compressed structural view

Returns:

a sparsity-preserving sparse matrix in compressed (csr) format

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_csr_matrix_view(ElementType *ptr, host_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a non-owning sparse matrix view in the coordinate format. This is sparsity-preserving, meaning that the underlying sparsity is known and cannot be changed. Use the sparsity-owning coo_matrix if sparsity needs to be mutable.

#include <raft/core/resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following pointer is assumed to reference device memory for a size of nnz
float* h_elm_ptr = ...;

raft::resources handle;
csr_structure = raft::make_host_compressed_structure(handle, n_rows, n_cols, nnz);
csr_matrix_view = raft::make_host_csr_matrix_view(handle, h_elm_ptr, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • ptr[in] a pointer to array of nonzero matrix elements on host (size nnz)

  • structure[in] a sparsity-preserving compressed sparse structural view

Returns:

a sparsity-preserving csr matrix view

template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_csr_matrix_view(raft::host_span<ElementType> elements, host_compressed_structure_view<IndptrType, IndicesType, NZType> structure)#

Create a non-owning sparse matrix view in the compressed-sparse row format. This is sparsity-preserving, meaning that the underlying sparsity is known and cannot be changed. Use the sparsity-owning coo_matrix if sparsity needs to be mutable.

#include <raft/core/resources.hpp>
#include <raft/core/host_span.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following span is assumed to be of size nnz
raft::host_span<float> h_elm_ptr;

raft::resources handle;
csr_structure = raft::make_host_compressed_structure(handle, n_rows, n_cols, nnz);
csr_matrix_view = raft::make_host_csr_matrix_view(handle, h_elm_ptr, csr_structure.view());
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • elements[in] host span containing array of matrix elements (size nnz)

  • structure[in] a sparsity-preserving structural view

Returns:

a sparsity-preserving csr matrix view

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_compressed_structure(raft::resources const &handle, IndptrType n_rows, IndicesType n_cols, NZType nnz = 0)#

Create a sparsity-owning compressed structure. This is not sparsity-preserving, meaning that the underlying sparsity does not need to be known upon construction. When not known up front, the allocation of the underlying indices array is delayed until resize(nnz) is invoked.

#include <raft/core/resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

raft::resources handle;
csr_structure = raft::make_host_compressed_structure(handle, n_rows, n_cols, nnz);
...
// compute expected sparsity
...
csr_structure.initialize_sparsity(nnz);
*

Template Parameters:
  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • handle[in] raft handle for managing expensive resources

  • n_rows[in] total number of rows

  • n_cols[in] total number of cols

  • nnz[in] total number of nonzeros, if known

Returns:

a sparsity-owning compressed structure instance

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_compressed_structure_view(IndptrType *indptr, IndicesType *indices, IndptrType n_rows, IndicesType n_cols, NZType nnz)#

Create a non-owning sparsity-preserved compressed structure view. Sparsity-preserving means that the underlying sparsity is known and cannot be changed. Use the sparsity-owning version if the sparsity is not known up front.

#include <raft/core/resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following pointer is assumed to reference host-accessible memory of size n_rows+1
int *indptr = ...;

// The following pointer is assumed to reference host-accessible memory of size nnz
int *indices = ...;

raft::resources handle;
csr_structure = raft::make_host_compressed_structure_view(handle, indptr, indices, n_rows,
n_cols, nnz);
Template Parameters:
  • ElementType

  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • indptr[in] structural indptr (size n_rows+1)

  • indices[in] structural indices (size nnz)

  • n_rows[in] total number of rows

  • n_cols[in] total number of columns

  • nnz[in] number of non-zeros

Returns:

a sparsity-preserving compressed structural view

template<typename IndptrType, typename IndicesType, typename NZType = uint64_t>
auto make_host_compressed_structure_view(raft::host_span<IndptrType> indptr, raft::host_span<IndicesType> indices, IndicesType n_cols)#

Create a non-owning sparsity-preserved compressed structure view. Sparsity-preserving means that the underlying sparsity is known and cannot be changed. Use the sparsity-owning version if the sparsity is not known up front.

#include <raft/core/resources.hpp>
#include <raft/core/host_csr_matrix.hpp>

int n_rows = 100000;
int n_cols = 10000;
int nnz = 5000;

// The following host span is assumed to be of size n_rows+1
raft::host_span<int> indptr;

// The following host span is assumed to be of size nnz
raft::host_span<int> indices;

raft::resources handle;
csr_structure = raft::make_host_compressed_structure_view(handle, indptr, indices, n_rows,
n_cols);
Template Parameters:
  • IndptrType

  • IndicesType

  • NZType

Parameters:
  • indptr[in] structural indptr (size n_rows+1)

  • indices[in] structural indices (size nnz)

  • n_cols[in] total number of columns

Returns:

a sparsity-preserving compressed structural view

template<typename T>
struct is_host_csr_matrix_view : public std::false_type#
#include <host_csr_matrix.hpp>
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType>
struct is_host_csr_matrix_view<host_csr_matrix_view<ElementType, IndptrType, IndicesType, NZType>> : public std::true_type#
#include <host_csr_matrix.hpp>
template<typename T>
struct is_host_csr_matrix : public std::false_type#
#include <host_csr_matrix.hpp>
template<typename ElementType, typename IndptrType, typename IndicesType, typename NZType, template<typename T> typename ContainerPolicy, SparsityType sparsity_type>
struct is_host_csr_matrix<host_csr_matrix<ElementType, IndptrType, IndicesType, NZType, ContainerPolicy, sparsity_type>> : public std::true_type#
#include <host_csr_matrix.hpp>