 |
Ginkgo
Generated from pipelines/2457497073 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
|
5 #ifndef GKO_PUBLIC_CORE_BASE_LIN_OP_HPP_
6 #define GKO_PUBLIC_CORE_BASE_LIN_OP_HPP_
10 #include <type_traits>
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>
30 template <
typename ValueType>
129 this->
template log<log::Logger::linop_apply_started>(
this, b.
get(),
131 this->validate_application_parameters(b.
get(), x.
get());
135 this->
template log<log::Logger::linop_apply_completed>(
this, b.
get(),
151 this->
template log<log::Logger::linop_advanced_apply_started>(
153 this->validate_application_parameters(alpha.
get(), b.
get(), beta.
get(),
160 this->
template log<log::Logger::linop_advanced_apply_completed>(
190 if (
this != &other) {
192 this->set_size(other.get_size());
207 size_{std::exchange(other.size_,
dim<2>{})}
217 explicit LinOp(std::shared_ptr<const Executor> exec,
218 const dim<2>& size = dim<2>{})
219 : EnableAbstractPolymorphicObject<LinOp>(exec), size_{size}
227 void set_size(
const dim<2>& value) noexcept { size_ = value; }
238 virtual void apply_impl(
const LinOp* b,
LinOp* x)
const = 0;
249 virtual void apply_impl(
const LinOp* alpha,
const LinOp* b,
259 void validate_application_parameters(
const LinOp* b,
const LinOp* x)
const
261 GKO_ASSERT_CONFORMANT(
this, b);
262 GKO_ASSERT_EQUAL_ROWS(
this, x);
263 GKO_ASSERT_EQUAL_COLS(b, x);
275 void validate_application_parameters(
const LinOp* alpha,
const LinOp* b,
277 const LinOp* x)
const
279 this->validate_application_parameters(b, x);
280 GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
281 GKO_ASSERT_EQUAL_DIMENSIONS(beta, dim<2>(1, 1));
348 std::unique_ptr<LinOp> generate(std::shared_ptr<const LinOp> input)
const
350 this->
template log<log::Logger::linop_factory_generate_started>(
352 const auto exec = this->get_executor();
353 std::unique_ptr<LinOp> generated;
354 if (input->get_executor() == exec) {
360 this->
template log<log::Logger::linop_factory_generate_completed>(
361 this, input.get(), generated.get());
401 virtual std::unique_ptr<LinOp>
transpose()
const = 0;
409 virtual std::unique_ptr<LinOp> conj_transpose()
const = 0;
442 template <
typename IndexType>
464 return as<Permutable>(this->row_permute(permutation_indices))
465 ->column_permute(permutation_indices);
485 return as<Permutable>(this->inverse_row_permute(permutation_indices))
486 ->inverse_column_permute(permutation_indices);
502 virtual std::unique_ptr<LinOp> row_permute(
519 virtual std::unique_ptr<LinOp> column_permute(
535 virtual std::unique_ptr<LinOp> inverse_row_permute(
552 virtual std::unique_ptr<LinOp> inverse_column_permute(
563 template <
typename ValueType,
typename IndexType>
566 using value_type = ValueType;
567 using index_type = IndexType;
606 this->
read(data.copy_to_host());
618 template <
typename ValueType,
typename IndexType>
621 using value_type = ValueType;
622 using index_type = IndexType;
652 return preconditioner_;
663 preconditioner_ = new_precond;
667 std::shared_ptr<const LinOp> preconditioner_{};
690 virtual std::unique_ptr<LinOp> extract_diagonal_linop()
const = 0;
701 template <
typename ValueType>
704 using value_type = ValueType;
708 std::unique_ptr<LinOp> extract_diagonal_linop()
const override;
715 virtual std::unique_ptr<matrix::Diagonal<ValueType>> extract_diagonal()
752 template <
typename AbsoluteLinOp>
755 using absolute_type = AbsoluteLinOp;
789 GKO_ASSERT_IS_SCALAR(a);
790 GKO_ASSERT_IS_SCALAR(b);
793 add_scaled_identity_impl(ae.get(), be.get());
797 virtual void add_scaled_identity_impl(
const LinOp* a,
const LinOp* b) = 0;
835 template <
typename ConcreteLinOp,
typename PolymorphicBase = LinOp>
842 using PolymorphicBase::apply;
845 GKO_ENABLE_SELF(ConcreteLinOp);
866 template <
typename ConcreteFactory,
typename ConcreteLinOp,
867 typename ParametersType,
typename PolymorphicBase =
LinOpFactory>
948 #define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name) \
950 const _parameters_name##_type& get_##_parameters_name() const \
952 return _parameters_name##_; \
955 class _factory_name \
956 : public ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
957 _parameters_name##_type> { \
958 friend class ::gko::EnablePolymorphicObject<_factory_name, \
959 ::gko::LinOpFactory>; \
960 friend class ::gko::enable_parameters_type<_parameters_name##_type, \
962 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
963 : ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
964 _parameters_name##_type>( \
967 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec, \
968 const _parameters_name##_type& parameters) \
969 : ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
970 _parameters_name##_type>( \
971 std::move(exec), parameters) \
974 friend ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
975 _parameters_name##_type>; \
979 _parameters_name##_type _parameters_name##_; \
982 static_assert(true, \
983 "This assert is used to counter the false positive extra " \
984 "semi-colon warnings")
990 #endif // GKO_PUBLIC_CORE_BASE_LIN_OP_HPP_
host_type copy_to_host() const
Copies the device_matrix_data entries to the host to return a regular matrix_data object with the sam...
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:160
void add_scaled_identity(ptr_param< const LinOp > const a, ptr_param< const LinOp > const b)
Scales this and adds another scalar times the identity to it.
Definition: lin_op.hpp:786
Definition: lin_op.hpp:117
A LinOp implementing this interface can be preconditioned.
Definition: lin_op.hpp:641
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition: abstract_factory.hpp:45
LinOp(LinOp &&other)
Move-constructs a LinOp.
Definition: lin_op.hpp:205
std::unique_ptr< abstract_product_type > generate(Args &&... args) const
Creates a new product from the given components.
Definition: abstract_factory.hpp:67
virtual std::unique_ptr< LinOp > permute(const array< IndexType > *permutation_indices) const
Returns a LinOp representing the symmetric row and column permutation of the Permutable object.
Definition: lin_op.hpp:461
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:354
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:392
The AbsoluteComputable is an interface that allows to get the component wise absolute of a LinOp.
Definition: lin_op.hpp:725
T * get() const
Definition: utils_helper.hpp:75
virtual std::unique_ptr< LinOp > compute_absolute_linop() const =0
Gets the absolute LinOp.
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:124
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition: polymorphic_object.hpp:743
void apply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Applies a linear operator to a vector (or a sequence of vectors).
Definition: lin_op.hpp:127
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition: utils_helper.hpp:173
Linear operators which support permutation should implement the Permutable interface.
Definition: lin_op.hpp:443
LinOp & operator=(LinOp &&other)
Move-assigns a LinOp.
Definition: lin_op.hpp:188
virtual std::shared_ptr< const LinOp > get_preconditioner() const
Returns the preconditioner operator used by the Preconditionable.
Definition: lin_op.hpp:650
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
virtual void read(const device_matrix_data< ValueType, IndexType > &data)
Reads a matrix from a device_matrix_data structure.
Definition: lin_op.hpp:593
void read(const matrix_assembly_data< ValueType, IndexType > &data)
Reads a matrix from a matrix_assembly_data structure.
Definition: lin_op.hpp:583
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
virtual bool apply_uses_initial_guess() const
Returns true if the linear operator uses the data given in x as an initial guess.
Definition: lin_op.hpp:178
virtual std::unique_ptr< LinOp > inverse_permute(const array< IndexType > *permutation_indices) const
Returns a LinOp representing the symmetric inverse row and column permutation of the Permutable objec...
Definition: lin_op.hpp:482
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition: lin_op.hpp:31
matrix_data< ValueType, IndexType > get_ordered_data() const
Definition: matrix_assembly_data.hpp:142
virtual void set_preconditioner(std::shared_ptr< const LinOp > new_precond)
Sets the preconditioner operator used by the Preconditionable.
Definition: lin_op.hpp:661
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:41
void apply(ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< const LinOp > beta, ptr_param< LinOp > x) const
Performs the operation x = alpha * op(b) + beta * x.
Definition: lin_op.hpp:148
virtual void compute_absolute_inplace()=0
Compute absolute inplace on each element.
virtual void read(device_matrix_data< ValueType, IndexType > &&data)
Reads a matrix from a device_matrix_data structure.
Definition: lin_op.hpp:604
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition: lin_op.hpp:564
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
LinOp & operator=(const LinOp &)=default
Copy-assigns a LinOp.
void write(StreamType &&os, MatrixPtrType &&matrix, layout_type layout=detail::mtx_io_traits< std::remove_cv_t< detail::pointee< MatrixPtrType >>>::default_layout)
Writes a matrix into an output stream in matrix market format.
Definition: mtx_io.hpp:299
batch_dim< 2, DimensionType > transpose(const batch_dim< 2, DimensionType > &input)
Returns a batch_dim object with its dimensions swapped for batched operators.
Definition: batch_dim.hpp:119
Adds the operation M <- a I + b M for matrix M, identity operator I and scalars a and b,...
Definition: lin_op.hpp:777
This structure is used as an intermediate type to assemble a sparse matrix.
Definition: matrix_assembly_data.hpp:59
virtual std::unique_ptr< absolute_type > compute_absolute() const =0
Gets the AbsoluteLinOp.
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
The EnableAbsoluteComputation mixin provides the default implementations of compute_absolute_linop an...
Definition: lin_op.hpp:753
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition: lin_op.hpp:343
std::unique_ptr< LinOp > compute_absolute_linop() const override
Gets the absolute LinOp.
Definition: lin_op.hpp:759
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:243
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:169
This type is a device-side equivalent to matrix_data.
Definition: device_matrix_data.hpp:36
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:836
LinOp(const LinOp &)=default
Copy-constructs a LinOp.
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:667