Ginkgo  Generated from pipelines/2662685947 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 
41 template <typename ValueType = default_precision, typename IndexType = int32>
42 class Hybrid
43  : public LinOp,
44  public EnableCloneable<Hybrid<ValueType, IndexType>>,
45  public ConvertibleTo<Hybrid<next_precision<ValueType>, IndexType>>,
46 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
47  public ConvertibleTo<Hybrid<next_precision<ValueType, 2>, IndexType>>,
48 #endif
49 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
50  public ConvertibleTo<Hybrid<next_precision<ValueType, 3>, IndexType>>,
51 #endif
52  public ConvertibleTo<Dense<ValueType>>,
53  public ConvertibleTo<Csr<ValueType, IndexType>>,
54  public DiagonalExtractable<ValueType>,
55  public ReadableFromMatrixData<ValueType, IndexType>,
56  public WritableToMatrixData<ValueType, IndexType>,
57  public EnableAbsoluteComputation<
58  remove_complex<Hybrid<ValueType, IndexType>>> {
59  friend class EnableCloneable<Hybrid>;
60  friend class Dense<ValueType>;
61  friend class Csr<ValueType, IndexType>;
62  friend class Hybrid<to_complex<ValueType>, IndexType>;
63  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
64 
65 public:
68  using ConvertibleTo<
69  Hybrid<next_precision<ValueType>, IndexType>>::convert_to;
70  using ConvertibleTo<Hybrid<next_precision<ValueType>, IndexType>>::move_to;
71  using ConvertibleTo<Dense<ValueType>>::convert_to;
72  using ConvertibleTo<Dense<ValueType>>::move_to;
73  using ConvertibleTo<Csr<ValueType, IndexType>>::convert_to;
74  using ConvertibleTo<Csr<ValueType, IndexType>>::move_to;
76 
77  using value_type = ValueType;
78  using index_type = IndexType;
79  using mat_data = matrix_data<ValueType, IndexType>;
80  using device_mat_data = device_matrix_data<ValueType, IndexType>;
81  using device_view = view::hybrid<value_type, index_type>;
82  using const_device_view = view::hybrid<const value_type, const index_type>;
83  using coo_type = Coo<ValueType, IndexType>;
84  using ell_type = Ell<ValueType, IndexType>;
85  using absolute_type = remove_complex<Hybrid>;
86 
87 
97  class strategy_type {
98  public:
103  : ell_num_stored_elements_per_row_(zero<size_type>()),
104  coo_nnz_(zero<size_type>())
105  {}
106 
120  size_type* ell_num_stored_elements_per_row,
121  size_type* coo_nnz)
122  {
123  array<size_type> ref_row_nnz(row_nnz.get_executor()->get_master(),
124  row_nnz.get_size());
125  ref_row_nnz = row_nnz;
126  ell_num_stored_elements_per_row_ =
127  this->compute_ell_num_stored_elements_per_row(&ref_row_nnz);
128  coo_nnz_ = this->compute_coo_nnz(ref_row_nnz);
129  *ell_num_stored_elements_per_row = ell_num_stored_elements_per_row_;
130  *coo_nnz = coo_nnz_;
131  }
132 
139  {
140  return ell_num_stored_elements_per_row_;
141  }
142 
148  size_type get_coo_nnz() const noexcept { return coo_nnz_; }
149 
158  array<size_type>* row_nnz) const = 0;
159 
160  protected:
169  size_type compute_coo_nnz(const array<size_type>& row_nnz) const
170  {
171  size_type coo_nnz = 0;
172  auto row_nnz_val = row_nnz.get_const_data();
173  for (size_type i = 0; i < row_nnz.get_size(); i++) {
174  if (row_nnz_val[i] > ell_num_stored_elements_per_row_) {
175  coo_nnz +=
176  row_nnz_val[i] - ell_num_stored_elements_per_row_;
177  }
178  }
179  return coo_nnz;
180  }
181 
182  private:
183  size_type ell_num_stored_elements_per_row_;
184  size_type coo_nnz_;
185  };
186 
191  class column_limit : public strategy_type {
192  public:
198  explicit column_limit(size_type num_column = 0)
199  : num_columns_(num_column)
200  {}
201 
203  array<size_type>* row_nnz) const override
204  {
205  return num_columns_;
206  }
207 
213  auto get_num_columns() const { return num_columns_; }
214 
215  private:
216  size_type num_columns_;
217  };
218 
227  public:
234  explicit imbalance_limit(double percent = 0.8) : percent_(percent)
235  {
236  percent_ = std::min(percent_, 1.0);
237  percent_ = std::max(percent_, 0.0);
238  }
239 
241  array<size_type>* row_nnz) const override
242  {
243  auto row_nnz_val = row_nnz->get_data();
244  auto num_rows = row_nnz->get_size();
245  if (num_rows == 0) {
246  return 0;
247  }
248  std::sort(row_nnz_val, row_nnz_val + num_rows);
249  if (percent_ < 1) {
250  auto percent_pos = static_cast<size_type>(num_rows * percent_);
251  return row_nnz_val[percent_pos];
252  } else {
253  return row_nnz_val[num_rows - 1];
254  }
255  }
256 
262  auto get_percentage() const { return percent_; }
263 
264  private:
265  double percent_;
266  };
267 
274  public:
278  imbalance_bounded_limit(double percent = 0.8, double ratio = 0.0001)
279  : strategy_(imbalance_limit(percent)), ratio_(ratio)
280  {}
281 
283  array<size_type>* row_nnz) const override
284  {
285  auto num_rows = row_nnz->get_size();
286  auto ell_cols =
287  strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
288  return std::min(ell_cols,
289  static_cast<size_type>(num_rows * ratio_));
290  }
291 
297  auto get_percentage() const { return strategy_.get_percentage(); }
298 
304  auto get_ratio() const { return ratio_; }
305 
306  private:
307  imbalance_limit strategy_;
308  double ratio_;
309  };
310 
311 
318  public:
323  : strategy_(
324  imbalance_limit(static_cast<double>(sizeof(IndexType)) /
325  (sizeof(ValueType) + 2 * sizeof(IndexType))))
326  {}
327 
329  array<size_type>* row_nnz) const override
330  {
331  return strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
332  }
333 
339  auto get_percentage() const { return strategy_.get_percentage(); }
340 
341  private:
342  imbalance_limit strategy_;
343  };
344 
345 
350  class automatic : public strategy_type {
351  public:
355  automatic() : strategy_(imbalance_bounded_limit(1.0 / 3.0, 0.001)) {}
356 
358  array<size_type>* row_nnz) const override
359  {
360  return strategy_.compute_ell_num_stored_elements_per_row(row_nnz);
361  }
362 
363  private:
364  imbalance_bounded_limit strategy_;
365  };
366 
367  friend class Hybrid<previous_precision<ValueType>, IndexType>;
368 
369  void convert_to(
370  Hybrid<next_precision<ValueType>, IndexType>* result) const override;
371 
372  void move_to(Hybrid<next_precision<ValueType>, IndexType>* result) override;
373 
374 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
375  friend class Hybrid<previous_precision<ValueType, 2>, IndexType>;
376  using ConvertibleTo<
377  Hybrid<next_precision<ValueType, 2>, IndexType>>::convert_to;
378  using ConvertibleTo<
379  Hybrid<next_precision<ValueType, 2>, IndexType>>::move_to;
380 
381  void convert_to(
382  Hybrid<next_precision<ValueType, 2>, IndexType>* result) const override;
383 
384  void move_to(
385  Hybrid<next_precision<ValueType, 2>, IndexType>* result) override;
386 #endif
387 
388 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
389  friend class Hybrid<previous_precision<ValueType, 3>, IndexType>;
390  using ConvertibleTo<
391  Hybrid<next_precision<ValueType, 3>, IndexType>>::convert_to;
392  using ConvertibleTo<
393  Hybrid<next_precision<ValueType, 3>, IndexType>>::move_to;
394 
395  void convert_to(
396  Hybrid<next_precision<ValueType, 3>, IndexType>* result) const override;
397 
398  void move_to(
399  Hybrid<next_precision<ValueType, 3>, IndexType>* result) override;
400 #endif
401 
402  void convert_to(Dense<ValueType>* other) const override;
403 
404  void move_to(Dense<ValueType>* other) override;
405 
406  void convert_to(Csr<ValueType, IndexType>* other) const override;
407 
408  void move_to(Csr<ValueType, IndexType>* other) override;
409 
410  void read(const mat_data& data) override;
411 
412  void read(const device_mat_data& data) override;
413 
414  void read(device_mat_data&& data) override;
415 
416  void write(mat_data& data) const override;
417 
418  std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
419 
420  std::unique_ptr<absolute_type> compute_absolute() const override;
421 
422  void compute_absolute_inplace() override;
423 
429  value_type* get_ell_values() noexcept { return ell_->get_values(); }
430 
438  const value_type* get_const_ell_values() const noexcept
439  {
440  return ell_->get_const_values();
441  }
442 
448  index_type* get_ell_col_idxs() noexcept { return ell_->get_col_idxs(); }
449 
457  const index_type* get_const_ell_col_idxs() const noexcept
458  {
459  return ell_->get_const_col_idxs();
460  }
461 
468  {
469  return ell_->get_num_stored_elements_per_row();
470  }
471 
477  size_type get_ell_stride() const noexcept { return ell_->get_stride(); }
478 
485  {
486  return ell_->get_num_stored_elements();
487  }
488 
500  value_type& ell_val_at(size_type row, size_type idx) noexcept
501  {
502  return ell_->val_at(row, idx);
503  }
504 
508  value_type ell_val_at(size_type row, size_type idx) const noexcept
509  {
510  return ell_->val_at(row, idx);
511  }
512 
523  index_type& ell_col_at(size_type row, size_type idx) noexcept
524  {
525  return ell_->col_at(row, idx);
526  }
527 
531  index_type ell_col_at(size_type row, size_type idx) const noexcept
532  {
533  return ell_->col_at(row, idx);
534  }
535 
541  const ell_type* get_ell() const noexcept { return ell_.get(); }
542 
548  value_type* get_coo_values() noexcept { return coo_->get_values(); }
549 
557  const value_type* get_const_coo_values() const noexcept
558  {
559  return coo_->get_const_values();
560  }
561 
567  index_type* get_coo_col_idxs() noexcept { return coo_->get_col_idxs(); }
568 
576  const index_type* get_const_coo_col_idxs() const noexcept
577  {
578  return coo_->get_const_col_idxs();
579  }
580 
586  index_type* get_coo_row_idxs() noexcept { return coo_->get_row_idxs(); }
587 
595  const index_type* get_const_coo_row_idxs() const noexcept
596  {
597  return coo_->get_const_row_idxs();
598  }
599 
606  {
607  return coo_->get_num_stored_elements();
608  }
609 
615  const coo_type* get_coo() const noexcept { return coo_.get(); }
616 
623  {
624  return coo_->get_num_stored_elements() +
625  ell_->get_num_stored_elements();
626  }
627 
633  std::shared_ptr<strategy_type> get_strategy() const noexcept
634  {
635  return strategy_;
636  }
637 
645  template <typename HybType>
646  std::shared_ptr<typename HybType::strategy_type> get_strategy() const;
647 
653  device_view get_device_view();
654 
660  const_device_view get_const_device_view() const;
661 
672  static std::unique_ptr<Hybrid> create(
673  std::shared_ptr<const Executor> exec,
674  std::shared_ptr<strategy_type> strategy =
675  std::make_shared<automatic>());
676 
688  static std::unique_ptr<Hybrid> create(
689  std::shared_ptr<const Executor> exec, const dim<2>& size,
690  std::shared_ptr<strategy_type> strategy =
691  std::make_shared<automatic>());
692 
705  static std::unique_ptr<Hybrid> create(
706  std::shared_ptr<const Executor> exec, const dim<2>& size,
707  size_type num_stored_elements_per_row,
708  std::shared_ptr<strategy_type> strategy =
709  std::make_shared<automatic>());
710 
723  static std::unique_ptr<Hybrid> create(
724  std::shared_ptr<const Executor> exec, const dim<2>& size,
725  size_type num_stored_elements_per_row, size_type stride,
726  std::shared_ptr<strategy_type> strategy);
727 
741  static std::unique_ptr<Hybrid> create(
742  std::shared_ptr<const Executor> exec, const dim<2>& size,
743  size_type num_stored_elements_per_row, size_type stride,
744  size_type num_nonzeros = {},
745  std::shared_ptr<strategy_type> strategy =
746  std::make_shared<automatic>());
747 
752  Hybrid& operator=(const Hybrid&);
753 
759  Hybrid& operator=(Hybrid&&);
760 
765  Hybrid(const Hybrid&);
766 
772  Hybrid(Hybrid&&);
773 
774 protected:
775  Hybrid(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
776  size_type num_stored_elements_per_row = 0, size_type stride = 0,
777  size_type num_nonzeros = 0,
778  std::shared_ptr<strategy_type> strategy =
779  std::make_shared<automatic>());
780 
791  void resize(dim<2> new_size, size_type ell_row_nnz, size_type coo_nnz);
792 
793  void apply_impl(const LinOp* b, LinOp* x) const override;
794 
795  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
796  LinOp* x) const override;
797 
798 private:
799  std::unique_ptr<ell_type> ell_;
800  std::unique_ptr<coo_type> coo_;
801  std::shared_ptr<strategy_type> strategy_;
802 };
803 
804 
805 template <typename ValueType, typename IndexType>
806 template <typename HybType>
807 std::shared_ptr<typename HybType::strategy_type>
809 {
810  static_assert(
811  std::is_same<HybType, Hybrid<typename HybType::value_type,
812  typename HybType::index_type>>::value,
813  "The given `HybType` type must be of type `matrix::Hybrid`!");
814 
815  std::shared_ptr<typename HybType::strategy_type> strategy;
816  if (std::dynamic_pointer_cast<automatic>(strategy_)) {
817  strategy = std::make_shared<typename HybType::automatic>();
818  } else if (auto temp = std::dynamic_pointer_cast<minimal_storage_limit>(
819  strategy_)) {
820  // minimal_storage_limit is related to ValueType and IndexType size.
821  if (sizeof(value_type) == sizeof(typename HybType::value_type) &&
822  sizeof(index_type) == sizeof(typename HybType::index_type)) {
823  strategy =
824  std::make_shared<typename HybType::minimal_storage_limit>();
825  } else {
826  strategy = std::make_shared<typename HybType::imbalance_limit>(
827  temp->get_percentage());
828  }
829  } else if (auto temp = std::dynamic_pointer_cast<imbalance_bounded_limit>(
830  strategy_)) {
831  strategy = std::make_shared<typename HybType::imbalance_bounded_limit>(
832  temp->get_percentage(), temp->get_ratio());
833  } else if (auto temp =
834  std::dynamic_pointer_cast<imbalance_limit>(strategy_)) {
835  strategy = std::make_shared<typename HybType::imbalance_limit>(
836  temp->get_percentage());
837  } else if (auto temp = std::dynamic_pointer_cast<column_limit>(strategy_)) {
838  strategy = std::make_shared<typename HybType::column_limit>(
839  temp->get_num_columns());
840  } else {
841  GKO_NOT_SUPPORTED(strategy_);
842  }
843  return strategy;
844 }
845 
846 
847 } // namespace matrix
848 } // namespace gko
849 
850 
851 #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:557
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:531
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:467
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:595
gko::matrix::Hybrid::minimal_storage_limit::minimal_storage_limit
minimal_storage_limit()
Creates a minimal_storage_limit strategy.
Definition: hybrid.hpp:322
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:278
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:191
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:357
gko::matrix::Hybrid::imbalance_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:262
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:97
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:119
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:523
gko::matrix::Hybrid::get_ell
const ell_type * get_ell() const noexcept
Returns the matrix of the ell part.
Definition: hybrid.hpp:541
gko::matrix::Hybrid::get_coo_values
value_type * get_coo_values() noexcept
Returns the values of the coo part.
Definition: hybrid.hpp:548
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:448
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:138
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:202
gko::matrix::Hybrid::get_ell_values
value_type * get_ell_values() noexcept
Returns the values of the ell part.
Definition: hybrid.hpp:429
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:350
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:605
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
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:586
gko::matrix::Hybrid::minimal_storage_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:339
gko::matrix::Hybrid::get_ell_stride
size_type get_ell_stride() const noexcept
Returns the stride of the ell part.
Definition: hybrid.hpp:477
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:438
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
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:328
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:622
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:567
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:576
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:148
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:240
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:273
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:687
gko::matrix::Hybrid::get_strategy
std::shared_ptr< strategy_type > get_strategy() const noexcept
Returns the strategy.
Definition: hybrid.hpp:633
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:102
gko::matrix::Hybrid::automatic::automatic
automatic()
Creates an automatic strategy.
Definition: hybrid.hpp:355
gko::array::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor associated with the array.
Definition: array.hpp:703
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:457
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:466
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:404
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:473
gko::matrix::Hybrid::column_limit::get_num_columns
auto get_num_columns() const
Get the number of columns limit.
Definition: hybrid.hpp:213
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:198
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:500
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:226
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:31
gko::ConvertibleTo
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition: polymorphic_object.hpp:140
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:508
gko::matrix::Hybrid
HYBRID is a matrix format which splits the matrix into ELLPACK and COO format.
Definition: coo.hpp:33
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:696
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:484
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:406
gko::array::get_size
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition: array.hpp:670
gko::matrix::Hybrid::get_coo
const coo_type * get_coo() const noexcept
Returns the matrix of the coo part.
Definition: hybrid.hpp:615
gko::matrix::Hybrid::imbalance_limit::imbalance_limit
imbalance_limit(double percent=0.8)
Creates a imbalance_limit strategy.
Definition: hybrid.hpp:234
gko::matrix::Hybrid::imbalance_bounded_limit::get_percentage
auto get_percentage() const
Get the percent setting.
Definition: hybrid.hpp:297
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:317
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:282
gko::matrix::Hybrid::imbalance_bounded_limit::get_ratio
auto get_ratio() const
Get the ratio setting.
Definition: hybrid.hpp:304
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:626
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:283
gko::matrix::Coo
COO stores a matrix in the coordinate matrix format.
Definition: coo.hpp:51