33 #ifndef GKO_CORE_BASE_LIN_OP_HPP_ 34 #define GKO_CORE_BASE_LIN_OP_HPP_ 36 #include <ginkgo/core/base/abstract_factory.hpp> 37 #include <ginkgo/core/base/dim.hpp> 38 #include <ginkgo/core/base/exception_helpers.hpp> 39 #include <ginkgo/core/base/matrix_data.hpp> 40 #include <ginkgo/core/base/polymorphic_object.hpp> 41 #include <ginkgo/core/base/std_extensions.hpp> 42 #include <ginkgo/core/base/types.hpp> 43 #include <ginkgo/core/base/utils.hpp> 44 #include <ginkgo/core/log/logger.hpp> 148 this->
template log<log::Logger::linop_apply_started>(
this, b, x);
149 this->validate_application_parameters(b, x);
153 this->
template log<log::Logger::linop_apply_completed>(
this, b, x);
162 this->
template log<log::Logger::linop_apply_started>(
this, b, x);
163 this->validate_application_parameters(b, x);
167 this->
template log<log::Logger::linop_apply_completed>(
this, b, x);
184 this->
template log<log::Logger::linop_advanced_apply_started>(
185 this, alpha, b, beta, x);
186 this->validate_application_parameters(alpha, b, beta, x);
192 this->
template log<log::Logger::linop_advanced_apply_completed>(
193 this, alpha, b, beta, x);
203 this->
template log<log::Logger::linop_advanced_apply_started>(
204 this, alpha, b, beta, x);
205 this->validate_application_parameters(alpha, b, beta, x);
211 this->
template log<log::Logger::linop_advanced_apply_completed>(
212 this, alpha, b, beta, x);
230 explicit LinOp(std::shared_ptr<const Executor> exec,
240 void set_size(
const dim<2> &value) noexcept { size_ = value; }
251 virtual void apply_impl(
const LinOp *b,
LinOp *x)
const = 0;
262 virtual void apply_impl(
const LinOp *alpha,
const LinOp *b,
272 void validate_application_parameters(
const LinOp *b,
const LinOp *x)
const 274 GKO_ASSERT_CONFORMANT(
this, b);
275 GKO_ASSERT_EQUAL_ROWS(
this, x);
276 GKO_ASSERT_EQUAL_COLS(b, x);
288 void validate_application_parameters(
const LinOp *alpha,
const LinOp *b,
290 const LinOp *x)
const 292 this->validate_application_parameters(b, x);
293 GKO_ASSERT_EQUAL_DIMENSIONS(alpha,
dim<2>(1, 1));
294 GKO_ASSERT_EQUAL_DIMENSIONS(beta,
dim<2>(1, 1));
361 std::unique_ptr<LinOp> generate(std::shared_ptr<const LinOp> input)
const 363 this->
template log<log::Logger::linop_factory_generate_started>(
366 this->
template log<log::Logger::linop_factory_generate_completed>(
367 this, input.get(), generated.get());
407 virtual std::unique_ptr<LinOp>
transpose()
const = 0;
415 virtual std::unique_ptr<LinOp> conj_transpose()
const = 0;
425 template <
typename ValueType,
typename IndexType>
445 template <
typename ValueType,
typename IndexType>
474 virtual std::shared_ptr<const LinOp> get_preconditioner()
const = 0;
508 template <
typename ConcreteLinOp,
typename PolymorphicBase = LinOp>
518 this->
template log<log::Logger::linop_apply_started>(
this, b, x);
519 this->validate_application_parameters(b, x);
523 this->
template log<log::Logger::linop_apply_completed>(
this, b, x);
529 this->
template log<log::Logger::linop_apply_started>(
this, b, x);
530 this->validate_application_parameters(b, x);
534 this->
template log<log::Logger::linop_apply_completed>(
this, b, x);
541 this->
template log<log::Logger::linop_advanced_apply_started>(
542 this, alpha, b, beta, x);
543 this->validate_application_parameters(alpha, b, beta, x);
549 this->
template log<log::Logger::linop_advanced_apply_completed>(
550 this, alpha, b, beta, x);
557 this->
template log<log::Logger::linop_advanced_apply_started>(
558 this, alpha, b, beta, x);
559 this->validate_application_parameters(alpha, b, beta, x);
565 this->
template log<log::Logger::linop_advanced_apply_completed>(
566 this, alpha, b, beta, x);
571 GKO_ENABLE_SELF(ConcreteLinOp);
592 template <
typename ConcreteFactory,
typename ConcreteLinOp,
593 typename ParametersType,
typename PolymorphicBase =
LinOpFactory>
611 #define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name) \ 613 class _factory_name; \ 614 struct _parameters_name##_type \ 615 : ::gko::enable_parameters_type<_parameters_name##_type, \ 691 #define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name) \ 693 const _parameters_name##_type &get_##_parameters_name() const \ 695 return _parameters_name##_; \ 698 class _factory_name \ 699 : public ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \ 700 _parameters_name##_type> { \ 701 friend class ::gko::EnablePolymorphicObject<_factory_name, \ 702 ::gko::LinOpFactory>; \ 703 friend class ::gko::enable_parameters_type<_parameters_name##_type, \ 705 using ::gko::EnableDefaultLinOpFactory< \ 706 _factory_name, _lin_op, \ 707 _parameters_name##_type>::EnableDefaultLinOpFactory; \ 709 friend ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \ 710 _parameters_name##_type>; \ 714 _parameters_name##_type _parameters_name##_; \ 717 static_assert(true, \ 718 "This assert is used to counter the false positive extra " \ 719 "semi-colon warnings") 730 #define GKO_ENABLE_BUILD_METHOD(_factory_name) \ 731 static auto build()->decltype(_factory_name::create()) \ 733 return _factory_name::create(); \ 735 static_assert(true, \ 736 "This assert is used to counter the false positive extra " \ 737 "semi-colon warnings") 751 #define GKO_FACTORY_PARAMETER(_name, ...) \ 752 mutable _name{__VA_ARGS__}; \ 754 template <typename... Args> \ 755 auto with_##_name(Args &&... _value) \ 756 const->const ::gko::xstd::decay_t<decltype(*this)> & \ 758 using type = decltype(this->_name); \ 759 this->_name = type{std::forward<Args>(_value)...}; \ 762 static_assert(true, \ 763 "This assert is used to counter the false positive extra " \ 764 "semi-colon warnings") 770 #define GKO_FACTORY_PARAMETER(_name, ...) \ 771 mutable _name{__VA_ARGS__}; \ 773 template <typename... Args> \ 774 auto with_##_name(Args &&... _value) \ 775 const->const ::gko::xstd::decay_t<decltype(*this)> & 782 #endif // GKO_CORE_BASE_LIN_OP_HPP_ This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:285
const LinOp * apply(const LinOp *b, LinOp *x) const
Applies a linear operator to a vector (or a sequence of vectors).
Definition: lin_op.hpp:160
std::unique_ptr< AbstractProductType > generate(Args &&... args) const
Creates a new product from the given components.
Definition: abstract_factory.hpp:92
void write(StreamType &&os, MatrixType *matrix, layout_type layout=layout_type::array)
Reads a matrix stored in matrix market format from an input stream.
Definition: mtx_io.hpp:134
A LinOpFactory represents a higher order mapping which transforms one linear operator into another...
Definition: lin_op.hpp:356
const LinOp * apply(const LinOp *alpha, const LinOp *b, const LinOp *beta, LinOp *x) const
Performs the operation x = alpha * op(b) + beta * x.
Definition: lin_op.hpp:200
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:148
Definition: lin_op.hpp:134
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:509
std::unique_ptr< MatrixType > read(StreamType &&is, MatrixArgs &&... args)
Reads a matrix stored in matrix market format from an input stream.
Definition: mtx_io.hpp:113
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:221
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition: abstract_factory.hpp:70
A LinOp implementing this interface can be preconditioned.
Definition: lin_op.hpp:465
LinOp * apply(const LinOp *b, LinOp *x)
Applies a linear operator to a vector (or a sequence of vectors).
Definition: lin_op.hpp:146
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:201
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:446
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:398
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:102
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition: lin_op.hpp:426
constexpr dim< 2, DimensionType > transpose(const dim< 2, DimensionType > &dimensions) noexcept
Returns a dim<2> object with its dimensions swapped.
Definition: dim.hpp:234
temporary_clone< T > make_temporary_clone(std::shared_ptr< const Executor > exec, T *ptr)
Creates a temporary_clone.
Definition: utils.hpp:474
LinOp * apply(const LinOp *alpha, const LinOp *b, const LinOp *beta, LinOp *x)
Performs the operation x = alpha * op(b) + beta * x.
Definition: lin_op.hpp:181