diff --git a/include/ginkgo/core/reorder/rcm.hpp b/include/ginkgo/core/reorder/rcm.hpp index 0d002bd4f89..e1ab30ba726 100644 --- a/include/ginkgo/core/reorder/rcm.hpp +++ b/include/ginkgo/core/reorder/rcm.hpp @@ -125,10 +125,10 @@ class Rcm : public EnablePolymorphicObject, return inv_permutation_; } - const array& get_permutation_array() const override + /*const array& get_permutation_array() const override { return permutation_array_; - } + }*/ GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) { @@ -211,15 +211,15 @@ class Rcm : public EnablePolymorphicObject, inv_permutation_ = gpu_inv_perm; } } - permutation_array_ = + auto permutation_array = make_array_view(this->get_executor(), permutation_->get_size()[0], permutation_->get_permutation()); + this->set_permutation_array(permutation_array); } private: std::shared_ptr permutation_; std::shared_ptr inv_permutation_; - array permutation_array_; }; diff --git a/include/ginkgo/core/reorder/reordering_base.hpp b/include/ginkgo/core/reorder/reordering_base.hpp index 977b138b3c7..fcba1f242cc 100644 --- a/include/ginkgo/core/reorder/reordering_base.hpp +++ b/include/ginkgo/core/reorder/reordering_base.hpp @@ -65,12 +65,24 @@ class ReorderingBase public: using index_type = IndexType; - virtual const array& get_permutation_array() const = 0; + const array& get_permutation_array() const + { + return permutation_array_; + } protected: explicit ReorderingBase(std::shared_ptr exec) - : EnableAbstractPolymorphicObject(exec) + : EnableAbstractPolymorphicObject(exec), + permutation_array_{exec} {} + + void set_permutation_array(array& permutation_array) + { + permutation_array_ = permutation_array; + } + +private: + array permutation_array_; }; @@ -88,6 +100,37 @@ struct ReorderingBaseArgs { }; +/** + * Declares an Abstract Factory specialized for ReorderingBases + */ +template +using ReorderingBaseFactory = + AbstractFactory, ReorderingBaseArgs>; + + +/** + * This is an alias for the EnableDefaultFactory mixin, which correctly sets the + * template parameters to enable a subclass of ReorderingBaseFactory. + * + * @tparam ConcreteFactory the concrete factory which is being implemented + * [CRTP parmeter] + * @tparam ConcreteReorderingBase the concrete ReorderingBase type which this + * factory produces, needs to have a constructor which takes a const + * ConcreteFactory *, and a const ReorderingBaseArgs * as parameters. + * @tparam ParametersType a subclass of enable_parameters_type template which + * defines all of the parameters of the factory + * @tparam PolymorphicBase parent of ConcreteFactory in the polymorphic + * hierarchy, has to be a subclass of + * ReorderingBaseFactory + */ +template > +using EnableDefaultReorderingBaseFactory = + EnableDefaultFactory; + + /** * This macro will generate a default implementation of a ReorderingBaseFactory * for the ReorderingBase subclass it is defined in. @@ -115,37 +158,27 @@ public: \ } \ \ class _factory_name \ - : public ::gko::EnableDefaultFactory< \ + : public ::gko::reorder::EnableDefaultReorderingBaseFactory< \ _factory_name, _reordering_base, _parameters_name##_type, \ - ::gko::AbstractFactory, \ - ::gko::reorder::ReorderingBaseArgs>> { \ + IndexType> { \ friend class ::gko::EnablePolymorphicObject< \ - _factory_name, \ - ::gko::AbstractFactory<::gko::reorder::ReorderingBase, \ - ::gko::reorder::ReorderingBaseArgs>>; \ + _factory_name, ::gko::reorder::ReorderingBaseFactory>; \ friend class ::gko::enable_parameters_type<_parameters_name##_type, \ _factory_name>; \ explicit _factory_name(std::shared_ptr exec) \ - : ::gko::EnableDefaultFactory< \ + : ::gko::reorder::EnableDefaultReorderingBaseFactory< \ _factory_name, _reordering_base, _parameters_name##_type, \ - ::gko::AbstractFactory< \ - ::gko::reorder::ReorderingBase, \ - ::gko::reorder::ReorderingBaseArgs>>(std::move(exec)) \ + IndexType>(std::move(exec)) \ {} \ explicit _factory_name(std::shared_ptr exec, \ const _parameters_name##_type& parameters) \ - : ::gko::EnableDefaultFactory< \ + : ::gko::reorder::EnableDefaultReorderingBaseFactory< \ _factory_name, _reordering_base, _parameters_name##_type, \ - ::gko::AbstractFactory< \ - ::gko::reorder::ReorderingBase, \ - ::gko::reorder::ReorderingBaseArgs>>(std::move(exec), \ - parameters) \ + IndexType>(std::move(exec), parameters) \ {} \ }; \ - friend ::gko::EnableDefaultFactory< \ - _factory_name, _reordering_base, _parameters_name##_type, \ - ::gko::AbstractFactory<::gko::reorder::ReorderingBase, \ - ::gko::reorder::ReorderingBaseArgs>>; \ + friend ::gko::reorder::EnableDefaultReorderingBaseFactory< \ + _factory_name, _reordering_base, _parameters_name##_type, IndexType>; \ \ private: \ _parameters_name##_type _parameters_name##_; \