5#ifndef GKO_PUBLIC_CORE_BASE_LIN_OP_HPP_
6#define GKO_PUBLIC_CORE_BASE_LIN_OP_HPP_
13#include <ginkgo/core/base/abstract_factory.hpp>
14#include <ginkgo/core/base/device_matrix_data.hpp>
15#include <ginkgo/core/base/dim.hpp>
16#include <ginkgo/core/base/exception_helpers.hpp>
17#include <ginkgo/core/base/math.hpp>
18#include <ginkgo/core/base/matrix_assembly_data.hpp>
19#include <ginkgo/core/base/matrix_data.hpp>
20#include <ginkgo/core/base/polymorphic_object.hpp>
21#include <ginkgo/core/base/types.hpp>
22#include <ginkgo/core/base/utils.hpp>
23#include <ginkgo/core/log/logger.hpp>
30template <
typename ValueType>
131 this->
template log<log::Logger::linop_apply_started>(
this, b.
get(),
137 this->
template log<log::Logger::linop_apply_completed>(
this, b.
get(),
147 this->
template log<log::Logger::linop_apply_started>(
this, b.
get(),
153 this->
template log<log::Logger::linop_apply_completed>(
this, b.
get(),
171 this->
template log<log::Logger::linop_advanced_apply_started>(
180 this->
template log<log::Logger::linop_advanced_apply_completed>(
191 this->
template log<log::Logger::linop_advanced_apply_started>(
200 this->
template log<log::Logger::linop_advanced_apply_completed>(
231 if (
this != &other) {
248 size_{
std::exchange(other.size_,
dim<2>{})}
258 explicit LinOp(std::shared_ptr<const Executor> exec,
302 GKO_ASSERT_CONFORMANT(
this, b);
303 GKO_ASSERT_EQUAL_ROWS(
this, x);
304 GKO_ASSERT_EQUAL_COLS(b, x);
318 const LinOp* x)
const
320 this->validate_application_parameters(b, x);
321 GKO_ASSERT_EQUAL_DIMENSIONS(alpha,
dim<2>(1, 1));
322 GKO_ASSERT_EQUAL_DIMENSIONS(beta,
dim<2>(1, 1));
389 std::unique_ptr<LinOp> generate(std::shared_ptr<const LinOp> input)
const
391 this->
template log<log::Logger::linop_factory_generate_started>(
393 const auto exec = this->get_executor();
394 std::unique_ptr<LinOp> generated;
395 if (input->get_executor() == exec) {
396 generated = this->AbstractFactory::generate(input);
399 this->AbstractFactory::generate(
gko::clone(exec, input));
401 this->
template log<log::Logger::linop_factory_generate_completed>(
402 this, input.get(), generated.get());
483template <
typename IndexType>
505 return as<Permutable>(this->row_permute(permutation_indices))
506 ->column_permute(permutation_indices);
526 return as<Permutable>(this->inverse_row_permute(permutation_indices))
527 ->inverse_column_permute(permutation_indices);
604template <
typename ValueType,
typename IndexType>
607 using value_type = ValueType;
608 using index_type = IndexType;
647 this->
read(data.copy_to_host());
659template <
typename ValueType,
typename IndexType>
662 using value_type = ValueType;
663 using index_type = IndexType;
692 return preconditioner_;
703 preconditioner_ = new_precond;
707 std::shared_ptr<const LinOp> preconditioner_{};
741template <
typename ValueType>
744 using value_type = ValueType;
792template <
typename AbsoluteLinOp>
795 using absolute_type = AbsoluteLinOp;
801 return this->compute_absolute();
829 GKO_ASSERT_IS_SCALAR(a);
830 GKO_ASSERT_IS_SCALAR(b);
833 add_scaled_identity_impl(ae.get(), be.get());
837 virtual void add_scaled_identity_impl(
const LinOp* a,
const LinOp* b) = 0;
875template <
typename ConcreteLinOp,
typename PolymorphicBase = LinOp>
881 PolymorphicBase>::EnablePolymorphicObject;
886 PolymorphicBase::apply(b, x);
892 PolymorphicBase::apply(b, x);
901 PolymorphicBase::apply(alpha, b, beta, x);
908 PolymorphicBase::apply(alpha, b, beta, x);
913 GKO_ENABLE_SELF(ConcreteLinOp);
934template <
typename ConcreteFactory,
typename ConcreteLinOp,
935 typename ParametersType,
typename PolymorphicBase =
LinOpFactory>
1016#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name) \
1018 const _parameters_name##_type& get_##_parameters_name() const \
1020 return _parameters_name##_; \
1023 class _factory_name \
1024 : public ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
1025 _parameters_name##_type> { \
1026 friend class ::gko::EnablePolymorphicObject<_factory_name, \
1027 ::gko::LinOpFactory>; \
1028 friend class ::gko::enable_parameters_type<_parameters_name##_type, \
1030 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
1031 : ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
1032 _parameters_name##_type>( \
1035 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec, \
1036 const _parameters_name##_type& parameters) \
1037 : ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
1038 _parameters_name##_type>( \
1039 std::move(exec), parameters) \
1042 friend ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
1043 _parameters_name##_type>; \
1047 _parameters_name##_type _parameters_name##_; \
1050 static_assert(true, \
1051 "This assert is used to counter the false positive extra " \
1052 "semi-colon warnings")
Definition lin_op.hpp:765
virtual void compute_absolute_inplace()=0
virtual std::unique_ptr< LinOp > compute_absolute_linop() const =0
Definition abstract_factory.hpp:47
Definition lin_op.hpp:793
virtual std::unique_ptr< absolute_type > compute_absolute() const =0
std::unique_ptr< LinOp > compute_absolute_linop() const override
Definition lin_op.hpp:799
Definition polymorphic_object.hpp:354
Definition abstract_factory.hpp:126
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:743
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:385
Definition lin_op.hpp:117
LinOp * apply(ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x)
Definition lin_op.hpp:168
LinOp(const LinOp &)=default
void set_size(const dim< 2 > &value) noexcept
Definition lin_op.hpp:268
virtual void apply_impl(const LinOp *alpha, const LinOp *b, const LinOp *beta, LinOp *x) const =0
void validate_application_parameters(const LinOp *b, const LinOp *x) const
Definition lin_op.hpp:300
virtual bool apply_uses_initial_guess() const
Definition lin_op.hpp:219
LinOp(std::shared_ptr< const Executor > exec, const dim< 2 > &size=dim< 2 >{})
Definition lin_op.hpp:258
LinOp * apply(ptr_param< const LinOp > b, ptr_param< LinOp > x)
Definition lin_op.hpp:129
virtual void apply_impl(const LinOp *b, LinOp *x) const =0
void validate_application_parameters(const LinOp *alpha, const LinOp *b, const LinOp *beta, const LinOp *x) const
Definition lin_op.hpp:316
const dim< 2 > & get_size() const noexcept
Definition lin_op.hpp:210
LinOp(LinOp &&other)
Definition lin_op.hpp:246
LinOp & operator=(LinOp &&other)
Definition lin_op.hpp:229
const LinOp * apply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Definition lin_op.hpp:145
const LinOp * apply(ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x) const
Definition lin_op.hpp:188
LinOp & operator=(const LinOp &)=default
Definition lin_op.hpp:484
virtual std::unique_ptr< LinOp > inverse_column_permute(const array< IndexType > *permutation_indices) const =0
virtual std::unique_ptr< LinOp > row_permute(const array< IndexType > *permutation_indices) const =0
virtual std::unique_ptr< LinOp > inverse_row_permute(const array< IndexType > *permutation_indices) const =0
virtual std::unique_ptr< LinOp > inverse_permute(const array< IndexType > *permutation_indices) const
Definition lin_op.hpp:523
virtual std::unique_ptr< LinOp > column_permute(const array< IndexType > *permutation_indices) const =0
virtual std::unique_ptr< LinOp > permute(const array< IndexType > *permutation_indices) const
Definition lin_op.hpp:502
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:681
virtual void set_preconditioner(std::shared_ptr< const LinOp > new_precond)
Definition lin_op.hpp:701
virtual std::shared_ptr< const LinOp > get_preconditioner() const
Definition lin_op.hpp:690
Definition lin_op.hpp:605
virtual void read(const device_matrix_data< ValueType, IndexType > &data)
Definition lin_op.hpp:634
virtual void read(device_matrix_data< ValueType, IndexType > &&data)
Definition lin_op.hpp:645
void read(const matrix_assembly_data< ValueType, IndexType > &data)
Definition lin_op.hpp:624
virtual void read(const matrix_data< ValueType, IndexType > &data)=0
Definition lin_op.hpp:817
void add_scaled_identity(ptr_param< const LinOp > const a, ptr_param< const LinOp > const b)
Definition lin_op.hpp:826
Definition lin_op.hpp:433
virtual std::unique_ptr< LinOp > conj_transpose() const =0
virtual std::unique_ptr< LinOp > transpose() const =0
Definition lin_op.hpp:660
virtual void write(matrix_data< ValueType, IndexType > &data) const =0
Definition device_matrix_data.hpp:36
host_type copy_to_host() const
Definition matrix_assembly_data.hpp:59
matrix_data< ValueType, IndexType > get_ordered_data() const
Definition matrix_assembly_data.hpp:140
Definition utils_helper.hpp:41
T * get() const
Definition utils_helper.hpp:75
The Ginkgo namespace.
Definition abstract_factory.hpp:20
detail::cloned_type< Pointer > clone(const Pointer &p)
Definition utils_helper.hpp:173
std::unique_ptr< MatrixType > read(StreamType &&is, MatrixArgs &&... args)
Definition mtx_io.hpp:159
detail::temporary_clone< detail::pointee< Ptr > > make_temporary_clone(std::shared_ptr< const Executor > exec, Ptr &&ptr)
Definition temporary_clone.hpp:208
Definition matrix_data.hpp:126