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
26#include <mia/core/traits.hh>
27
29
42template <typename F>
44{
45public:
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
140template <typename F>
141const char *const TSparseSolver<F>::type_descr = "sparsesolver";
142
143
144template <typename F>
145const char *const TSparseSolver<F>::A_mult_x::type_descr = "amultx";
146
147
157template <typename F>
158struct 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
181template <typename F>
182F 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
The base class for all plug-in created object.
Definition: product_base.hh:41
A class that implements the multiplication of a cell of the matrix A with the field x.
A_mult_x(const dimsize_type &size)
virtual int get_boundary_size() const =0
virtual value_type operator()(const_field_iterator ix) const =0
dimsize_type get_size() const
static const char *const type_descr
plugin type component of plugin path descriptor
F plugin_data
helper typedef for the plug-in handling
A_mult_x plugin_type
helper typedef for the plug-in handling
solver for sparse systems of equations
virtual ~TSparseSolver()
dim_traits< F >::dimsize_type dimsize_type
typeef of the dimension type
F plugin_data
helper typedef for the plug-in handling
Field::value_type value_type
type of the values stored in Field
virtual int solve(const Field &rhs, Field &x, const A_mult_x &mult) const =0
Field::const_iterator const_field_iterator
type of the field random access const_iterator
static const char *const type_descr
plugin type component of plugin path descriptor
TSparseSolver< F > plugin_type
helper for the plug-in handling
Field::iterator field_iterator
type of the field random access iterator
F Field
typedef for the field the solver works on
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
A trait to obtaine information about of dimensions of a class.
Definition: traits.hh:36
Class template to implement a matrix - field multiplication.
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)