Ginkgo  Generated from pipelines/2897303314 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
hybrid.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MATRIX_HYBRID_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_HYBRID_HPP_
7 
8 
9 #include <algorithm>
10 
11 #include <ginkgo/core/base/array.hpp>
12 #include <ginkgo/core/base/lin_op.hpp>
13 #include <ginkgo/core/matrix/coo.hpp>
14 #include <ginkgo/core/matrix/csr.hpp>
15 #include <ginkgo/core/matrix/ell.hpp>
16 
17 
18 namespace gko {
19 namespace matrix {
20 
21 
22 template <typename ValueType>
23 class Dense;
24 
25 template <typename ValueType, typename IndexType>
26 class Csr;
27 
28 
40 template <typename ValueType = default_precision, typename IndexType = int32>
41 class Hybrid
42  : public LinOp,
43  public EnableCloneable<Hybrid<ValueType, IndexType>>,
44  public ConvertibleTo<Hybrid<next_precision<ValueType>, IndexType>>,
45 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
46  public ConvertibleTo<Hybrid<next_precision<ValueType, 2>, IndexType>>,
47 #endif
48 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
49  public ConvertibleTo<Hybrid<next_precision<ValueType, 3>, IndexType>>,
50 #endif
51  public ConvertibleTo<Dense<ValueType>>,
52  public ConvertibleTo<Csr<ValueType, IndexType>>,
53  public DiagonalExtractable<ValueType>,
54  public ReadableFromMatrixData<ValueType, IndexType>,
55  public WritableToMatrixData<ValueType, IndexType>,
56  public EnableAbsoluteComputation<
57  remove_complex<Hybrid<ValueType, IndexType>>> {
58  friend class EnableCloneable<Hybrid>;
59  friend class Dense<ValueType>;
60  friend class Csr<ValueType, IndexType>;
61  friend class Hybrid<to_complex<ValueType>, IndexType>;
62  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
63 
64 public:
67  using ConvertibleTo<
68  Hybrid<next_precision<ValueType>, IndexType>>::convert_to;
69  using ConvertibleTo<Hybrid<next_precision<ValueType>, IndexType>>::move_to;
70  using ConvertibleTo<Dense<ValueType>>::convert_to;
71  using ConvertibleTo<Dense<ValueType>>::move_to;
72  using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
73  using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
75 
76  using value_type = ValueType;
77  using index_type = IndexType;
78  using mat_data = matrix_data<ValueType, IndexType>;
79  using device_mat_data = device_matrix_data<ValueType, IndexType>;
80  using device_view = view::hybrid<value_type, index_type>;
81  using const_device_view = view::hybrid<const value_type, const index_type>;
82  using coo_type = Coo<ValueType, IndexType>;
83  using ell_type = Ell<ValueType, IndexType>;
84  using absolute_type = remove_complex<Hybrid>;
85 
86 
96  class strategy_type {
97  public:
102  : ell_num_stored_elements_per_row_(zero<size_type>()),
103  coo_nnz_(zero<size_type>())
104  {}
105 
119  size_type* ell_num_stored_elements_per_row,
120  size_type* coo_nnz)
121  {
122  array<size_type> ref_row_nnz(row_nnz.get_executor()->get_master(),
123  row_nnz.get_size());
124  ref_row_nnz = row_nnz;
125  ell_num_stored_elements_per_row_ =
126  this->compute_ell_num_stored_elements_per_row(&ref_row_nnz);
127  coo_nnz_ = this->compute_coo_nnz(ref_row_nnz);
128  *ell_num_stored_elements_per_row = ell_num_stored_elements_per_row_;
129  *coo_nnz = coo_nnz_;
130  }
131 
138  {
139  return ell_num_stored_elements_per_row_;
140  }
141 
147  size_type get_coo_nnz() const noexcept { return coo_nnz_; }
148 
157  array<size_type>* row_nnz) const = 0;
158 
159  protected:
168  size_type compute_coo_nnz(const array<size_type>& row_nnz) const
169  {
170  size_type coo_nnz = 0;
171  auto row_nnz_val = row_nnz.get_const_data();
172  for (size_type i = 0; i < row_nnz.get_size(); i++) {
173  if (row_nnz_val[i] > ell_num_stored_elements_per_row_) {
174  coo_nnz +=
175  row_nnz_val[i] - ell_num_stored_elements_per_row_;
176  }
177  }
178  return coo_nnz;
179  }
180 
181  private:
182  size_type ell_num_stored_elements_per_row_;
183  size_type coo_nnz_;
184  };
185 
190  class column_limit : public strategy_type {
191  public:
197  explicit column_limit(size_type num_column = 0)
198  : num_columns_(num_column)
199  {}
200 
202  array<size_type>* row_nnz) const override
203  {
204  return num_columns_;
205  }
206 
212  auto get_num_columns() const { return num_columns_; }
213 
214  private:
215  size_type num_columns_;
216  };
217 
226  public:
233  explicit imbalance_limit(double percent = 0.8) : percent_(percent)
234  {
235  percent_ = std::min(percent_, 1.0);
236  percent_ = std::max(percent_, 0.0);
237  }
238 
240  array<size_type>* row_nnz) const override
241  {
242  auto row_nnz_val = row_nnz->get_data();
243  auto num_rows = row_nnz->get_size();
244  if (num_rows == 0) {
245  return 0;
246  }
247  std::sort(row_nnz_val, row_nnz_val + num_rows);
248  if (percent_ < 1) {
249  auto percent_pos = static_cast<size_type>(num_rows * percent_);
250  return row_nnz_val[percent_pos];
251  } else {
252  return row_nnz_val[num_rows - 1];
253  }
254  }
255 
261  auto get_percentage() const { return percent_; }
262 
263  private:
264  double percent_;
265  };
266 
273  public:
277  imbalance_bounded_limit(double percent = 0.8, double ratio = 0.0001)
278  : strategy_(imbalance_limit(percent)), ratio_(ratio)
279  {}
280 
282  array<size_type>* row_nnz) const override
283  {
284  auto num_rows = row_nnz->get_size();
285  auto ell_cols =
286  strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
287  return std::min(ell_cols,
288  static_cast<size_type>(num_rows * ratio_));
289  }
290 
296  auto get_percentage() const { return strategy_.get_percentage(); }
297 
303  auto get_ratio() const { return ratio_; }
304 
305  private:
306  imbalance_limit strategy_;
307  double ratio_;
308  };
309 
310 
317  public:
322  : strategy_(
323  imbalance_limit(static_cast<double>(sizeof(IndexType)) /
324  (sizeof(ValueType) + 2 * sizeof(IndexType))))
325  {}
326 
328  array<size_type>* row_nnz) const override
329  {
330  return strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
331  }
332 
338  auto get_percentage() const { return strategy_.get_percentage(); }
339 
340  private:
341  imbalance_limit strategy_;
342  };
343 
344 
349  class automatic : public strategy_type {
350  public:
354  automatic() : strategy_(imbalance_bounded_limit(1.0 / 3.0, 0.001)) {}
355 
357  array<size_type>* row_nnz) const override
358  {
359  return strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
360  }
361 
362  private:
363  imbalance_bounded_limit strategy_;
364  };
365 
366  friend class Hybrid<previous_precision<ValueType>, IndexType>;
367 
368  void convert_to(
369  Hybrid<next_precision<ValueType>, IndexType>* result) const override;
370 
371  void move_to(Hybrid<next_precision<ValueType>, IndexType>* result) override;
372 
373 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
374  friend class Hybrid<previous_precision<ValueType, 2>, IndexType>;
375  using ConvertibleTo<
376  Hybrid<next_precision<ValueType, 2>, IndexType>>::convert_to;
377  using ConvertibleTo<
378  Hybrid<next_precision<ValueType, 2>, IndexType>>::move_to;
379 
380  void convert_to(
381  Hybrid<next_precision<ValueType, 2>, IndexType>* result) const override;
382 
383  void move_to(
384  Hybrid<next_precision<ValueType, 2>, IndexType>* result) override;
385 #endif
386 
387 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
388  friend class Hybrid<previous_precision<ValueType, 3>, IndexType>;
389  using ConvertibleTo<
390  Hybrid<next_precision<ValueType, 3>, IndexType>>::convert_to;
391  using ConvertibleTo<
392  Hybrid<next_precision<ValueType, 3>, IndexType>>::move_to;
393 
394  void convert_to(
395  Hybrid<next_precision<ValueType, 3>, IndexType>* result) const override;
396 
397  void move_to(
398  Hybrid<next_precision<ValueType, 3>, IndexType>* result) override;
399 #endif
400 
401  void convert_to(Dense<ValueType>* other) const override;
402 
403  void move_to(Dense<ValueType>* other) override;
404 
405  void convert_to(Csr<ValueType, IndexType>* other) const override;
406 
407  void move_to(Csr<ValueType, IndexType>* other) override;
408 
409  void read(const mat_data& data) override;
410 
411  void read(const device_mat_data& data) override;
412 
413  void read(device_mat_data&& data) override;
414 
416 
417  void write(mat_data& data) const override;
418 
419  std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
420 
421  std::unique_ptr<absolute_type> compute_absolute() const override;
422 
423  void compute_absolute_inplace() override;
424 
430  value_type* get_ell_values() noexcept { return ell_->get_values(); }
431 
439  const value_type* get_const_ell_values() const noexcept
440  {
441  return ell_->get_const_values();
442  }
443 
449  index_type* get_ell_col_idxs() noexcept { return ell_->get_col_idxs(); }
450 
458  const index_type* get_const_ell_col_idxs() const noexcept
459  {
460  return ell_->get_const_col_idxs();
461  }
462 
469  {
470  return ell_->get_num_stored_elements_per_row();
471  }
472 
478  size_type get_ell_stride() const noexcept { return ell_->get_stride(); }
479 
486  {
487  return ell_->get_num_stored_elements();
488  }
489 
501  value_type& ell_val_at(size_type row, size_type idx) noexcept
502  {
503  return ell_->val_at(row, idx);
504  }
505 
509  value_type ell_val_at(size_type row, size_type idx) const noexcept
510  {
511  return ell_->val_at(row, idx);
512  }
513 
524  index_type& ell_col_at(size_type row, size_type idx) noexcept
525  {
526  return ell_->col_at(row, idx);
527  }
528 
532  index_type ell_col_at(size_type row, size_type idx) const noexcept
533  {
534  return ell_->col_at(row, idx);
535  }
536 
542  const ell_type* get_ell() const noexcept { return ell_.get(); }
543 
549  value_type* get_coo_values() noexcept { return coo_->get_values(); }
550 
558  const value_type* get_const_coo_values() const noexcept
559  {
560  return coo_->get_const_values();
561  }
562 
568  index_type* get_coo_col_idxs() noexcept { return coo_->get_col_idxs(); }
569 
577  const index_type* get_const_coo_col_idxs() const noexcept
578  {
579  return coo_->get_const_col_idxs();
580  }
581 
587  index_type* get_coo_row_idxs() noexcept { return coo_->get_row_idxs(); }
588 
596  const index_type* get_const_coo_row_idxs() const noexcept
597  {
598  return coo_->get_const_row_idxs();
599  }
600 
607  {
608  return coo_->get_num_stored_elements();
609  }
610 
616  const coo_type* get_coo() const noexcept { return coo_.get(); }
617 
624  {
625  return coo_->get_num_stored_elements() +
626  ell_->get_num_stored_elements();
627  }
628 
634  std::shared_ptr<strategy_type> get_strategy() const noexcept
635  {
636  return strategy_;
637  }
638 
646  template <typename HybType>
647  std::shared_ptr<typename HybType::strategy_type> get_strategy() const;
648 
654  device_view get_device_view();
655 
661  const_device_view get_const_device_view() const;
662 
673  static std::unique_ptr<Hybrid> create(
674  std::shared_ptr<const Executor> exec,
675  std::shared_ptr<strategy_type> strategy =
676  std::make_shared<automatic>());
677 
689  static std::unique_ptr<Hybrid> create(
690  std::shared_ptr<const Executor> exec, const dim<2>& size,
691  std::shared_ptr<strategy_type> strategy =
692  std::make_shared<automatic>());
693 
706  static std::unique_ptr<Hybrid> create(
707  std::shared_ptr<const Executor> exec, const dim<2>& size,
708  size_type num_stored_elements_per_row,
709  std::shared_ptr<strategy_type> strategy =
710  std::make_shared<automatic>());
711 
724  static std::unique_ptr<Hybrid> create(
725  std::shared_ptr<const Executor> exec, const dim<2>& size,
726  size_type num_stored_elements_per_row, size_type stride,
727  std::shared_ptr<strategy_type> strategy);
728 
742  static std::unique_ptr<Hybrid> create(
743  std::shared_ptr<const Executor> exec, const dim<2>& size,
744  size_type num_stored_elements_per_row, size_type stride,
745  size_type num_nonzeros = {},
746  std::shared_ptr<strategy_type> strategy =
747  std::make_shared<automatic>());
748 
753  Hybrid& operator=(const Hybrid&);
754 
760  Hybrid& operator=(Hybrid&&);
761 
766  Hybrid(const Hybrid&);
767 
773  Hybrid(Hybrid&&);
774 
775 protected:
776  Hybrid(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
777  size_type num_stored_elements_per_row = 0, size_type stride = 0,
778  size_type num_nonzeros = 0,
779  std::shared_ptr<strategy_type> strategy =
780  std::make_shared<automatic>());
781 
792  void resize(dim<2> new_size, size_type ell_row_nnz, size_type coo_nnz);
793 
794  void apply_impl(const LinOp* b, LinOp* x) const override;
795 
796  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
797  LinOp* x) const override;
798 
799 private:
800  std::unique_ptr<ell_type> ell_;
801  std::unique_ptr<coo_type> coo_;
802  std::shared_ptr<strategy_type> strategy_;
803 };
804 
805 
806 template <typename ValueType, typename IndexType>
807 template <typename HybType>
808 std::shared_ptr<typename HybType::strategy_type>
810 {
811  static_assert(
812  std::is_same<HybType, Hybrid<typename HybType::value_type,
813  typename HybType::index_type>>::value,
814  "The given `HybType` type must be of type `matrix::Hybrid`!");
815 
816  std::shared_ptr<typename HybType::strategy_type> strategy;
817  if (std::dynamic_pointer_cast<automatic>(strategy_)) {
818  strategy = std::make_shared<typename HybType::automatic>();
819  } else if (auto temp = std::dynamic_pointer_cast<minimal_storage_limit>(
820  strategy_)) {
821  // minimal_storage_limit is related to ValueType and IndexType size.
822  if (sizeof(value_type) == sizeof(typename HybType::value_type) &&
823  sizeof(index_type) == sizeof(typename HybType::index_type)) {
824  strategy =
825  std::make_shared<typename HybType::minimal_storage_limit>();
826  } else {
827  strategy = std::make_shared<typename HybType::imbalance_limit>(
828  temp->get_percentage());
829  }
830  } else if (auto temp = std::dynamic_pointer_cast<imbalance_bounded_limit>(
831  strategy_)) {
832  strategy = std::make_shared<typename HybType::imbalance_bounded_limit>(
833  temp->get_percentage(), temp->get_ratio());
834  } else if (auto temp =
835  std::dynamic_pointer_cast<imbalance_limit>(strategy_)) {
836  strategy = std::make_shared<typename HybType::imbalance_limit>(
837  temp->get_percentage());
838  } else if (auto temp = std::dynamic_pointer_cast<column_limit>(strategy_)) {
839  strategy = std::make_shared<typename HybType::column_limit>(
840  temp->get_num_columns());
841  } else {
842  GKO_NOT_SUPPORTED(strategy_);
843  }
844  return strategy;
845 }
846 
847 
848 } // namespace matrix
849 } // namespace gko
850 
851 
852 #endif // GKO_PUBLIC_CORE_MATRIX_HYBRID_HPP_
gko::matrix::Hybrid::get_const_coo_values
const value_type * get_const_coo_values() const noexcept
Returns the values of the coo part.
Definition: hybrid.hpp:558
gko::matrix::Hybrid::ell_col_at
index_type ell_col_at(size_type row, size_type idx) const noexcept
Returns the idx-th column index of the row-th row in the ell part.
Definition: hybrid.hpp:532
gko::matrix::Hybrid::get_ell_num_stored_elements_per_row
size_type get_ell_num_stored_elements_per_row() const noexcept
Returns the number of stored elements per row of ell part.
Definition: hybrid.hpp:468
gko::matrix::Hybrid::get_const_coo_row_idxs
const index_type * get_const_coo_row_idxs() const noexcept
Returns the row indexes of the coo part.
Definition: hybrid.hpp:596
gko::matrix::Hybrid::minimal_storage_limit::minimal_storage_limit
minimal_storage_limit()
Creates a minimal_storage_limit strategy.
Definition: hybrid.hpp:321
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::Hybrid::imbalance_bounded_limit::imbalance_bounded_limit
imbalance_bounded_limit(double percent=0.8, double ratio=0.0001)
Creates a imbalance_bounded_limit strategy.
Definition: hybrid.hpp:277
gko::matrix::Hybrid::column_limit
column_limit is a strategy_type which decides the number of stored elements per row of the ell part b...
Definition: hybrid.hpp:190
gko::matrix::Hybrid::automatic::compute_ell_num_stored_elements_per_row
size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const override
Computes the number of stored elements per row of the ell part.
Definition: hybrid.hpp:356
gko::matrix::Hybrid::imbalance_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:261
gko::ReadableFromMatrixData::read
virtual void read(const matrix_data< ValueType, IndexType > &data)=0
Reads a matrix from a matrix_data structure.
gko::matrix::Dense
Dense is a matrix format which explicitly stores all values of the matrix.
Definition: dense_cache.hpp:28
gko::matrix::Hybrid::strategy_type
strategy_type is to decide how to set the hybrid config.
Definition: hybrid.hpp:96
gko::matrix::Hybrid::strategy_type::compute_hybrid_config
void compute_hybrid_config(const array< size_type > &row_nnz, size_type *ell_num_stored_elements_per_row, size_type *coo_nnz)
Computes the config of the Hybrid matrix (ell_num_stored_elements_per_row and coo_nnz).
Definition: hybrid.hpp:118
gko::matrix::Hybrid::ell_col_at
index_type & ell_col_at(size_type row, size_type idx) noexcept
Returns the idx-th column index of the row-th row in the ell part.
Definition: hybrid.hpp:524
gko::matrix::Hybrid::get_ell
const ell_type * get_ell() const noexcept
Returns the matrix of the ell part.
Definition: hybrid.hpp:542
gko::matrix::Hybrid::get_coo_values
value_type * get_coo_values() noexcept
Returns the values of the coo part.
Definition: hybrid.hpp:549
gko::matrix::Hybrid::get_ell_col_idxs
index_type * get_ell_col_idxs() noexcept
Returns the column indexes of the ell part.
Definition: hybrid.hpp:449
gko::matrix::Hybrid::strategy_type::get_ell_num_stored_elements_per_row
size_type get_ell_num_stored_elements_per_row() const noexcept
Returns the number of stored elements per row of the ell part.
Definition: hybrid.hpp:137
gko::matrix::Hybrid::column_limit::compute_ell_num_stored_elements_per_row
size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const override
Computes the number of stored elements per row of the ell part.
Definition: hybrid.hpp:201
gko::matrix::Hybrid::get_ell_values
value_type * get_ell_values() noexcept
Returns the values of the ell part.
Definition: hybrid.hpp:430
gko::matrix::Hybrid::automatic
automatic is a strategy_type which decides the number of stored elements per row of the ell part auto...
Definition: hybrid.hpp:349
gko::matrix::Hybrid::get_coo_num_stored_elements
size_type get_coo_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the coo part.
Definition: hybrid.hpp:606
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:101
gko::matrix::Hybrid::read
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
gko::matrix::Hybrid::get_coo_row_idxs
index_type * get_coo_row_idxs() noexcept
Returns the row indexes of the coo part.
Definition: hybrid.hpp:587
gko::matrix::Hybrid::minimal_storage_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:338
gko::matrix::Hybrid::get_ell_stride
size_type get_ell_stride() const noexcept
Returns the stride of the ell part.
Definition: hybrid.hpp:478
gko::matrix::Hybrid::get_const_ell_values
const value_type * get_const_ell_values() const noexcept
Returns the values of the ell part.
Definition: hybrid.hpp:439
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::matrix::Hybrid::get_const_device_view
const_device_view get_const_device_view() const
Returns a non-owning const device view of this matrix.
gko::matrix::Hybrid::minimal_storage_limit::compute_ell_num_stored_elements_per_row
size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const override
Computes the number of stored elements per row of the ell part.
Definition: hybrid.hpp:327
gko::matrix::Hybrid::get_num_stored_elements
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: hybrid.hpp:623
gko::array< size_type >
gko::dim< 2 >
gko::matrix::Hybrid::get_coo_col_idxs
index_type * get_coo_col_idxs() noexcept
Returns the column indexes of the coo part.
Definition: hybrid.hpp:568
gko::matrix::Hybrid::get_const_coo_col_idxs
const index_type * get_const_coo_col_idxs() const noexcept
Returns the column indexes of the coo part.
Definition: hybrid.hpp:577
gko::matrix::Hybrid::strategy_type::compute_ell_num_stored_elements_per_row
virtual size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const =0
Computes the number of stored elements per row of the ell part.
gko::matrix::Hybrid::strategy_type::get_coo_nnz
size_type get_coo_nnz() const noexcept
Returns the number of nonzeros of the coo part.
Definition: hybrid.hpp:147
gko::matrix::Hybrid::imbalance_limit::compute_ell_num_stored_elements_per_row
size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const override
Computes the number of stored elements per row of the ell part.
Definition: hybrid.hpp:239
gko::matrix::Hybrid::imbalance_bounded_limit
imbalance_bounded_limit is a strategy_type which decides the number of stored elements per row of the...
Definition: hybrid.hpp:272
gko::matrix::Hybrid::get_device_view
device_view get_device_view()
Returns a non-owning device view of this matrix.
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::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
gko::matrix::Hybrid::get_strategy
std::shared_ptr< strategy_type > get_strategy() const noexcept
Returns the strategy.
Definition: hybrid.hpp:634
gko::matrix::Hybrid::create
static std::unique_ptr< Hybrid > create(std::shared_ptr< const Executor > exec, std::shared_ptr< strategy_type > strategy=std::make_shared< automatic >())
Creates an uninitialized Hybrid matrix of specified method.
gko::matrix::Hybrid::strategy_type::strategy_type
strategy_type()
Creates a strategy_type.
Definition: hybrid.hpp:101
gko::matrix::Hybrid::automatic::automatic
automatic()
Creates an automatic strategy.
Definition: hybrid.hpp:354
gko::array::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor associated with the array.
Definition: array.hpp:702
gko::matrix::Hybrid::get_const_ell_col_idxs
const index_type * get_const_ell_col_idxs() const noexcept
Returns the column indexes of the ell part.
Definition: hybrid.hpp:458
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::Hybrid::compute_absolute_inplace
void compute_absolute_inplace() override
Compute absolute inplace on each element.
gko::EnableCloneable::convert_to
void convert_to(result_type *result) const override
Converts the implementer to an object of type result_type.
Definition: polymorphic_object.hpp:411
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::Hybrid::column_limit::get_num_columns
auto get_num_columns() const
Get the number of columns limit.
Definition: hybrid.hpp:212
gko::matrix::Hybrid::compute_absolute
std::unique_ptr< absolute_type > compute_absolute() const override
Gets the AbsoluteLinOp.
gko::matrix::Hybrid::column_limit::column_limit
column_limit(size_type num_column=0)
Creates a column_limit strategy.
Definition: hybrid.hpp:197
gko::matrix::Hybrid::ell_val_at
value_type & ell_val_at(size_type row, size_type idx) noexcept
Returns the idx-th non-zero element of the row-th row in the ell part.
Definition: hybrid.hpp:501
gko::matrix::Hybrid::write
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
gko::matrix::Hybrid::imbalance_limit
imbalance_limit is a strategy_type which decides the number of stored elements per row of the ell par...
Definition: hybrid.hpp:225
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:32
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::Hybrid::Hybrid
Hybrid(const Hybrid &)
Copy-assigns a Hybrid matrix.
gko::matrix::Hybrid::ell_val_at
value_type ell_val_at(size_type row, size_type idx) const noexcept
Returns the idx-th non-zero element of the row-th row in the ell part.
Definition: hybrid.hpp:509
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::Hybrid::get_ell_num_stored_elements
size_type get_ell_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the ell part.
Definition: hybrid.hpp:485
gko::matrix::Hybrid::extract_diagonal
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
Extracts the diagonal entries of the matrix into a vector.
gko::EnableCloneable::move_to
void move_to(result_type *result) override
Converts the implementer to an object of type result_type by moving data from this object.
Definition: polymorphic_object.hpp:413
gko::array::get_size
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition: array.hpp:669
gko::matrix::Hybrid::get_coo
const coo_type * get_coo() const noexcept
Returns the matrix of the coo part.
Definition: hybrid.hpp:616
gko::matrix::Hybrid::imbalance_limit::imbalance_limit
imbalance_limit(double percent=0.8)
Creates a imbalance_limit strategy.
Definition: hybrid.hpp:233
gko::matrix::Hybrid::imbalance_bounded_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:296
gko::matrix::Hybrid::minimal_storage_limit
minimal_storage_limit is a strategy_type which decides the number of stored elements per row of the e...
Definition: hybrid.hpp:316
gko::matrix::Hybrid::imbalance_bounded_limit::compute_ell_num_stored_elements_per_row
size_type compute_ell_num_stored_elements_per_row(array< size_type > *row_nnz) const override
Computes the number of stored elements per row of the ell part.
Definition: hybrid.hpp:281
gko::matrix::Hybrid::imbalance_bounded_limit::get_ratio
auto get_ratio() const
Get the ratio setting.
Definition: hybrid.hpp:303
gko::LinOp::LinOp
LinOp(const LinOp &)=default
Copy-constructs a LinOp.
gko::matrix::Hybrid::operator=
Hybrid & operator=(const Hybrid &)
Copy-assigns a Hybrid matrix.
gko::zero
constexpr T zero()
Returns the additive identity for T.
Definition: math.hpp:625
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