gko::Cloneable#
Cloneable is the interface for objects that can be copied polymorphically.
clone() and clone(exec) copy the object on its own executor or on exec.
copy_from() and move_from() overwrite an existing object, and
create_default() makes an empty object of the same type.
The mixin EnableCloneable<ConcreteType> implements this interface from the
concrete type’s copy and move assignment, and returns the concrete type from
clone() and create_default(). Matrix formats, solver::Nullspace and
preconditioner::NullspaceProjection derive from it. The free function
gko::clone accepts smart and plain pointers to cloneable objects.
auto A = gko::share(gko::read<gko::matrix::Csr<double, int>>(
std::ifstream("A.mtx"), exec));
// A copy on the host, whatever executor A lives on:
auto A_host = gko::clone(exec->get_master(), A);
// A copy on A's own executor, typed as the concrete class:
std::unique_ptr<gko::matrix::Csr<double, int>> A_copy = A->clone();
-
class Cloneable#
Interface for objects that can be cloned.
Note
The derived types must also derive from PolymorphicObject.
Subclassed by
gko::EnableCloneable< Matrix< default_precision, int32, int64 > >
gko::EnableCloneable< ScaledPermutation< default_precision, int32 > >
gko::EnableCloneable< SparsityCsr< default_precision, int32 > >
gko::EnableCloneable< GaussSeidel< default_precision, int32 > >
gko::EnableCloneable< NullspaceProjection< default_precision > >
-
template<typename ConcreteType>
class EnableCloneable # Inherits from
public gko::ConvertibleTo<ConcreteType>
public gko::Cloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that have implemented copy and move constructors.
Note
The ConcreteType must have public constructors, or this class as a friend class.
- Template Parameters:
ConcreteType – the concrete type from which the copy_from is being enabled [CRTP parameter]
Subclassed by
gko::experimental::distributed::Partition< LocalIndexType, GlobalIndexType >
gko::experimental::distributed::Vector< to_complex< value_type > >
gko::experimental::distributed::Vector< previous_precision< ValueType > >
gko::experimental::distributed::Vector< previous_precision< ValueType, 2 > >
gko::experimental::distributed::Vector< previous_precision< ValueType, 3 > >
Public Functions
- std::shared_ptr<const Executor> exec,
Creates a clone of the object.
This is the polymorphic equivalent of the executor copy constructor
decltype(*this)(exec, this).- Parameters:
exec – the executor where the clone will be created
- Returns:
A clone of the LinOp.
-
inline std::unique_ptr<ConcreteType> clone() const#
Creates a clone of the object.
This is a shorthand for clone(std::shared_ptr<const Executor>) that uses the executor of this object to construct the new object.
- Returns:
A clone of the LinOp.
-
inline virtual void convert_to(result_type *result) const override#
Converts the implementer to an object of type result_type.
- Parameters:
result – the object used to store the result of the conversion
-
inline virtual void move_to(result_type *result) override#
Converts the implementer to an object of type result_type by moving data from this object.
This method is used when the implementer is a temporary object, and move semantics can be used.
Note
ConvertibleTo::move_to can be implemented by simply calling ConvertibleTo::convert_to. However, this operation can often be optimized by exploiting the fact that implementer’s data can be moved to the result.
- Parameters:
result – the object used to emplace the result of the conversion
See also