vnl_sparse_matrix_linear_system.cxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_sparse_matrix_linear_system.cxx
2 
3 #include <cassert>
5 #include <vnl/vnl_copy.h>
6 
7 template <>
9 {
10  b = b_;
11 }
12 
13 template <>
15 {
16  A_.pre_mult(b,x);
17 }
18 
19 template <>
21 {
22  vnl_copy(b_, b);
23 }
24 
25 template <>
27 {
28  static vnl_vector<float> x_float;
29  static vnl_vector<float> b_float;
30 
31  if (x_float.size() != x.size()) x_float = vnl_vector<float> (x.size());
32  if (b_float.size() != b.size()) b_float = vnl_vector<float> (b.size());
33 
34  vnl_copy(b, b_float);
35  A_.pre_mult(b_float,x_float);
36  vnl_copy(x_float, x);
37 }
38 
39 template <>
41 {
42  A_.mult(x,b);
43 }
44 
45 
46 template <>
48 {
49  static vnl_vector<float> x_float;
50  static vnl_vector<float> b_float;
51 
52  if (x_float.size() != x.size()) x_float = vnl_vector<float> (x.size());
53  if (b_float.size() != b.size()) b_float = vnl_vector<float> (b.size());
54 
55  vnl_copy(x, x_float);
56  A_.mult(x_float,b_float);
57  vnl_copy(b_float, b);
58 }
59 
60 
61 template<class T>
63 {
64  assert(x.size() == px.size());
65 
66  if (jacobi_precond_.size() == 0) {
67  vnl_vector<T> tmp(get_number_of_unknowns());
68  A_.diag_AtA(tmp);
69  const_cast<vnl_vector<double> &>(jacobi_precond_) = vnl_vector<double> (tmp.size());
70  for (unsigned int i=0; i < tmp.size(); ++i)
71  const_cast<vnl_vector<double> &>(jacobi_precond_)[i] = 1.0 / double(tmp[i]);
72  }
73 
74  px = dot_product(x,jacobi_precond_);
75 }
76 
vnl_sparse_matrix -> vnl_linear_system adaptor
void get_rhs(vnl_vector< double > &b) const override
Implementations of the vnl_linear_system virtuals.
VNL_EXPORT void vnl_copy(S const *const src, T *const dst, const unsigned n)
Easy conversion between vectors and matrices templated over different types.
Definition: vnl_copy.cxx:15
void apply_preconditioner(vnl_vector< double > const &x, vnl_vector< double > &px) const override
Implementations of the vnl_linear_system virtuals.
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
Easy conversion between vectors and matrices templated over different types.
T dot_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_sparse_matrix -> vnl_linear_system adaptor.
void transpose_multiply(vnl_vector< double > const &b, vnl_vector< double > &x) const override
Implementations of the vnl_linear_system virtuals.
void multiply(vnl_vector< double > const &x, vnl_vector< double > &b) const override
Implementations of the vnl_linear_system virtuals.