xmatrix0.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xvector.h"
4 
5 namespace nmx::gsl::mat {
6 
13 template<class T>
14 class IMBase : public IGslContainer<T, gsl_matrix, 1>
15 {
16  //verwende die Funktionen der Basisklasse
18 
19 public:
24  inline size_t rows() const { return gsl()->size1; }
25 
30  inline size_t columns() const { return gsl()->size2; }
31 
36  inline bool empty() const { //
37  return gsl() == nullptr ? true : rows() == 0 && columns() == 0;
38  }
39 
46  inline double operator()(size_t idx, size_t jdx) const {
47  return gsl_matrix_get(gsl(), idx, jdx);
48  }
49 
56  inline double &operator()(size_t i, size_t j) {
57  return *gsl_matrix_ptr(gsl(), i, j); //
58  }
59 
65  inline void save(std::ostream &os, Format fmt = Output::array()) const {
66  for (size_t _idx = 0; _idx < rows(); _idx++) {
67  os << gsl_matrix_get(gsl(), _idx, 0);
68  for (size_t _jdx = 1; _jdx < columns(); _jdx++) {
69  os << fmt.sep() << gsl_matrix_get(gsl(), _idx, _jdx);
70  }
71  os << fmt.lend();
72  }
73  }
74 
82  inline friend std::ostream &operator<<(std::ostream &os, const T &p) {
83  p.save(os);
84  return os;
85  }
86 
93  template<class FN>
94  inline T &transform(FN fn) {
95  for (size_t idx = 0; idx < rows(); idx++) {
96  for (size_t jdx = 0; jdx < columns(); jdx++) {
97  double val = gsl_matrix_get(gsl(), idx, jdx);
98  gsl_matrix_set(gsl(), idx, jdx, fn(val));
99  }
100  }
101  return static_cast<T &>(*this);
102  }
103 };
104 
105 } // namespace nmx::gsl::mat
The IMBase class Basisfunktionalität für eine gsl-Matrix in Form einer Komponente T ist die Klasse...
Definition: xmatrix0.h:14
static const Format & array()
array lese internes Formatierungsobjekt
Definition: xoutput.h:118
T & transform(FN fn)
transform eine Funktion wird auf alle Elemente der Matrix angewandt
Definition: xmatrix0.h:94
size_t columns() const
columns
Definition: xmatrix0.h:30
void save(std::ostream &os, Format fmt=Output::array()) const
save Speichert reihenweise eine Matrix
Definition: xmatrix0.h:65
size_t rows() const
rows
Definition: xmatrix0.h:24
friend std::ostream & operator<<(std::ostream &os, const T &p)
operator << leitet die Daten der abgeleiteten Klasse an einem Ausgabestrom weiter ...
Definition: xmatrix0.h:82
const gsl_matrix * gsl() const
ermöglicht direkten Zugriff auf gsl-Funktionen
Definition: xvector0.h:18
bool empty() const
empty
Definition: xmatrix0.h:36
The Format class Formatierte Ausgabe von Arrays.
Definition: xfmt.h:10
double operator()(size_t idx, size_t jdx) const
operator () lesender Zugriff
Definition: xmatrix0.h:46
double & operator()(size_t i, size_t j)
operator () schreibender Zugriff
Definition: xmatrix0.h:56
The IGslContainer struct Basisklasse für gsl-Vektoren und Matrizen.
Definition: xvector0.h:13