xmatrix1.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xmatrix0.h"
4 #include <type_traits>
5 
6 namespace nmx::gsl::mat {
7 
11 template<class T>
12 class IMCalc : public IGslContainer<T, gsl_matrix, 2>
13 {
14  // benutze Elementfunktionen der Basisklasse
16 
17 protected:
25  template<class X, class FN>
26  inline T &apply_fn(const X &v, FN fn) {
27  if constexpr (std::is_same_v<X, double>) {
28  // v ist eine Zahl
29  fn(gsl(), v);
30  } else {
31  // v ist ein Vektor oder eine View
32  fn(gsl(), v.gsl());
33  }
34  // Referenz auf das aufrufende Objekt als Instanz vom Typ T
35  // (downcast)
36  return static_cast<T &>(*this);
37  }
38 
39 public:
45  inline T &operator+=(const T &v) { //
46  return apply_fn(v, gsl_matrix_add);
47  }
48  inline T &operator-=(const T &v) { //
49  return apply_fn(v, gsl_matrix_sub);
50  }
51  inline T &operator*=(const T &v) { //
52  return apply_fn(v, gsl_matrix_mul_elements);
53  }
54  inline T &operator/=(const T &v) { //
55  return apply_fn(v, gsl_matrix_div_elements);
56  }
57 
63  inline T &operator+=(double x) { //
64  return apply_fn(x, gsl_matrix_add_constant);
65  }
66  inline T &operator-=(double x) { //
67  return apply_fn(-x, gsl_matrix_add_constant);
68  }
69  inline T &operator*=(double x) { //
70  return apply_fn(x, gsl_matrix_scale);
71  }
72 
79  inline friend T operator+(const T &m1, const T &m2) {
80  T m{ m1 };
81  m += m2;
82  return m;
83  }
84 
91  inline friend T operator-(const T &m1, const T &m2) {
92  T m{ m1 };
93  m -= m2;
94  return m;
95  }
96 }; //IMCalc
97 
98 } // namespace nmx::gsl::mat
T & operator+=(double x)
operator +=,-=,*=
Definition: xmatrix1.h:63
T & operator+=(const T &v)
operator +=,-=,*=,/+
Definition: xmatrix1.h:45
T & apply_fn(const X &v, FN fn)
apply_fn Hilfsfunktion
Definition: xmatrix1.h:26
T & operator-=(double x)
Definition: xmatrix1.h:66
T & operator*=(const T &v)
Definition: xmatrix1.h:51
T & operator*=(double x)
Definition: xmatrix1.h:69
The IMCalc class kombinierte Rechenoperationen und Zuweisungen.
Definition: xmatrix1.h:12
friend T operator-(const T &m1, const T &m2)
operator - subtrahiere zwei Matrizen
Definition: xmatrix1.h:91
friend T operator+(const T &m1, const T &m2)
operator + addiere zwei Matrizen
Definition: xmatrix1.h:79
T & operator-=(const T &v)
Definition: xmatrix1.h:48
T & operator/=(const T &v)
Definition: xmatrix1.h:54
const gsl_matrix * gsl() const
ermöglicht direkten Zugriff auf gsl-Funktionen
Definition: xvector0.h:18
The IGslContainer struct Basisklasse für gsl-Vektoren und Matrizen.
Definition: xvector0.h:13