33#ifndef GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
34#define GKO_PUBLIC_CORE_MATRIX_SPARSITY_CSR_HPP_
40#include <ginkgo/core/base/array.hpp>
41#include <ginkgo/core/base/lin_op.hpp>
42#include <ginkgo/core/base/polymorphic_object.hpp>
49template <
typename ValueType,
typename IndexType>
53template <
typename ValueType>
57template <
typename ValueType,
typename IndexType>
79template <
typename ValueType = default_precision,
typename IndexType =
int32>
81 :
public EnableLinOp<SparsityCsr<ValueType, IndexType>>,
90 friend class Csr<ValueType, IndexType>;
91 friend class Dense<ValueType>;
92 friend class Fbcsr<ValueType, IndexType>;
103 using value_type = ValueType;
104 using index_type = IndexType;
150 bool is_sorted_by_column_index()
const;
234 std::shared_ptr<const Executor> exec,
const dim<2>& size,
235 gko::detail::const_array_view<IndexType>&& col_idxs,
236 gko::detail::const_array_view<IndexType>&&
row_ptrs,
241 return std::unique_ptr<const SparsityCsr>(
new SparsityCsr{
242 exec, size, gko::detail::array_const_cast(std::move(col_idxs)),
243 gko::detail::array_const_cast(std::move(
row_ptrs)), value});
284 row_ptrs_(exec, size[0] + 1),
309 template <
typename ColIdxsArray,
typename RowPtrsArray>
310 SparsityCsr(std::shared_ptr<const Executor> exec,
const dim<2>& size,
316 value_{exec, {value}}
318 GKO_ASSERT_EQ(this->get_size()[0] + 1, row_ptrs_.get_num_elems());
328 SparsityCsr(std::shared_ptr<const Executor> exec,
329 std::shared_ptr<const LinOp> matrix)
330 : EnableLinOp<SparsityCsr>(exec, matrix->get_size())
333 this->copy_from(
tmp_);
336 void apply_impl(
const LinOp* b, LinOp* x)
const override;
338 void apply_impl(
const LinOp* alpha,
const LinOp* b,
const LinOp* beta,
339 LinOp* x)
const override;
342 array<index_type> col_idxs_;
343 array<index_type> row_ptrs_;
344 array<value_type> value_;
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition polymorphic_object.hpp:499
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:776
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition lin_op.hpp:634
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition lin_op.hpp:689
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition array.hpp:646
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition array.hpp:655
void fill(const value_type value)
Fill the array with the given value.
size_type get_num_elems() const noexcept
Returns the number of elements in the array.
Definition array.hpp:637
This type is a device-side equivalent to matrix_data.
Definition device_matrix_data.hpp:63
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:146
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
Fixed-block compressed sparse row storage matrix format.
Definition fbcsr.hpp:138
SparsityCsr is a matrix format which stores only the sparsity pattern of a sparse matrix by compressi...
Definition sparsity_csr.hpp:87
std::unique_ptr< SparsityCsr > to_adjacency_matrix() const
Transforms the sparsity matrix to an adjacency matrix.
SparsityCsr & operator=(SparsityCsr &&)
Move-assigns a SparsityCsr matrix.
SparsityCsr & operator=(const SparsityCsr &)
Copy-assigns a SparsityCsr matrix.
index_type * get_col_idxs() noexcept
Returns the column indices of the matrix.
Definition sparsity_csr.hpp:157
SparsityCsr(SparsityCsr &&)
Move-constructs a SparsityCsr matrix.
void read(const device_mat_data &data) override
Reads a matrix from a device_matrix_data structure.
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
SparsityCsr(const SparsityCsr &)
Copy-constructs a SparsityCsr matrix.
const index_type * get_const_col_idxs() const noexcept
Returns the column indices of the matrix.
Definition sparsity_csr.hpp:166
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
const index_type * get_const_row_ptrs() const noexcept
Returns the row pointers of the matrix.
Definition sparsity_csr.hpp:185
void read(device_mat_data &&data) override
Reads a matrix from a device_matrix_data structure.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
size_type get_num_nonzeros() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition sparsity_csr.hpp:215
const value_type * get_const_value() const noexcept
Returns the value stored in the matrix.
Definition sparsity_csr.hpp:204
index_type * get_row_ptrs() noexcept
Returns the row pointers of the matrix.
Definition sparsity_csr.hpp:176
void sort_by_column_index()
Sorts each row by column index.
static std::unique_ptr< const SparsityCsr > create_const(std::shared_ptr< const Executor > exec, const dim< 2 > &size, gko::detail::const_array_view< IndexType > &&col_idxs, gko::detail::const_array_view< IndexType > &&row_ptrs, ValueType value=one< ValueType >())
Creates a constant (immutable) SparsityCsr matrix from constant arrays.
Definition sparsity_csr.hpp:233
value_type * get_value() noexcept
Returns the value stored in the matrix.
Definition sparsity_csr.hpp:195
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:155