Medusa  1.1
Coordinate Free Mehless Method implementation
ImplicitVectorOperators.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_OPERATORS_IMPLICITVECTOROPERATORS_HPP_
2 #define MEDUSA_BITS_OPERATORS_IMPLICITVECTOROPERATORS_HPP_
3 
9 #include "ImplicitOperators.hpp"
11 #include "ShapeStorage_fwd.hpp"
12 
13 namespace mm {
14 
15 template <class shape_storage_type, class matrix_type, class rhs_type>
17  const shape_storage_t& ss, matrix_t& M, rhs_t& rhs, int row_offset, int col_offset) :
18  ss(&ss), M(&M), rhs(&rhs), row_offset(row_offset), col_offset(col_offset) {
19  assert_msg(0 <= row_offset, "Row offset cannot be negative, got %d.", row_offset);
20  assert_msg(0 <= col_offset, "Col offset cannot be negative, got %d.", col_offset);
21  assert_msg(M.rows() >= dim*ss.size() + row_offset,
22  "Matrix does not have enough rows, expected at least %d = %d + %d, got %d.",
23  dim*ss.size()+row_offset, row_offset, dim*ss.size(), M.rows());
24  assert_msg(M.cols() >= dim*ss.size(),
25  "Matrix does not have enough columns, expected at least %d = %d + %d, got %d.",
26  dim*ss.size()+col_offset, col_offset, dim*ss.size(), M.cols());
27  assert_msg(rhs.size() >= dim*ss.size() + row_offset,
28  "RHS vector does not have enough rows, expected at least %d = %d + %d, got %d.",
29  dim*ss.size()+row_offset, row_offset, dim*ss.size(), M.rows());
30  #ifndef NDEBUG
31  // Warning if the matrix or rhs is not zero initialized.
32  if (M.squaredNorm() > 1e-10) {
33  std::cerr << "Warning: matrix in implicit operators not initialized to zero!" << std::endl;
34  }
35  if (rhs.squaredNorm() > 1e-10) {
36  std::cerr << "Warning: rhs in implicit operators not initialized to zero!" << std::endl;
37  }
38  #endif
39 }
40 
42 template <typename S, typename M, typename R>
43 std::ostream& operator<<(std::ostream& os, const ImplicitVectorOperators<S, M, R>& op) {
44  os << "Implicit vector operators ";
45  os << ((op.hasShapes()) ? "with" : "without") << " linked storage ";
46  if (!op.hasShapes()) {
47  os << "without linked storage";
48  } else {
49  os << "over storage: " << *op.ss;
50  }
51  os << " with " << ((op.hasMatrix()) ? "defined" : "undefined") << " problem matrix";
52  os << " and with " << ((op.hasRhs()) ? "defined" : "undefined") << " problem rhs.";
53  return os;
54 }
55 
57 template <typename Derived, typename vec_t, typename OpFamilies>
58 template <typename M, typename R>
59 ImplicitVectorOperators<Derived, M, R>
61  return {*static_cast<const Derived*>(this), matrix, rhs};
62 }
64 } // namespace mm
65 
66 #endif // MEDUSA_BITS_OPERATORS_IMPLICITVECTOROPERATORS_HPP_
mm::ImplicitVectorOperators::hasMatrix
bool hasMatrix() const
Returns true if operators have a non-null pointer to problem matrix.
Definition: ImplicitVectorOperators_fwd.hpp:363
mm::ImplicitVectorOperators::rhs_t
rhs_type rhs_t
Right hand side type.
Definition: ImplicitVectorOperators_fwd.hpp:48
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::ImplicitVectorOperators::hasRhs
bool hasRhs() const
Returns true if operators have a non-null pointer to problem right hand side.
Definition: ImplicitVectorOperators_fwd.hpp:365
mm::ImplicitVectorOperators::rhs
rhs_t * rhs
Pointer to right hand side.
Definition: ImplicitVectorOperators_fwd.hpp:63
mm::ImplicitVectorOperators::matrix_t
matrix_type matrix_t
Matrix type.
Definition: ImplicitVectorOperators_fwd.hpp:47
ShapeStorage_fwd.hpp
mm::operator<<
std::ostream & operator<<(std::ostream &os, const Gaussian< S > &b)
Output basic information about given Gaussian RBF.
Definition: Gaussian.hpp:37
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::ImplicitVectorOperators::M
matrix_t * M
Pointer to problem matrix.
Definition: ImplicitVectorOperators_fwd.hpp:62
mm::ImplicitVectorOperators::dim
@ dim
Dimensionality of the domain.
Definition: ImplicitVectorOperators_fwd.hpp:55
mm::ImplicitVectorOperators::hasShapes
bool hasShapes() const
Returns true if operators have a non-null pointer to storage and false otherwise.
Definition: ImplicitVectorOperators_fwd.hpp:361
mm::ImplicitVectorOperators::ss
const shape_storage_t * ss
Shape storage, but name is shortened for readability.
Definition: ImplicitVectorOperators_fwd.hpp:61
mm::ImplicitVectorOperators::col_offset
int col_offset
Column offset to be used when accessing matrix coefficients.
Definition: ImplicitVectorOperators_fwd.hpp:65
mm::ShapeStorage::implicitVectorOperators
ImplicitVectorOperators< Derived, M, R > implicitVectorOperators(M &matrix, R &rhs) const
Construct implicit vector operators over this storage.
mm::ImplicitVectorOperators::shape_storage_t
shape_storage_type shape_storage_t
Type of shape storage.
Definition: ImplicitVectorOperators_fwd.hpp:46
ImplicitVectorOperators_fwd.hpp
mm::ImplicitVectorOperators::ImplicitVectorOperators
ImplicitVectorOperators()
Default constructor sets offset to 0 and pointers to nullptr.
Definition: ImplicitVectorOperators_fwd.hpp:319
mm::ImplicitVectorOperators
This class represents implicit vector operators that fill given matrix M and right hand side rhs with...
Definition: ImplicitVectorOperators_fwd.hpp:44
mm::ImplicitVectorOperators::row_offset
int row_offset
Row offset to be used when accessing matrix or rhs coefficients.
Definition: ImplicitVectorOperators_fwd.hpp:64
ImplicitOperators.hpp