Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
csr.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
7 
8 
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/index_set.hpp>
11 #include <ginkgo/core/base/lin_op.hpp>
12 #include <ginkgo/core/base/math.hpp>
13 #include <ginkgo/core/matrix/device_views.hpp>
14 #include <ginkgo/core/matrix/permutation.hpp>
15 #include <ginkgo/core/matrix/scaled_permutation.hpp>
16 
17 
18 namespace gko {
19 namespace matrix {
20 
21 
22 template <typename ValueType>
23 class MultiVector;
24 
25 template <typename ValueType>
26 class Dense;
27 
28 template <typename ValueType>
29 class Diagonal;
30 
31 template <typename ValueType, typename IndexType>
32 class Coo;
33 
34 template <typename ValueType, typename IndexType>
35 class Ell;
36 
37 template <typename ValueType, typename IndexType>
38 class Hybrid;
39 
40 template <typename ValueType, typename IndexType>
41 class Sellp;
42 
43 template <typename ValueType, typename IndexType>
45 
46 template <typename ValueType, typename IndexType>
47 class Csr;
48 
49 template <typename ValueType, typename IndexType>
50 class Fbcsr;
51 
52 template <typename ValueType, typename IndexType>
53 class CsrBuilder;
54 
55 
56 namespace csr {
57 
58 
62 enum class spmv_strategy {
68  automatic,
75  load_balance,
82  merge_path,
87  classical,
97  sparselib
98 };
99 
100 
101 } // namespace csr
102 
103 
142 template <typename ValueType = default_precision, typename IndexType = int32>
143 class Csr : public LinOp,
144  public EnableCloneable<Csr<ValueType, IndexType>>,
145  public ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>,
146 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
147  public ConvertibleTo<Csr<next_precision<ValueType, 2>, IndexType>>,
148 #endif
149 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
150  public ConvertibleTo<Csr<next_precision<ValueType, 3>, IndexType>>,
151 #endif
152  public ConvertibleTo<Dense<ValueType>>,
153  public ConvertibleTo<Coo<ValueType, IndexType>>,
154  public ConvertibleTo<Ell<ValueType, IndexType>>,
155  public ConvertibleTo<Fbcsr<ValueType, IndexType>>,
156  public ConvertibleTo<Hybrid<ValueType, IndexType>>,
157  public ConvertibleTo<Sellp<ValueType, IndexType>>,
158  public ConvertibleTo<SparsityCsr<ValueType, IndexType>>,
159  public DiagonalExtractable<ValueType>,
160  public ReadableFromMatrixData<ValueType, IndexType>,
161  public WritableToMatrixData<ValueType, IndexType>,
162  public Transposable,
163  public Permutable<IndexType>,
165  remove_complex<Csr<ValueType, IndexType>>>,
166  public ScaledIdentityAddable {
167  friend class EnableCloneable<Csr>;
168  friend class Coo<ValueType, IndexType>;
169  friend class Dense<ValueType>;
170  friend class Diagonal<ValueType>;
171  friend class Ell<ValueType, IndexType>;
172  friend class Hybrid<ValueType, IndexType>;
173  friend class Sellp<ValueType, IndexType>;
174  friend class SparsityCsr<ValueType, IndexType>;
175  friend class Fbcsr<ValueType, IndexType>;
176  friend class CsrBuilder<ValueType, IndexType>;
177  friend class Csr<to_complex<ValueType>, IndexType>;
178  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
179 
180 public:
183  using ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>::convert_to;
184  using ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>::move_to;
185  using ConvertibleTo<Dense<ValueType>>::convert_to;
186  using ConvertibleTo<Dense<ValueType>>::move_to;
187  using ConvertibleTo<Coo<ValueType, IndexType>>::convert_to;
189  using ConvertibleTo<Ell<ValueType, IndexType>>::convert_to;
200 
201  using value_type = ValueType;
202  using index_type = IndexType;
203  using transposed_type = Csr<ValueType, IndexType>;
204  using mat_data = matrix_data<ValueType, IndexType>;
205  using device_mat_data = device_matrix_data<ValueType, IndexType>;
206  using absolute_type = remove_complex<Csr>;
207  using device_view = view::csr<value_type, index_type>;
208  using const_device_view = view::csr<const value_type, const index_type>;
209 
210  class GKO_DEPRECATED(
211  "please use enum gko::matrix::csr::spmv_strategy::<strategy>")
212  strategy_type {
213  public:
214  virtual ~strategy_type() = default;
215 
216  // return the corresponding enum in incoming release
217  virtual csr::spmv_strategy get_enum() const = 0;
218  };
219 
220  class GKO_DEPRECATED(
221  "please use enum gko::matrix::csr::spmv_strategy::classical") classical
222  : public strategy_type {
223  public:
224  csr::spmv_strategy get_enum() const override
225  {
226  return csr::spmv_strategy::classical;
227  }
228  };
229 
230  class GKO_DEPRECATED(
231  "please use enum gko::matrix::csr::spmv_strategy::merge_path")
232  merge_path : public strategy_type {
233  public:
234  csr::spmv_strategy get_enum() const override
235  {
236  return csr::spmv_strategy::merge_path;
237  }
238  };
239 
240  class GKO_DEPRECATED(
241  "please use enum gko::matrix::csr::spmv_strategy::sparselib") cusparse
242  : public strategy_type {
243  public:
244  csr::spmv_strategy get_enum() const override
245  {
246  return csr::spmv_strategy::sparselib;
247  }
248  };
249 
250  class GKO_DEPRECATED(
251  "please use enum gko::matrix::csr::spmv_strategy::sparselib") sparselib
252  : public strategy_type {
253  public:
254  csr::spmv_strategy get_enum() const override
255  {
256  return csr::spmv_strategy::sparselib;
257  }
258  };
259 
260  class GKO_DEPRECATED(
261  "please use enum gko::matrix::csr::spmv_strategy::load_balance")
262  load_balance : public strategy_type {
263  public:
264  load_balance(std::shared_ptr<const Executor>) {}
265 
266  csr::spmv_strategy get_enum() const override
267  {
268  return csr::spmv_strategy::load_balance;
269  }
270  };
271 
272  class GKO_DEPRECATED(
273  "please use enum gko::matrix::csr::spmv_strategy::automatic")
274  automatical : public strategy_type {
275  public:
276  automatical(std::shared_ptr<const Executor>) {}
277 
278  csr::spmv_strategy get_enum() const override
279  {
280  return csr::spmv_strategy::automatic;
281  }
282  };
283 
284 
285  friend class Csr<previous_precision<ValueType>, IndexType>;
286 
287  void convert_to(
288  Csr<next_precision<ValueType>, IndexType>* result) const override;
289 
290  void move_to(Csr<next_precision<ValueType>, IndexType>* result) override;
291 
292 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
293  friend class Csr<previous_precision<ValueType, 2>, IndexType>;
294  using ConvertibleTo<
295  Csr<next_precision<ValueType, 2>, IndexType>>::convert_to;
296  using ConvertibleTo<Csr<next_precision<ValueType, 2>, IndexType>>::move_to;
297 
298  void convert_to(
299  Csr<next_precision<ValueType, 2>, IndexType>* result) const override;
300 
301  void move_to(Csr<next_precision<ValueType, 2>, IndexType>* result) override;
302 #endif
303 
304 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
305  friend class Csr<previous_precision<ValueType, 3>, IndexType>;
306  using ConvertibleTo<
307  Csr<next_precision<ValueType, 3>, IndexType>>::convert_to;
308  using ConvertibleTo<Csr<next_precision<ValueType, 3>, IndexType>>::move_to;
309 
310  void convert_to(
311  Csr<next_precision<ValueType, 3>, IndexType>* result) const override;
312 
313  void move_to(Csr<next_precision<ValueType, 3>, IndexType>* result) override;
314 #endif
315 
316  void convert_to(Dense<ValueType>* other) const override;
317 
318  void move_to(Dense<ValueType>* other) override;
319 
320  void convert_to(Coo<ValueType, IndexType>* result) const override;
321 
322  void move_to(Coo<ValueType, IndexType>* result) override;
323 
324  void convert_to(Ell<ValueType, IndexType>* result) const override;
325 
326  void move_to(Ell<ValueType, IndexType>* result) override;
327 
328  void convert_to(Fbcsr<ValueType, IndexType>* result) const override;
329 
330  void move_to(Fbcsr<ValueType, IndexType>* result) override;
331 
332  void convert_to(Hybrid<ValueType, IndexType>* result) const override;
333 
334  void move_to(Hybrid<ValueType, IndexType>* result) override;
335 
336  void convert_to(Sellp<ValueType, IndexType>* result) const override;
337 
338  void move_to(Sellp<ValueType, IndexType>* result) override;
339 
340  void convert_to(SparsityCsr<ValueType, IndexType>* result) const override;
341 
342  void move_to(SparsityCsr<ValueType, IndexType>* result) override;
343 
344  void read(const mat_data& data) override;
345 
346  void read(const device_mat_data& data) override;
347 
348  void read(device_mat_data&& data) override;
349 
350  void write(mat_data& data) const override;
351 
352  void write(device_mat_data& data) const override;
353 
354  std::unique_ptr<LinOp> transpose() const override;
355 
356  std::unique_ptr<LinOp> conj_transpose() const override;
357 
364 
371 
378  friend class Csr;
379 
380  public:
381  explicit multiply_reuse_info();
382 
384 
385  multiply_reuse_info(const multiply_reuse_info&) = delete;
386 
388 
389  multiply_reuse_info& operator=(const multiply_reuse_info&) = delete;
390 
391  multiply_reuse_info& operator=(multiply_reuse_info&&) noexcept;
392 
399  ptr_param<Csr> out) const;
400 
401  private:
402  struct lookup_data;
403 
404  explicit multiply_reuse_info(std::unique_ptr<lookup_data> data);
405 
406  std::unique_ptr<lookup_data> internal;
407  };
408 
419  std::unique_ptr<Csr> multiply(ptr_param<const Csr> other) const;
420 
437  std::pair<std::unique_ptr<Csr>, multiply_reuse_info> multiply_reuse(
438  ptr_param<const Csr> other) const;
439 
446  friend class Csr;
447 
448  public:
449  explicit multiply_add_reuse_info();
450 
452 
454 
456 
458  delete;
459 
460  multiply_add_reuse_info& operator=(multiply_add_reuse_info&&) noexcept;
461 
470  ptr_param<const MultiVector<value_type>> scale_mult,
471  ptr_param<const Csr> mtx_mult,
473  ptr_param<const Csr> mtx_add,
474  ptr_param<Csr> out) const;
475 
476  private:
477  struct lookup_data;
478 
479  explicit multiply_add_reuse_info(std::unique_ptr<lookup_data> data);
480 
481  std::unique_ptr<lookup_data> internal;
482  };
483 
499  std::unique_ptr<Csr> multiply_add(
500  ptr_param<const MultiVector<value_type>> scale_mult,
501  ptr_param<const Csr> mtx_mult,
503  ptr_param<const Csr> mtx_add) const;
504 
526  std::pair<std::unique_ptr<Csr>, multiply_add_reuse_info> multiply_add_reuse(
527  ptr_param<const MultiVector<value_type>> scale_mult,
528  ptr_param<const Csr> mtx_mult,
530  ptr_param<const Csr> mtx_add) const;
531 
538  friend class Csr;
539 
540  public:
541  explicit scale_add_reuse_info();
542 
544 
546 
548 
549  scale_add_reuse_info& operator=(const scale_add_reuse_info&) = delete;
550 
551  scale_add_reuse_info& operator=(scale_add_reuse_info&&) noexcept;
552 
561  ptr_param<const MultiVector<value_type>> scale2,
562  ptr_param<const Csr> mtx2, ptr_param<Csr> out) const;
563 
564  private:
565  struct lookup_data;
566 
567  explicit scale_add_reuse_info(std::unique_ptr<lookup_data> data);
568 
569  std::unique_ptr<lookup_data> internal;
570  };
571 
586  std::unique_ptr<Csr> scale_add(
587  ptr_param<const MultiVector<value_type>> scale_this,
588  ptr_param<const MultiVector<value_type>> scale_other,
589  ptr_param<const Csr> mtx_other) const;
590 
612  std::pair<std::unique_ptr<Csr>, scale_add_reuse_info> add_scale_reuse(
613  ptr_param<const MultiVector<value_type>> scale_this,
614  ptr_param<const MultiVector<value_type>> scale_other,
615  ptr_param<const Csr> mtx_other) const;
616 
623  explicit permuting_reuse_info();
624 
626  explicit permuting_reuse_info(
627  std::unique_ptr<Permutation<index_type>> value_permutation);
628 
637  ptr_param<Csr> output) const;
638 
639  std::unique_ptr<Permutation<IndexType>> value_permutation;
640  };
641 
654  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> transpose_reuse()
655  const;
656 
667  std::unique_ptr<Csr> permute(
668  ptr_param<const Permutation<index_type>> permutation,
670 
685  std::unique_ptr<Csr> permute(
686  ptr_param<const Permutation<index_type>> row_permutation,
687  ptr_param<const Permutation<index_type>> column_permutation,
688  bool invert = false) const;
689 
706  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> permute_reuse(
707  ptr_param<const Permutation<index_type>> permutation,
709 
729  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> permute_reuse(
730  ptr_param<const Permutation<index_type>> row_permutation,
731  ptr_param<const Permutation<index_type>> column_permutation,
732  bool invert = false) const;
733 
743  std::unique_ptr<Csr> scale_permute(
746 
759  std::unique_ptr<Csr> scale_permute(
761  row_permutation,
763  column_permutation,
764  bool invert = false) const;
765 
766  std::unique_ptr<LinOp> permute(
767  const array<IndexType>* permutation_indices) const override;
768 
769  std::unique_ptr<LinOp> inverse_permute(
770  const array<IndexType>* inverse_permutation_indices) const override;
771 
772  std::unique_ptr<LinOp> row_permute(
773  const array<IndexType>* permutation_indices) const override;
774 
775  std::unique_ptr<LinOp> column_permute(
776  const array<IndexType>* permutation_indices) const override;
777 
778  std::unique_ptr<LinOp> inverse_row_permute(
779  const array<IndexType>* inverse_permutation_indices) const override;
780 
781  std::unique_ptr<LinOp> inverse_column_permute(
782  const array<IndexType>* inverse_permutation_indices) const override;
783 
784  std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
785 
786  std::unique_ptr<absolute_type> compute_absolute() const override;
787 
788  void compute_absolute_inplace() override;
789 
793  void sort_by_column_index();
794 
795  /*
796  * Tests if all row entry pairs (value, col_idx) are sorted by column index
797  *
798  * @returns True if all row entry pairs (value, col_idx) are sorted by
799  * column index
800  */
801  bool is_sorted_by_column_index() const;
802 
808  value_type* get_values() noexcept { return values_.get_data(); }
809 
817  const value_type* get_const_values() const noexcept
818  {
819  return values_.get_const_data();
820  }
821 
826  std::unique_ptr<MultiVector<ValueType>> create_value_view();
827 
832  std::unique_ptr<const MultiVector<ValueType>> create_const_value_view()
833  const;
834 
840  index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
841 
849  const index_type* get_const_col_idxs() const noexcept
850  {
851  return col_idxs_.get_const_data();
852  }
853 
859  index_type* get_row_ptrs() noexcept { return row_ptrs_.get_data(); }
860 
868  const index_type* get_const_row_ptrs() const noexcept
869  {
870  return row_ptrs_.get_const_data();
871  }
872 
878  index_type* get_srow() noexcept { return srow_.get_data(); }
879 
887  const index_type* get_const_srow() const noexcept
888  {
889  return srow_.get_const_data();
890  }
891 
898  {
899  return srow_.get_size();
900  }
901 
908  {
909  return values_.get_size();
910  }
911 
917  csr::spmv_strategy get_strategy() const noexcept;
918 
926  csr::spmv_strategy get_actual_strategy() const noexcept;
927 
933  void set_strategy(csr::spmv_strategy strategy)
934  {
935  strategy_ = strategy;
936  this->make_srow();
937  }
938 
946  {
947  auto exec = this->get_executor();
948  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
949  this->scale_impl(make_temporary_clone(exec, alpha).get());
950  }
951 
959  {
960  auto exec = this->get_executor();
961  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
962  this->inv_scale_impl(make_temporary_clone(exec, alpha).get());
963  }
964 
965  void validate_data() const override;
966 
975  static std::unique_ptr<Csr> create(std::shared_ptr<const Executor> exec,
976  csr::spmv_strategy strategy);
977 
989  static std::unique_ptr<Csr> create(
990  std::shared_ptr<const Executor> exec, const dim<2>& size = {},
991  size_type num_nonzeros = {},
992  csr::spmv_strategy strategy = csr::spmv_strategy::automatic);
993 
1014  static std::unique_ptr<Csr> create(
1015  std::shared_ptr<const Executor> exec, const dim<2>& size,
1016  array<value_type> values, array<index_type> col_idxs,
1017  array<index_type> row_ptrs,
1018  csr::spmv_strategy strategy = csr::spmv_strategy::automatic);
1019 
1024  template <typename InputValueType, typename InputColumnIndexType,
1025  typename InputRowPtrType>
1026  GKO_DEPRECATED(
1027  "explicitly construct the gko::array argument instead of passing "
1028  "initializer lists")
1029  static std::unique_ptr<Csr> create(
1030  std::shared_ptr<const Executor> exec, const dim<2>& size,
1031  std::initializer_list<InputValueType> values,
1032  std::initializer_list<InputColumnIndexType> col_idxs,
1033  std::initializer_list<InputRowPtrType> row_ptrs)
1034  {
1035  return create(exec, size, array<value_type>{exec, std::move(values)},
1036  array<index_type>{exec, std::move(col_idxs)},
1037  array<index_type>{exec, std::move(row_ptrs)});
1038  }
1039 
1056  static std::unique_ptr<const Csr> create_const(
1057  std::shared_ptr<const Executor> exec, const dim<2>& size,
1058  gko::detail::const_array_view<ValueType>&& values,
1059  gko::detail::const_array_view<IndexType>&& col_idxs,
1060  gko::detail::const_array_view<IndexType>&& row_ptrs,
1061  csr::spmv_strategy strategy = csr::spmv_strategy::automatic);
1062 
1063  GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
1064 
1069  [[deprecated("please use enum version")]] static std::unique_ptr<Csr>
1070  create(std::shared_ptr<const Executor> exec,
1071  std::shared_ptr<strategy_type> strategy);
1072 
1078  [[deprecated("please use enum version")]] static std::unique_ptr<Csr>
1079  create(std::shared_ptr<const Executor> exec, const dim<2>& size,
1080  array<value_type> values, array<index_type> col_idxs,
1081  array<index_type> row_ptrs, std::shared_ptr<strategy_type> strategy);
1082 
1089  [[deprecated("please use enum version")]] static std::unique_ptr<const Csr>
1090  create_const(std::shared_ptr<const Executor> exec, const dim<2>& size,
1091  gko::detail::const_array_view<ValueType>&& values,
1092  gko::detail::const_array_view<IndexType>&& col_idxs,
1093  gko::detail::const_array_view<IndexType>&& row_ptrs,
1094  std::shared_ptr<strategy_type> strategy);
1095 
1096  GKO_END_DISABLE_DEPRECATION_WARNINGS
1097 
1110  std::unique_ptr<Csr<ValueType, IndexType>> create_submatrix(
1111  const index_set<IndexType>& row_index_set,
1112  const index_set<IndexType>& column_index_set) const;
1113 
1125  std::unique_ptr<Csr<ValueType, IndexType>> create_submatrix(
1126  const span& row_span, const span& column_span) const;
1127 
1131  Csr& operator=(const Csr&);
1132 
1138  Csr& operator=(Csr&&);
1139 
1143  Csr(const Csr&);
1144 
1150  Csr(Csr&&);
1151 
1152 protected:
1153  Csr(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
1154  size_type num_nonzeros = {},
1155  csr::spmv_strategy strategy = csr::spmv_strategy::automatic);
1156 
1157  Csr(std::shared_ptr<const Executor> exec, const dim<2>& size,
1158  array<value_type> values, array<index_type> col_idxs,
1159  array<index_type> row_ptrs,
1160  csr::spmv_strategy strategy = csr::spmv_strategy::automatic);
1161 
1162  void apply_impl(const AbstractMultiVector* b,
1163  AbstractMultiVector* x) const override;
1164 
1165  void apply_impl(const AbstractMultiVector* alpha,
1166  const AbstractMultiVector* b,
1167  const AbstractMultiVector* beta,
1168  AbstractMultiVector* x) const override;
1169 
1173  void make_srow();
1174 
1181  void make_srow(index_type max_nnz_per_row);
1182 
1189  virtual void scale_impl(const AbstractMultiVector* alpha);
1190 
1197  virtual void inv_scale_impl(const AbstractMultiVector* alpha);
1198 
1199 private:
1200  csr::spmv_strategy strategy_;
1201  array<value_type> values_;
1202  array<index_type> col_idxs_;
1203  array<index_type> row_ptrs_;
1204  array<index_type> srow_;
1205  index_type max_nnz_per_row_;
1206 
1207  void add_scaled_identity_impl(const AbstractMultiVector* a,
1208  const AbstractMultiVector* b) override;
1209 };
1210 
1211 
1212 } // namespace matrix
1213 } // namespace gko
1214 
1215 
1216 #endif // GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
gko::matrix::Csr::inv_scale
void inv_scale(ptr_param< const AbstractMultiVector > alpha)
Scales the matrix with the inverse of a scalar.
Definition: csr.hpp:958
gko::matrix::Csr::automatical
Definition: csr.hpp:272
gko::matrix::Csr::get_const_srow
const index_type * get_const_srow() const noexcept
Returns the starting rows.
Definition: csr.hpp:887
gko::matrix::Csr::operator=
Csr & operator=(const Csr &)
Copy-assigns a Csr matrix.
gko::matrix::Csr::get_col_idxs
index_type * get_col_idxs() noexcept
Returns the column indexes of the matrix.
Definition: csr.hpp:840
gko::matrix::Fbcsr
Fixed-block compressed sparse row storage matrix format.
Definition: csr.hpp:50
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition: matrix.hpp:30
gko::matrix::Csr::get_const_row_ptrs
const index_type * get_const_row_ptrs() const noexcept
Returns the row pointers of the matrix.
Definition: csr.hpp:868
gko::matrix::Csr::validate_data
void validate_data() const override
Throws gko::InvalidData exception if we found the data inside the object does not fulfill certain pro...
gko::matrix::Csr::multiply
std::unique_ptr< Csr > multiply(ptr_param< const Csr > other) const
Computes the sparse matrix product this * other on the executor of this matrix.
gko::LinOp
Definition: lin_op.hpp:163
gko::matrix::Csr::permute_reuse
std::pair< std::unique_ptr< Csr >, permuting_reuse_info > permute_reuse(ptr_param< const Permutation< index_type >> permutation, permute_mode mode=permute_mode::symmetric) const
Computes the operations necessary to propagate changed values from a matrix A to a permuted matrix.
gko::matrix::Dense
Dense is a matrix format which explicitly stores all values of the matrix.
Definition: lin_op.hpp:35
gko::matrix::Csr::multiply_add_reuse_info
Class describing the internal lookup structures created by multiply_add_reuse to recompute a sparse m...
Definition: csr.hpp:445
gko::matrix::CsrBuilder
Definition: csr.hpp:53
gko::matrix::Csr::inverse_row_permute
std::unique_ptr< LinOp > inverse_row_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the row permutation of the inverse permuted object.
gko::matrix::Csr::sparselib
Definition: csr.hpp:250
gko::DiagonalExtractable
The diagonal of a LinOp implementing this interface can be extracted.
Definition: lin_op.hpp:922
gko::matrix::SparsityCsr
SparsityCsr is a matrix format which stores only the sparsity pattern of a sparse matrix by compressi...
Definition: csr.hpp:44
gko::matrix::Csr::load_balance
Definition: csr.hpp:260
gko::matrix::Csr::multiply_reuse
std::pair< std::unique_ptr< Csr >, multiply_reuse_info > multiply_reuse(ptr_param< const Csr > other) const
Computes the sparse matrix product this * other on the executor of this matrix, and necessary data fo...
gko::log_propagation_mode::automatic
Events get reported to loggers attached to the triggering object and propagating loggers (Logger::nee...
gko::matrix::Csr::get_const_device_view
const_device_view get_const_device_view() const
Returns a non-owning const device view of this matrix.
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:596
gko::matrix::Csr::scale_add_reuse_info::update_values
void update_values(ptr_param< const MultiVector< value_type >> scale1, ptr_param< const Csr > mtx1, ptr_param< const MultiVector< value_type >> scale2, ptr_param< const Csr > mtx2, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix sum out = scale1 * mtx1 + scale2 * mtx2 when only the values of m...
gko::matrix::Csr::column_permute
std::unique_ptr< LinOp > column_permute(const array< IndexType > *permutation_indices) const override
Returns a LinOp representing the column permutation of the Permutable object.
gko::matrix::ScaledPermutation
ScaledPermutation is a matrix combining a permutation with scaling factors.
Definition: scaled_permutation.hpp:35
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::matrix::Csr::get_srow
index_type * get_srow() noexcept
Returns the starting rows.
Definition: csr.hpp:878
gko::matrix::Csr::transpose_reuse
std::pair< std::unique_ptr< Csr >, permuting_reuse_info > transpose_reuse() const
Computes the necessary data to update a transposed matrix from its original matrix.
gko::matrix::Permutation
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition: permutation.hpp:110
gko::matrix::Csr::multiply_add_reuse_info::update_values
void update_values(ptr_param< const Csr > mtx, ptr_param< const MultiVector< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const MultiVector< value_type >> scale_add, ptr_param< const Csr > mtx_add, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix product out = scale_mult * mtx * mtx_mult + scale_add * mtx_add w...
gko::matrix::Csr::add_scale_reuse
std::pair< std::unique_ptr< Csr >, scale_add_reuse_info > add_scale_reuse(ptr_param< const MultiVector< value_type >> scale_this, ptr_param< const MultiVector< value_type >> scale_other, ptr_param< const Csr > mtx_other) const
Computes the sparse matrix sum scale_this * this + scale_other * mtx_add on the executor of this matr...
gko::matrix::Csr::permuting_reuse_info::permuting_reuse_info
permuting_reuse_info()
Creates an empty reuse info.
gko::matrix::Csr::row_permute
std::unique_ptr< LinOp > row_permute(const array< IndexType > *permutation_indices) const override
Returns a LinOp representing the row permutation of the Permutable object.
gko::Permutable
Linear operators which support permutation should implement the Permutable interface.
Definition: lin_op.hpp:647
gko::matrix::Csr::scale
void scale(ptr_param< const AbstractMultiVector > alpha)
Scales the matrix with a scalar.
Definition: csr.hpp:945
gko::matrix::Csr::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::matrix::Csr::multiply_add_reuse
std::pair< std::unique_ptr< Csr >, multiply_add_reuse_info > multiply_add_reuse(ptr_param< const MultiVector< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const MultiVector< value_type >> scale_add, ptr_param< const Csr > mtx_add) const
Computes the sparse matrix product scale_mult * this * mtx_mult + scale_add * mtx_add on the executor...
gko::matrix::Csr::create
static std::unique_ptr< Csr > create(std::shared_ptr< const Executor > exec, csr::spmv_strategy strategy)
Creates an uninitialized CSR matrix of the specified size.
gko::matrix::Csr::extract_diagonal
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
Extracts the diagonal entries of the matrix into a vector.
gko::array< IndexType >
gko::matrix::Csr::cusparse
Definition: csr.hpp:240
gko::matrix::Csr::inverse_permute
std::unique_ptr< LinOp > inverse_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the symmetric inverse row and column permutation of the Permutable objec...
gko::matrix::Csr::get_row_ptrs
index_type * get_row_ptrs() noexcept
Returns the row pointers of the matrix.
Definition: csr.hpp:859
gko::span
A span is a lightweight structure used to create sub-ranges from other ranges.
Definition: range.hpp:45
gko::dim< 2 >
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
gko::matrix::Csr::merge_path
Definition: csr.hpp:230
gko::matrix::Csr::permute
std::unique_ptr< Csr > permute(ptr_param< const Permutation< index_type >> permutation, permute_mode mode=permute_mode::symmetric) const
Creates a permuted copy of this matrix with the given permutation .
gko::index_set
An index set class represents an ordered set of intervals.
Definition: index_set.hpp:55
gko::matrix::Csr::set_strategy
void set_strategy(csr::spmv_strategy strategy)
Set the strategy.
Definition: csr.hpp:933
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::array::get_data
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:686
gko::ReadableFromMatrixData
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition: lin_op.hpp:768
gko::matrix::Csr::get_actual_strategy
csr::spmv_strategy get_actual_strategy() const noexcept
Returns the actual strategy.
gko::matrix::Csr::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:823
gko::matrix::permute_mode::symmetric
The rows and columns will be permuted.
gko::matrix::Csr::create_value_view
std::unique_ptr< MultiVector< ValueType > > create_value_view()
Creates a MultiVector view of the value array of this matrix as a column vector of dimensions nnz x 1...
gko::matrix::Csr::get_const_values
const value_type * get_const_values() const noexcept
Returns the values of the matrix.
Definition: csr.hpp:817
gko::stop::mode
mode
The mode for the residual norm criterion.
Definition: residual_norm.hpp:37
gko::matrix::Csr::multiply_add
std::unique_ptr< Csr > multiply_add(ptr_param< const MultiVector< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const MultiVector< value_type >> scale_add, ptr_param< const Csr > mtx_add) const
Computes the sparse matrix product scale_mult * this * mtx_mult + scale_add * mtx_add on the executor...
gko::matrix::Csr::get_num_stored_elements
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: csr.hpp:907
gko::matrix::MultiVector< value_type >
gko::matrix::Csr::create_submatrix
std::unique_ptr< Csr< ValueType, IndexType > > create_submatrix(const index_set< IndexType > &row_index_set, const index_set< IndexType > &column_index_set) const
Creates a submatrix from this Csr matrix given row and column index_set objects.
gko::ScaledIdentityAddable
Adds the operation M <- a I + b M for matrix M, identity operator I and scalars a and b,...
Definition: lin_op.hpp:999
gko::matrix::Csr::permuting_reuse_info
A struct describing a transformation of the matrix that reorders the values of the matrix into the tr...
Definition: csr.hpp:621
gko::next_precision
typename detail::find_precision_impl< T, step >::type next_precision
Obtains the next move type of T in the singly-linked precision corresponding bfloat16/half.
Definition: math.hpp:465
gko::matrix::Csr::sort_by_column_index
void sort_by_column_index()
Sorts all (value, col_idx) pairs in each row by column index.
gko::previous_precision
typename detail::find_precision_impl< T, -step >::type previous_precision
Obtains the previous move type of T in the singly-linked precision corresponding bfloat16/half.
Definition: math.hpp:472
gko::matrix::Csr::classical
Definition: csr.hpp:220
gko::matrix::Csr::get_strategy
csr::spmv_strategy get_strategy() const noexcept
Returns the strategy.
gko::matrix::Csr::permuting_reuse_info::update_values
void update_values(ptr_param< const Csr > input, ptr_param< Csr > output) const
Propagates the values from an input matrix to the transformed matrix.
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:372
gko::matrix::Csr::get_device_view
device_view get_device_view()
Returns a non-owning device view of this matrix.
gko::matrix::Ell
ELL is a matrix format where stride with explicit zeros is used such that all rows have the same numb...
Definition: csr.hpp:35
gko::ConvertibleTo
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition: polymorphic_object.hpp:147
gko::matrix::Csr::compute_absolute
std::unique_ptr< absolute_type > compute_absolute() const override
Gets the AbsoluteLinOp.
gko::matrix::Csr::strategy_type
Definition: csr.hpp:210
gko::make_temporary_clone
detail::temporary_clone< detail::pointee< Ptr > > make_temporary_clone(std::shared_ptr< const Executor > exec, Ptr &&ptr)
Creates a temporary_clone.
Definition: temporary_clone.hpp:208
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:617
gko::matrix::Hybrid
HYBRID is a matrix format which splits the matrix into ELLPACK and COO format.
Definition: coo.hpp:32
gko::array::get_const_data
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:695
gko::matrix::Csr::write
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
gko::matrix::permute_mode
permute_mode
Specifies how a permutation will be applied to a matrix.
Definition: permutation.hpp:42
gko::matrix::Csr::multiply_reuse_info::update_values
void update_values(ptr_param< const Csr > mtx1, ptr_param< const Csr > mtx2, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix product out = mtx1 * mtx2 when only the values of mtx1 and mtx2 c...
gko::matrix::Sellp
SELL-P is a matrix format similar to ELL format.
Definition: csr.hpp:41
gko::matrix::Csr::get_const_col_idxs
const index_type * get_const_col_idxs() const noexcept
Returns the column indexes of the matrix.
Definition: csr.hpp:849
gko::EnableAbsoluteComputation
The EnableAbsoluteComputation mixin provides the default implementations of compute_absolute_linop an...
Definition: lin_op.hpp:975
gko::matrix::Csr::create_const
static std::unique_ptr< const Csr > create_const(std::shared_ptr< const Executor > exec, const dim< 2 > &size, gko::detail::const_array_view< ValueType > &&values, gko::detail::const_array_view< IndexType > &&col_idxs, gko::detail::const_array_view< IndexType > &&row_ptrs, csr::spmv_strategy strategy=csr::spmv_strategy::automatic)
Creates a constant (immutable) Csr matrix from a set of constant arrays.
gko::matrix::Csr::inverse_column_permute
std::unique_ptr< LinOp > inverse_column_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the row permutation of the inverse permuted object.
gko::matrix::Csr::Csr
Csr(const Csr &)
Copy-constructs a Csr matrix.
gko::PolymorphicObject::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:69
gko::array::get_size
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition: array.hpp:669
gko::matrix::Csr::create_const_value_view
std::unique_ptr< const MultiVector< ValueType > > create_const_value_view() const
Creates a const MultiVector view of the value array of this matrix as a column vector of dimensions n...
gko::remove_complex
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:263
gko::matrix::Csr::compute_absolute_inplace
void compute_absolute_inplace() override
Compute absolute inplace on each element.
gko::matrix::Csr::scale_permute
std::unique_ptr< Csr > scale_permute(ptr_param< const ScaledPermutation< value_type, index_type >> permutation, permute_mode=permute_mode::symmetric) const
Creates a scaled and permuted copy of this matrix.
gko::device_matrix_data
This type is a device-side equivalent to matrix_data.
Definition: device_matrix_data.hpp:36
gko::matrix::Csr::read
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
gko::matrix::view::csr
Non-owning view of a matrix::Csr to be used inside device kernels.
Definition: device_views.hpp:98
gko::matrix::Csr::scale_add
std::unique_ptr< Csr > scale_add(ptr_param< const MultiVector< value_type >> scale_this, ptr_param< const MultiVector< value_type >> scale_other, ptr_param< const Csr > mtx_other) const
Computes the sparse matrix sum scale_this * this + scale_other * mtx_add on the executor of this matr...
gko::matrix::Csr::get_values
value_type * get_values() noexcept
Returns the values of the matrix.
Definition: csr.hpp:808
gko::matrix::Csr::multiply_reuse_info
Class describing the internal lookup structures created by multiply_reuse(const Csr*) to recompute a ...
Definition: csr.hpp:377
gko::matrix::Csr::get_num_srow_elements
size_type get_num_srow_elements() const noexcept
Returns the number of the srow stored elements (involved warps)
Definition: csr.hpp:897
gko::matrix::Csr::scale_add_reuse_info
Class describing the internal lookup structures created by scale_add_reuse to recompute a sparse matr...
Definition: csr.hpp:537
gko::to_complex
typename detail::to_complex_s< T >::type to_complex
Obtain the type which adds the complex of complex/scalar type or the template parameter of class by a...
Definition: math.hpp:282
gko::matrix::Coo
COO stores a matrix in the coordinate matrix format.
Definition: coo.hpp:49