sparse_solver.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_sparse_solver_hh
#define mia_core_sparse_solver_hh
#include <mia/core/product_base.hh>
#include <mia/core/traits.hh>
NS_MIA_BEGIN
template <typename F>
class TSparseSolver : public CProductBase
{
public:
typedef F Field;
typedef F plugin_data;
typedef typename dim_traits<F>::dimsize_type dimsize_type;
typedef TSparseSolver<F> plugin_type;
static const char *const type_descr;
typedef typename Field::iterator field_iterator;
typedef typename Field::const_iterator const_field_iterator;
typedef typename Field::value_type value_type;
class A_mult_x: public CProductBase
{
public:
typedef F plugin_data;
typedef A_mult_x plugin_type;
static const char *const type_descr;
A_mult_x(): m_size(dimsize_type()) {};
A_mult_x(const dimsize_type& size): m_size(size) {};
virtual ~A_mult_x() {};
virtual value_type operator () (const_field_iterator ix) const = 0;
virtual int get_boundary_size() const = 0;
dimsize_type get_size() const
{
return m_size;
}
private:
dimsize_type m_size;
};
virtual ~TSparseSolver() {};
virtual int solve(const Field& rhs, Field& x, const A_mult_x& mult) const = 0;
};
template <typename F>
const char *const TSparseSolver<F>::type_descr = "sparsesolver";
template <typename F>
const char *const TSparseSolver<F>::A_mult_x::type_descr = "amultx";
template <typename F>
struct multiply {
static void apply(F& MIA_PARAM_UNUSED(result),
const typename TSparseSolver<F>::A_mult_x& MIA_PARAM_UNUSED(A), const F& MIA_PARAM_UNUSED(x))
{
static_assert(sizeof(F) == 0, "This operation needs to be specialized");
}
};
template <typename F>
F operator * (const typename TSparseSolver<F>::A_mult_x& A, const F& x)
{
F result(x.get_size());
multiply<F>::apply(result, A, x);
return result;
}
NS_MIA_END
#endif
CProductBase
The base class for all plug-in created object.
Definition product_base.hh:41
TSparseSolver::A_mult_x
A class that implements the multiplication of a cell of the matrix A with the field x.
Definition sparse_solver.hh:78
TSparseSolver::A_mult_x::A_mult_x
A_mult_x(const dimsize_type &size)
Definition sparse_solver.hh:93
TSparseSolver::A_mult_x::~A_mult_x
virtual ~A_mult_x()
Definition sparse_solver.hh:96
TSparseSolver::A_mult_x::get_boundary_size
virtual int get_boundary_size() const =0
TSparseSolver::A_mult_x::operator()
virtual value_type operator()(const_field_iterator ix) const =0
TSparseSolver::A_mult_x::get_size
dimsize_type get_size() const
Definition sparse_solver.hh:118
TSparseSolver::A_mult_x::type_descr
static const char *const type_descr
plugin type component of plugin path descriptor
Definition sparse_solver.hh:87
TSparseSolver::A_mult_x::plugin_data
F plugin_data
helper typedef for the plug-in handling
Definition sparse_solver.hh:81
TSparseSolver::A_mult_x::plugin_type
A_mult_x plugin_type
helper typedef for the plug-in handling
Definition sparse_solver.hh:84
TSparseSolver::A_mult_x::A_mult_x
A_mult_x()
Definition sparse_solver.hh:90
TSparseSolver
solver for sparse systems of equations
Definition sparse_solver.hh:44
TSparseSolver< C2DFImage >::type_descr
static const char *const type_descr
Definition sparse_solver.hh:59
TSparseSolver::~TSparseSolver
virtual ~TSparseSolver()
Definition sparse_solver.hh:127
TSparseSolver::dimsize_type
dim_traits< F >::dimsize_type dimsize_type
typeef of the dimension type
Definition sparse_solver.hh:53
TSparseSolver::plugin_data
F plugin_data
helper typedef for the plug-in handling
Definition sparse_solver.hh:50
TSparseSolver::value_type
Field::value_type value_type
type of the values stored in Field
Definition sparse_solver.hh:68
TSparseSolver::solve
virtual int solve(const Field &rhs, Field &x, const A_mult_x &mult) const =0
TSparseSolver::const_field_iterator
Field::const_iterator const_field_iterator
type of the field random access const_iterator
Definition sparse_solver.hh:65
TSparseSolver::plugin_type
TSparseSolver< F > plugin_type
helper for the plug-in handling
Definition sparse_solver.hh:56
TSparseSolver::field_iterator
Field::iterator field_iterator
type of the field random access iterator
Definition sparse_solver.hh:62
TSparseSolver::Field
F Field
typedef for the field the solver works on
Definition sparse_solver.hh:47
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
product_base.hh
operator*
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition sparse_solver.hh:182
dim_traits::dimsize_type
T::dimsize_type dimsize_type
the trait
Definition traits.hh:38
multiply
Class template to implement a matrix - field multiplication.
Definition sparse_solver.hh:158
multiply::apply
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition sparse_solver.hh:165
traits.hh