Skip to content

Commit

Permalink
Use updated deferred factory macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikvn committed Nov 5, 2023
1 parent 2578294 commit b8babda
Showing 1 changed file with 11 additions and 45 deletions.
56 changes: 11 additions & 45 deletions include/ginkgo/core/solver/batch_solver_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,13 @@ class BatchSolver {
* excluding the parameters available in iterative_solver_factory_parameters.
* @see GKO_CREATE_FACTORY_PARAMETERS
*/
struct preconditioned_iterative_solver_factory_parameters {
/**
* The preconditioner to be used by the iterative solver. By default, no
* preconditioner is used.
*/
std::shared_ptr<const BatchLinOpFactory> preconditioner{nullptr};

/**
* Already generated preconditioner. If one is provided, the factory
* `preconditioner` will be ignored.
*/
std::shared_ptr<const BatchLinOp> generated_preconditioner{nullptr};
};
struct preconditioned_iterative_solver_factory_parameters {};


template <typename Parameters, typename Factory>
struct enable_preconditioned_iterative_solver_factory_parameters
: enable_parameters_type<Parameters, Factory>,
preconditioned_iterative_solver_factory_parameters {
: enable_parameters_type<Parameters, Factory> {
using parameters_type = Parameters;
/**
* Default maximum number iterations allowed.
*
Expand All @@ -225,40 +213,18 @@ struct enable_preconditioned_iterative_solver_factory_parameters
tolerance_type, ::gko::batch::stop::tolerance_type::absolute);

/**
* Provides a preconditioner factory to be used by the iterative solver in a
* fluent interface.
* @see preconditioned_iterative_solver_factory_parameters::preconditioner
* The preconditioner to be used by the iterative solver. By default, no
* preconditioner is used.
*/
Parameters& with_preconditioner(
deferred_factory_parameter<BatchLinOpFactory> preconditioner)
{
this->preconditioner_generator = std::move(preconditioner);
this->deferred_factories["preconditioner"] = [](const auto& exec,
auto& params) {
if (!params.preconditioner_generator.is_empty()) {
params.preconditioner =
params.preconditioner_generator.on(exec);
}
};
return *self();
}
std::shared_ptr<const BatchLinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
preconditioner);

/**
* Provides a concrete preconditioner to be used by the iterative solver in
* a fluent interface.
* @see preconditioned_iterative_solver_factory_parameters::preconditioner
* Already generated preconditioner. If one is provided, the factory
* `preconditioner` will be ignored.
*/
Parameters& with_generated_preconditioner(
std::shared_ptr<const BatchLinOp> generated_preconditioner)
{
this->generated_preconditioner = std::move(generated_preconditioner);
return *self();
}

private:
GKO_ENABLE_SELF(Parameters);

deferred_factory_parameter<BatchLinOpFactory> preconditioner_generator;
std::shared_ptr<const BatchLinOp> GKO_FACTORY_PARAMETER_SCALAR(
generated_preconditioner, nullptr);
};


Expand Down

0 comments on commit b8babda

Please sign in to comment.