Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse Pairwise Distances API Updates #1502

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/include/raft/core/coo_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class coo_matrix_view
using row_type = RowType;
using col_type = ColType;
using nnz_type = NZType;
static constexpr auto get_sparsity_type() { return SparsityType::PRESERVING; }
coo_matrix_view(raft::span<ElementType, is_device> element_span,
coordinate_structure_view<RowType, ColType, NZType, is_device> structure_view)
: sparse_matrix_view<ElementType,
Expand Down
1 change: 1 addition & 0 deletions cpp/include/raft/core/csr_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class csr_matrix_view
using indptr_type = IndptrType;
using indices_type = IndicesType;
using nnz_type = NZType;
static constexpr auto get_sparsity_type() { return SparsityType::PRESERVING; }
csr_matrix_view(
raft::span<ElementType, is_device> element_span,
compressed_structure_view<IndptrType, IndicesType, NZType, is_device> structure_view)
Expand Down
52 changes: 30 additions & 22 deletions cpp/include/raft/core/device_coo_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,37 @@

namespace raft {

template <typename ElementType,
typename RowType,
/**
* Specialization for a sparsity-preserving coordinate structure view which uses device memory
*/
template <typename RowType, typename ColType, typename NZType>
using device_coordinate_structure_view = coordinate_structure_view<RowType, ColType, NZType, true>;

/**
* Specialization for a sparsity-owning coordinate structure which uses device memory
*/
template <typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = device_uvector_policy,
SparsityType sparsity_type = SparsityType::OWNING>
using device_coo_matrix =
coo_matrix<ElementType, RowType, ColType, NZType, true, ContainerPolicy, sparsity_type>;
template <typename T> typename ContainerPolicy = device_uvector_policy>
using device_coordinate_structure =
coordinate_structure<RowType, ColType, NZType, true, ContainerPolicy>;

/**
* Specialization for a coo matrix view which uses device memory
*/
template <typename ElementType, typename RowType, typename ColType, typename NZType>
using device_coo_matrix_view = coo_matrix_view<ElementType, RowType, ColType, NZType, true>;

template <typename ElementType,
typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = device_uvector_policy,
SparsityType sparsity_type = SparsityType::OWNING>
using device_coo_matrix =
coo_matrix<ElementType, RowType, ColType, NZType, true, ContainerPolicy, sparsity_type>;

/**
* Specialization for a sparsity-owning coo matrix which uses device memory
*/
Expand All @@ -62,21 +78,12 @@ using device_sparsity_preserving_coo_matrix = coo_matrix<ElementType,
ContainerPolicy,
SparsityType::PRESERVING>;

/**
* Specialization for a sparsity-owning coordinate structure which uses device memory
*/
template <typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = device_uvector_policy>
using device_coordinate_structure =
coordinate_structure<RowType, ColType, NZType, true, ContainerPolicy>;
template <typename T>
struct is_device_coo_matrix_view : std::false_type {};

/**
* Specialization for a sparsity-preserving coordinate structure view which uses device memory
*/
template <typename RowType, typename ColType, typename NZType>
using device_coordinate_structure_view = coordinate_structure_view<RowType, ColType, NZType, true>;
template <typename ElementType, typename RowType, typename ColType, typename NZType>
struct is_device_coo_matrix_view<device_coo_matrix_view<ElementType, RowType, ColType, NZType>>
: std::true_type {};

template <typename T>
struct is_device_coo_matrix : std::false_type {};
Expand All @@ -100,8 +107,9 @@ constexpr bool is_device_coo_sparsity_owning_v =
is_device_coo_matrix<T>::value and T::get_sparsity_type() == OWNING;

template <typename T>
constexpr bool is_device_coo_sparsity_preserving_v =
is_device_coo_matrix<T>::value and T::get_sparsity_type() == PRESERVING;
constexpr bool is_device_coo_sparsity_preserving_v = std::disjunction_v<
is_device_coo_matrix_view<T>,
std::bool_constant<is_device_coo_matrix<T>::value and T::get_sparsity_type() == PRESERVING>>;

/**
* Create a sparsity-owning sparse matrix in the coordinate format. sparsity-owning means that
Expand Down
96 changes: 49 additions & 47 deletions cpp/include/raft/core/device_csr_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@

namespace raft {

/**
* Specialization for a sparsity-preserving compressed structure view which uses device memory
*/
template <typename IndptrType, typename IndicesType, typename NZType>
using device_compressed_structure_view =
compressed_structure_view<IndptrType, IndicesType, NZType, true>;

/**
* Specialization for a sparsity-owning compressed structure 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 csr matrix view 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>;

template <typename ElementType,
typename IndptrType,
typename IndicesType,
Expand All @@ -45,6 +68,29 @@ template <typename ElementType,
using device_sparsity_owning_csr_matrix =
csr_matrix<ElementType, IndptrType, IndicesType, NZType, true, ContainerPolicy>;

/**
* Specialization for a sparsity-preserving 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>;

template <typename T>
struct is_device_csr_matrix_view : std::false_type {};

template <typename ElementType, typename IndptrType, typename IndicesType, typename NZType>
struct is_device_csr_matrix_view<
device_csr_matrix_view<ElementType, IndptrType, IndicesType, NZType>> : std::true_type {};

template <typename T>
struct is_device_csr_matrix : std::false_type {};

Expand All @@ -67,53 +113,9 @@ 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;

/**
* Specialization for a csr matrix view 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 sparsity-preserving 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 csr matrix view 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 sparsity-owning compressed structure 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-preserving compressed structure view which uses device memory
*/
template <typename IndptrType, typename IndicesType, typename NZType>
using device_compressed_structure_view =
compressed_structure_view<IndptrType, IndicesType, NZType, true>;
constexpr bool is_device_csr_sparsity_preserving_v = std::disjunction_v<
is_device_csr_matrix_view<T>,
std::bool_constant<is_device_csr_matrix<T>::value and T::get_sparsity_type() == PRESERVING>>;

/**
* Create a sparsity-owning sparse matrix in the compressed-sparse row format. sparsity-owning
Expand Down
52 changes: 30 additions & 22 deletions cpp/include/raft/core/host_coo_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,37 @@

namespace raft {

template <typename ElementType,
typename RowType,
/**
* Specialization for a sparsity-preserving coordinate structure view which uses host memory
*/
template <typename RowType, typename ColType, typename NZType>
using host_coordinate_structure_view = coordinate_structure_view<RowType, ColType, NZType, false>;

/**
* Specialization for a sparsity-owning coordinate structure which uses host memory
*/
template <typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = host_vector_policy,
SparsityType sparsity_type = SparsityType::OWNING>
using host_coo_matrix =
coo_matrix<ElementType, RowType, ColType, NZType, false, ContainerPolicy, sparsity_type>;
template <typename T> typename ContainerPolicy = host_vector_policy>
using host_coordinate_structure =
coordinate_structure<RowType, ColType, NZType, false, ContainerPolicy>;

/**
* Specialization for a coo matrix view which uses host memory
*/
template <typename ElementType, typename RowType, typename ColType, typename NZType>
using host_coo_matrix_view = coo_matrix_view<ElementType, RowType, ColType, NZType, false>;

template <typename ElementType,
typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = host_vector_policy,
SparsityType sparsity_type = SparsityType::OWNING>
using host_coo_matrix =
coo_matrix<ElementType, RowType, ColType, NZType, false, ContainerPolicy, sparsity_type>;

/**
* Specialization for a sparsity-owning coo matrix which uses host memory
*/
Expand All @@ -61,21 +77,12 @@ using host_sparsity_preserving_coo_matrix = coo_matrix<ElementType,
ContainerPolicy,
SparsityType::PRESERVING>;

/**
* Specialization for a sparsity-owning coordinate structure which uses host memory
*/
template <typename RowType,
typename ColType,
typename NZType,
template <typename T> typename ContainerPolicy = host_vector_policy>
using host_coordinate_structure =
coordinate_structure<RowType, ColType, NZType, false, ContainerPolicy>;
template <typename T>
struct is_host_coo_matrix_view : std::false_type {};

/**
* Specialization for a sparsity-preserving coordinate structure view which uses host memory
*/
template <typename RowType, typename ColType, typename NZType>
using host_coordinate_structure_view = coordinate_structure_view<RowType, ColType, NZType, false>;
template <typename ElementType, typename RowType, typename ColType, typename NZType>
struct is_host_coo_matrix_view<host_coo_matrix_view<ElementType, RowType, ColType, NZType>>
: std::true_type {};

template <typename T>
struct is_host_coo_matrix : std::false_type {};
Expand All @@ -99,8 +106,9 @@ constexpr bool is_host_coo_sparsity_owning_v =
is_host_coo_matrix<T>::value and T::get_sparsity_type() == OWNING;

template <typename T>
constexpr bool is_host_coo_sparsity_preserving_v =
is_host_coo_matrix<T>::value and T::get_sparsity_type() == PRESERVING;
constexpr bool is_host_coo_sparsity_preserving_v = std::disjunction_v<
is_host_coo_matrix_view<T>,
std::bool_constant<is_host_coo_matrix<T>::value and T::get_sparsity_type() == PRESERVING>>;

/**
* Create a sparsity-owning sparse matrix in the coordinate format. sparsity-owning means that
Expand Down
Loading