My Project
sparse_solver.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_sparse_solver_hh
22 #define mia_core_sparse_solver_hh
23 
24 
25 #include <mia/core/product_base.hh>
26 #include <mia/core/traits.hh>
27 
29 
42 template <typename F>
44 {
45 public:
47  typedef F Field;
48 
50  typedef F plugin_data;
51 
54 
57 
59  static const char *const type_descr;
60 
62  typedef typename Field::iterator field_iterator;
63 
65  typedef typename Field::const_iterator const_field_iterator;
66 
68  typedef typename Field::value_type value_type;
69 
77  class A_mult_x: public CProductBase
78  {
79  public:
81  typedef F plugin_data;
82 
85 
87  static const char *const type_descr;
88 
90  A_mult_x(): m_size(dimsize_type()) {};
91 
93  A_mult_x(const dimsize_type& size): m_size(size) {};
94 
96  virtual ~A_mult_x() {};
97 
108 
112  virtual int get_boundary_size() const = 0;
113 
119  {
120  return m_size;
121  }
122  private:
123  dimsize_type m_size;
124 
125  };
126 
127  virtual ~TSparseSolver() {};
128 
129 
137  virtual int solve(const Field& rhs, Field& x, const A_mult_x& mult) const = 0;
138 };
139 
140 template <typename F>
141 const char *const TSparseSolver<F>::type_descr = "sparsesolver";
142 
143 
144 template <typename F>
145 const char *const TSparseSolver<F>::A_mult_x::type_descr = "amultx";
146 
147 
157 template <typename F>
158 struct multiply {
165  static void apply(F& MIA_PARAM_UNUSED(result),
166  const typename TSparseSolver<F>::A_mult_x& MIA_PARAM_UNUSED(A), const F& MIA_PARAM_UNUSED(x))
167  {
168  static_assert(sizeof(F) == 0, "This operation needs to be specialized");
169  }
170 };
171 
172 
181 template <typename F>
182 F operator * (const typename TSparseSolver<F>::A_mult_x& A, const F& x)
183 {
184  F result(x.get_size());
185  multiply<F>::apply(result, A, x);
186  return result;
187 }
188 
189 
191 
192 #endif
dim_traits
A trait to obtaine information about of dimensions of a class.
Definition: traits.hh:36
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
operator*
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition: sparse_solver.hh:182
multiply::apply
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition: sparse_solver.hh:165
TSparseSolver::field_iterator
Field::iterator field_iterator
type of the field random access iterator
Definition: sparse_solver.hh:62
TSparseSolver::A_mult_x::operator()
virtual value_type operator()(const_field_iterator ix) const =0
TSparseSolver::A_mult_x::plugin_type
A_mult_x plugin_type
helper typedef for the plug-in handling
Definition: sparse_solver.hh:84
TSparseSolver::Field
F Field
typedef for the field the solver works on
Definition: sparse_solver.hh:47
TSparseSolver::type_descr
static const char *const type_descr
plugin type component of plugin path descriptor
Definition: sparse_solver.hh:59
multiply
Class template to implement a matrix - field multiplication.
Definition: sparse_solver.hh:158
TSparseSolver::A_mult_x::A_mult_x
A_mult_x()
Definition: sparse_solver.hh:90
traits.hh
CProductBase
The base class for all plug-in created object.
Definition: product_base.hh:41
TSparseSolver::A_mult_x::get_size
dimsize_type get_size() const
Definition: sparse_solver.hh:118
TSparseSolver::A_mult_x::plugin_data
F plugin_data
helper typedef for the plug-in handling
Definition: sparse_solver.hh:81
TSparseSolver::plugin_type
TSparseSolver< F > plugin_type
helper for the plug-in handling
Definition: sparse_solver.hh:56
TSparseSolver::dimsize_type
dim_traits< F >::dimsize_type dimsize_type
typeef of the dimension type
Definition: sparse_solver.hh:53
TSparseSolver::A_mult_x::~A_mult_x
virtual ~A_mult_x()
Definition: sparse_solver.hh:96
TSparseSolver::A_mult_x::type_descr
static const char *const type_descr
plugin type component of plugin path descriptor
Definition: sparse_solver.hh:87
product_base.hh
TSparseSolver::value_type
Field::value_type value_type
type of the values stored in Field
Definition: sparse_solver.hh:68
TSparseSolver::A_mult_x::A_mult_x
A_mult_x(const dimsize_type &size)
Definition: sparse_solver.hh:93
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::const_field_iterator
Field::const_iterator const_field_iterator
type of the field random access const_iterator
Definition: sparse_solver.hh:65
TSparseSolver::solve
virtual int solve(const Field &rhs, Field &x, const A_mult_x &mult) const =0
TSparseSolver::plugin_data
F plugin_data
helper typedef for the plug-in handling
Definition: sparse_solver.hh:50
TSparseSolver::~TSparseSolver
virtual ~TSparseSolver()
Definition: sparse_solver.hh:127
TSparseSolver::A_mult_x::get_boundary_size
virtual int get_boundary_size() const =0
TSparseSolver
solver for sparse systems of equations
Definition: sparse_solver.hh:44