cotila  1.2.1
A compile time linear algebra system
All Classes Files Functions Variables Modules Pages
matrix.h
Go to the documentation of this file.
1 
5 #ifndef COTILA_MATRIX_MATRIX_H_
6 #define COTILA_MATRIX_MATRIX_H_
7 
8 #include <array>
9 #include <cotila/vector/utility.h>
10 #include <cotila/vector/vector.h>
11 #include <cotila/detail/assert.h>
12 #include <tuple>
13 
14 namespace cotila {
15 
25 template <typename T, std::size_t N, std::size_t M> struct matrix {
26  static_assert(N != 0 && M != 0,
27  "matrix must have have positive dimensions");
28  COTILA_DETAIL_ASSERT_ARITHMETIC(T)
29 
30  using value_type = T;
31  using size_type = std::size_t;
32  static constexpr size_type column_size = N;
33  static constexpr size_type row_size = M;
34 
36 
43  constexpr vector<T, M> row(std::size_t i) const {
44  if (i >= N)
45  throw "index out of range";
46  return generate<M>([i, this](std::size_t j) { return arrays[i][j]; });
47  }
48 
55  constexpr vector<T, N> column(std::size_t i) const {
56  if (i >= M)
57  throw "index out of range";
58  return generate<N>([i, this](std::size_t j) { return arrays[j][i]; });
59  }
60 
70  constexpr T *operator[](std::size_t i) { return arrays[i]; }
71 
73  constexpr T const *operator[](std::size_t i) const { return arrays[i]; }
75 
76  T arrays[N][M];
77 };
78 
84 
94 template <typename T, std::size_t M, std::size_t N>
95 matrix(const T (&)[M][N])->matrix<T, M, N>;
96 
105 template <typename T, std::size_t M, std::size_t N>
106 matrix(const T (&)[M][N][2])->matrix<std::complex<T>, M, N>;
107 
109 
112 } // namespace cotila
113 
114 #endif // COTILA_MATRIX_MATRIX_H_
constexpr T const * operator[](std::size_t i) const
access specified element
Definition: matrix.h:73
Definition: math.h:16
matrix(const T(&)[M][N]) -> matrix< T, M, N >
deduction guide for aggregate initialization
A container representing a vector.
Definition: vector.h:25
constexpr vector< T, M > row(std::size_t i) const
access specified row
Definition: matrix.h:43
static constexpr size_type row_size
Number of columns.
Definition: matrix.h:33
constexpr vector< T, N > column(std::size_t i) const
access specified column
Definition: matrix.h:55
Contains the definition of the cotila::vector class.
A container representing a matrix.
Definition: matrix.h:25
static constexpr size_type column_size
Number of rows.
Definition: matrix.h:32
constexpr T * operator[](std::size_t i)
access specified element
Definition: matrix.h:70