OGLplus  (0.59.0) a C++ wrapper for rendering APIs

matrix.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_HPP
9 #define EAGINE_MATH_MATRIX_HPP
10 
11 #include "../assert.hpp"
12 #include "../maybe_unused.hpp"
13 #include "vector.hpp"
14 #include <utility>
15 
16 namespace eagine {
17 namespace math {
18 //------------------------------------------------------------------------------
23 template <typename T, int C, int R, bool RM, bool V>
24 struct matrix {
25  using type = matrix;
26 
28  using element_type = T;
29 
30  template <int... U>
31  using _iseq = std::integer_sequence<int, U...>;
32 
33  template <int N>
34  using _make_iseq = std::make_integer_sequence<int, N>;
35 
36  vect::data_t<T, RM ? C : R, V> _v[RM ? R : C];
37 
38  template <typename P, int... I>
39  static auto _from_hlp(const P* dt, span_size_t sz, _iseq<I...>) noexcept
40  -> matrix {
41  return matrix{
42  {vect::from_array < T,
43  RM ? C : R,
44  V > ::apply(dt + I * (RM ? C : R), sz - I * (RM ? C : R))...}};
45  }
46 
48  template <typename P>
49  static auto from(const P* dt, span_size_t sz) noexcept -> matrix {
50  return _from_hlp(dt, sz, _make_iseq < RM ? R : C > ());
51  }
52 
53  template <typename P, int M, int N, bool W, int... I>
54  static auto _from_hlp(const matrix<P, M, N, RM, W>& m, _iseq<I...>) noexcept
55  -> matrix {
56  return matrix{
57  {vect::cast<P, (RM ? M : N), W, T, (RM ? C : R), V>::apply(
58  m._v[I], T(0))...}};
59  }
60 
62  template <typename P, int M, int N, bool W>
63  static auto from(const matrix<P, M, N, RM, W>& m) noexcept
64  -> std::enable_if_t<(C <= M) && (R <= N), matrix> {
65  return _from_hlp(m, _make_iseq < RM ? R : C > ());
66  }
67 
69  auto operator[](int i) const noexcept -> const vector<T, RM ? C : R, V> {
70  return {_v[i]};
71  }
72 };
73 //------------------------------------------------------------------------------
76 template <typename T, int C, int R, bool RM, bool V>
77 struct is_row_major<matrix<T, C, R, RM, V>> : bool_constant<RM> {};
78 
81 template <typename X>
82 const auto is_row_major_v = is_row_major<X>::value;
83 //------------------------------------------------------------------------------
86 template <typename T, int C, int R, bool RM, bool V>
87 static constexpr auto rows(const matrix<T, C, R, RM, V>&) noexcept {
88  return R;
89 }
90 //------------------------------------------------------------------------------
93 template <typename T, int C, int R, bool RM, bool V>
94 static constexpr auto columns(const matrix<T, C, R, RM, V>&) noexcept {
95  return C;
96 }
97 //------------------------------------------------------------------------------
100 template <typename T, int C, int R, bool RM, bool V>
101 static constexpr auto row_major(const matrix<T, C, R, RM, V>&) noexcept {
102  return RM;
103 }
104 //------------------------------------------------------------------------------
107 template <typename T, int N, bool RM, bool V>
108 static constexpr auto dimension(const matrix<T, N, N, RM, V>&) noexcept {
109  return N;
110 }
111 //------------------------------------------------------------------------------
114 template <int CI, int RI, typename T, int C, int R, bool V>
115 static constexpr auto get_cm(const matrix<T, C, R, false, V>& m) noexcept
116  -> std::enable_if_t<(CI < C && RI < R), T> {
117  return m._v[CI][RI];
118 }
119 //------------------------------------------------------------------------------
122 template <int CI, int RI, typename T, int C, int R, bool V>
123 static constexpr auto get_cm(const matrix<T, C, R, true, V>& m) noexcept
124  -> std::enable_if_t<(CI < C && RI < R), T> {
125  return m._v[RI][CI];
126 }
127 //------------------------------------------------------------------------------
130 template <typename T, int C, int R, bool V>
131 static constexpr auto
132 get_cm(const matrix<T, C, R, false, V>& m, int ci, int ri) noexcept -> T {
133  EAGINE_ASSERT(ci < C && ri < R);
134  return m._v[ci][ri];
135 }
136 //------------------------------------------------------------------------------
139 template <typename T, int C, int R, bool V>
140 static constexpr auto
141 get_cm(const matrix<T, C, R, true, V>& m, int ci, int ri) noexcept -> T {
142  EAGINE_ASSERT(ci < C && ri < R);
143  return m._v[ri][ci];
144 }
145 //------------------------------------------------------------------------------
148 template <int RI, int CI, typename T, int C, int R, bool V>
149 static constexpr auto get_rm(const matrix<T, C, R, false, V>& m) noexcept
150  -> std::enable_if_t<(CI < C && RI < R), T> {
151  return m._v[CI][RI];
152 }
153 //------------------------------------------------------------------------------
156 template <int RI, int CI, typename T, int C, int R, bool V>
157 static constexpr auto get_rm(const matrix<T, C, R, true, V>& m) noexcept
158  -> std::enable_if_t<(CI < C && RI < R), T> {
159  return m._v[RI][CI];
160 }
161 //------------------------------------------------------------------------------
164 template <typename T, int C, int R, bool V>
165 static constexpr auto
166 get_rm(const matrix<T, C, R, false, V>& m, int ri, int ci) noexcept -> T {
167  EAGINE_ASSERT(ci < C && ri < R);
168  return m._v[ci][ri];
169 }
170 //------------------------------------------------------------------------------
173 template <typename T, int C, int R, bool V>
174 static constexpr auto
175 get_rm(const matrix<T, C, R, true, V>& m, int ri, int ci) noexcept -> T {
176  EAGINE_ASSERT(ci < C && ri < R);
177  return m._v[ri][ci];
178 }
179 //------------------------------------------------------------------------------
182 template <int CI, int RI, typename T, int C, int R, bool V>
183 static inline auto set_cm(matrix<T, C, R, false, V>& m, T v) noexcept
184  -> std::enable_if_t<(CI < C && RI < R)> {
185  m._v[CI][RI] = v;
186 }
187 //------------------------------------------------------------------------------
190 template <int CI, int RI, typename T, int C, int R, bool V>
191 static inline auto set_cm(matrix<T, C, R, true, V>& m, T v) noexcept
192  -> std::enable_if_t<(CI < C && RI < R)> {
193  m._v[RI][CI] = v;
194 }
195 //------------------------------------------------------------------------------
198 template <typename T, int C, int R, bool V>
199 static inline void
200 set_cm(matrix<T, C, R, false, V>& m, int ci, int ri, T v) noexcept {
201  EAGINE_ASSERT(ci < C && ri < R);
202  m._v[ci][ri] = v;
203 }
204 //------------------------------------------------------------------------------
207 template <typename T, int C, int R, bool V>
208 static inline void
209 set_cm(matrix<T, C, R, true, V>& m, int ci, int ri, T v) noexcept {
210  EAGINE_ASSERT(ci < C && ri < R);
211  m._v[ri][ci] = v;
212 }
213 //------------------------------------------------------------------------------
216 template <int RI, int CI, typename T, int C, int R, bool V>
217 static inline auto set_rm(matrix<T, C, R, false, V>& m, T v) noexcept
218  -> std::enable_if_t<(CI < C && RI < R)> {
219  m._v[CI][RI] = v;
220 }
221 //------------------------------------------------------------------------------
224 template <int RI, int CI, typename T, int C, int R, bool V>
225 static inline auto set_rm(matrix<T, C, R, true, V>& m, T v) noexcept
226  -> std::enable_if_t<(CI < C && RI < R)> {
227  m._v[RI][CI] = v;
228 }
229 //------------------------------------------------------------------------------
232 template <typename T, int C, int R, bool V>
233 static inline void
234 set_rm(matrix<T, C, R, false, V>& m, int ri, int ci, T v) noexcept {
235  EAGINE_ASSERT(ci < C && ri < R);
236  m._v[ci][ri] = v;
237 }
238 //------------------------------------------------------------------------------
241 template <typename T, int C, int R, bool V>
242 static inline void
243 set_rm(matrix<T, C, R, true, V>& m, int ri, int ci, T v) noexcept {
244  EAGINE_ASSERT(ci < C && ri < R);
245  m._v[ri][ci] = v;
246 }
247 //------------------------------------------------------------------------------
248 // transpose_tpl helper 4x4 matrix
249 template <bool DstRM, typename T, bool V>
250 static inline auto transpose_tpl_hlp(
251  const vect::data_t<T, 4, V>& q0,
252  const vect::data_t<T, 4, V>& q1,
253  const vect::data_t<T, 4, V>& q2,
254  const vect::data_t<T, 4, V>& q3) noexcept {
256  {vect::shuffle2<T, 4, V>::template apply<0, 2, 4, 6>(q0, q2),
257  vect::shuffle2<T, 4, V>::template apply<1, 3, 5, 7>(q0, q2),
258  vect::shuffle2<T, 4, V>::template apply<0, 2, 4, 6>(q1, q3),
259  vect::shuffle2<T, 4, V>::template apply<1, 3, 5, 7>(q1, q3)}};
260 }
261 //------------------------------------------------------------------------------
262 // transpose_tpl 4x4 matrix
263 template <bool DstRM, bool SrcRM, typename T, bool V>
264 static inline auto transpose_tpl(const matrix<T, 4, 4, SrcRM, V>& m) noexcept
265  -> matrix<T, 4, 4, DstRM, V> {
266  return transpose_tpl_hlp<DstRM, T, V>(
267  vect::shuffle2<T, 4, V>::template apply<0, 1, 4, 5>(m._v[0], m._v[1]),
268  vect::shuffle2<T, 4, V>::template apply<2, 3, 6, 7>(m._v[0], m._v[1]),
269  vect::shuffle2<T, 4, V>::template apply<0, 1, 4, 5>(m._v[2], m._v[3]),
270  vect::shuffle2<T, 4, V>::template apply<2, 3, 6, 7>(m._v[2], m._v[3]));
271 }
272 //------------------------------------------------------------------------------
273 // transpose_tpl
274 template <bool DstRM, bool SrcRM, typename T, int C, int R, bool V>
275 static inline auto transpose_tpl(const matrix<T, C, R, SrcRM, V>& m) noexcept
276  -> matrix<T, (DstRM == SrcRM ? R : C), (DstRM == SrcRM ? C : R), DstRM, V> {
277  static const bool S = (DstRM != SrcRM);
278  matrix<T, (S ? C : R), (S ? R : C), DstRM, V> r;
279 
280  for(int i = 0; i < R; ++i) {
281  for(int j = 0; j < C; ++j) {
282  set_rm(r, S ? i : j, S ? j : i, get_rm(m, i, j));
283  }
284  }
285 
286  return r;
287 }
288 //------------------------------------------------------------------------------
291 template <typename T, int C, int R, bool RM, bool V>
292 static inline auto transpose(const matrix<T, C, R, RM, V>& m) noexcept
294  return transpose_tpl<RM, RM, T>(m);
295 }
296 //------------------------------------------------------------------------------
297 // reordered matrix trait
298 template <typename X>
299 struct reordered_matrix;
300 //------------------------------------------------------------------------------
303 template <typename X>
304 using reordered_matrix_t = typename reordered_matrix<X>::type;
305 //------------------------------------------------------------------------------
308 template <typename T, int C, int R, bool RM, bool V>
309 struct reordered_matrix<matrix<T, C, R, RM, V>> : matrix<T, R, C, !RM, V> {};
310 //------------------------------------------------------------------------------
313 template <typename T, int C, int R, bool RM, bool V>
314 static inline auto reorder(const matrix<T, C, R, RM, V>& m) noexcept
316  return transpose_tpl<!RM, RM, T>(m);
317 }
318 //------------------------------------------------------------------------------
321 template <typename T, int C, int R, bool V>
322 static constexpr auto make_row_major(matrix<T, C, R, true, V> m) noexcept
324  return m;
325 }
326 //------------------------------------------------------------------------------
329 template <typename T, int C, int R, bool V>
330 static inline auto make_row_major(const matrix<T, C, R, false, V>& m) noexcept
332  return reorder(m);
333 }
334 //------------------------------------------------------------------------------
337 template <typename T, int C, int R, bool V>
338 static constexpr auto make_column_major(matrix<T, C, R, false, V> m) noexcept
340  return m;
341 }
342 //------------------------------------------------------------------------------
345 template <typename T, int C, int R, bool V>
346 static inline auto make_column_major(const matrix<T, C, R, true, V>& m) noexcept
348  return reorder(m);
349 }
350 //------------------------------------------------------------------------------
353 template <int I, typename T, int C, int R, bool RM, bool V>
354 static constexpr auto major_vector(const matrix<T, C, R, RM, V>& m) noexcept
355  -> std::enable_if_t<(I < (RM ? R : C)), vector<T, (RM ? C : R), V>> {
356  return {m._v[I]};
357 }
358 //------------------------------------------------------------------------------
361 template <int I, typename T, int C, int R, bool RM, bool V>
362 static inline auto minor_vector(const matrix<T, C, R, RM, V>& m) noexcept
363  -> std::enable_if_t<(I < (RM ? C : R)), vector<T, (RM ? R : C), V>> {
364  return major_vector<I>(reorder(m));
365 }
366 //------------------------------------------------------------------------------
367 // minor_vector mat4x4
368 template <int I, typename T, bool RM, bool V>
369 static inline auto minor_vector(const matrix<T, 4, 4, RM, V>& m) noexcept
370  -> std::enable_if_t<(I < 4), vector<T, 4, V>> {
371  return {vect::shuffle2<T, 4, V>::template apply<0, 1, 4, 5>(
372  vect::shuffle2<T, 4, V>::template apply<0 + I, 4 + I, -1, -1>(
373  m._v[0], m._v[1]),
374  vect::shuffle2<T, 4, V>::template apply<0 + I, 4 + I, -1, -1>(
375  m._v[2], m._v[3]))};
376 }
377 //------------------------------------------------------------------------------
380 template <int I, typename T, int C, int R, bool V>
381 static constexpr auto row(const matrix<T, C, R, true, V>& m) noexcept
382  -> vector<T, C, V> {
383  static_assert(I < R);
384  return major_vector<I>(m);
385 }
386 //------------------------------------------------------------------------------
389 template <int I, typename T, int C, int R, bool V>
390 static inline auto row(const matrix<T, C, R, false, V>& m) noexcept
391  -> vector<T, C, V> {
392  static_assert(I < R);
393  return minor_vector<I>(m);
394 }
395 //------------------------------------------------------------------------------
396 // _row_hlp
397 template <typename T, int C, int R, bool RM, bool V>
398 static inline auto
399 _row_hlp(const matrix<T, C, R, RM, V>& m, int_constant<0U>, int i) noexcept
400  -> vector<T, C, V> {
401  EAGINE_ASSERT(i == 0U);
402  EAGINE_MAYBE_UNUSED(i);
403  return row<0U>(m);
404 }
405 //------------------------------------------------------------------------------
406 // _row_hlp
407 template <typename T, int R, int C, bool RM, bool V, int I>
408 static inline auto
409 _row_hlp(const matrix<T, C, R, RM, V>& m, int_constant<I>, int i) noexcept
410  -> vector<T, C, V> {
411  if(I == i) {
412  return row<I>(m);
413  }
414  return _row_hlp(m, int_constant<I - 1>(), i);
415 }
416 //------------------------------------------------------------------------------
419 template <typename T, int R, int C, bool RM, bool V>
420 static inline auto row(const matrix<T, C, R, RM, V>& m, int i) noexcept
421  -> vector<T, C, V> {
422  return _row_hlp(m, int_constant<R - 1>(), i);
423 }
424 //------------------------------------------------------------------------------
427 template <int I, typename T, int C, int R, bool V>
428 static constexpr auto column(const matrix<T, C, R, false, V>& m) noexcept
429  -> vector<T, R, V> {
430  return major_vector<I>(m);
431 }
432 //------------------------------------------------------------------------------
435 template <int I, typename T, int C, int R, bool V>
436 static inline auto column(const matrix<T, C, R, true, V>& m) noexcept
437  -> vector<T, R, V> {
438  return minor_vector<I>(m);
439 }
440 //------------------------------------------------------------------------------
441 // _col_hlp
442 template <typename T, int C, int R, bool RM, bool V>
443 static inline auto
444 _col_hlp(const matrix<T, C, R, RM, V>& m, int_constant<0U>, int i) noexcept
445  -> vector<T, R, V> {
446  EAGINE_ASSERT(i == 0);
447  EAGINE_MAYBE_UNUSED(i);
448  return column<0>(m);
449 }
450 //------------------------------------------------------------------------------
451 // _col_hlp
452 template <typename T, int C, int R, bool RM, bool V, int I>
453 static inline auto
454 _col_hlp(const matrix<T, C, R, RM, V>& m, int_constant<I>, int i) noexcept
455  -> vector<T, R, V> {
456  if(I == i) {
457  return column<I>(m);
458  }
459  return _col_hlp(m, int_constant<I - 1>(), i);
460 }
461 //------------------------------------------------------------------------------
464 template <typename T, int R, int C, bool RM, bool V>
465 static inline auto column(const matrix<T, C, R, RM, V>& m, int i) noexcept
466  -> vector<T, R, V> {
467  return _col_hlp(m, int_constant<C - 1>(), i);
468 }
469 //------------------------------------------------------------------------------
473 template <typename X>
474 struct is_matrix_constructor : std::false_type {};
475 
481 template <typename X>
483 //------------------------------------------------------------------------------
484 template <bool RM, typename T, int C, int R, bool V>
485 struct is_matrix_constructor<matrix<T, C, R, RM, V>> : std::true_type {};
486 //------------------------------------------------------------------------------
490 template <typename X>
492 //------------------------------------------------------------------------------
495 template <typename X>
497 //------------------------------------------------------------------------------
498 // constructed_matrix trait
499 template <typename T, int C, int R, bool RM, bool V>
500 struct constructed_matrix<matrix<T, C, R, RM, V>> : matrix<T, C, R, RM, V> {};
501 //------------------------------------------------------------------------------
502 // construct_matrix (noop)
503 template <bool RM, typename T, int C, int R, bool V>
504 static constexpr auto construct_matrix(const matrix<T, C, R, RM, V>& m) noexcept
505  -> const matrix<T, C, R, RM, V>& {
506  return m;
507 }
508 //------------------------------------------------------------------------------
509 // construct_matrix (reorder)
510 template <bool RM, typename T, int C, int R, bool V>
511 static constexpr auto construct_matrix(const matrix<T, C, R, !RM, V>& m) noexcept
512  -> matrix<T, C, R, RM, V> {
513  return reorder(m);
514 }
515 //------------------------------------------------------------------------------
516 // are_multiplicable
517 template <typename T, int M, int N, int K, bool RM1, bool RM2, bool V>
518 struct are_multiplicable<matrix<T, M, K, RM1, V>, matrix<T, K, N, RM2, V>>
519  : std::true_type {};
520 //------------------------------------------------------------------------------
521 // multiplication_result MxM
522 template <typename T, int M, int N, int K, bool RM1, bool RM2, bool V>
523 struct multiplication_result<matrix<T, K, M, RM1, V>, matrix<T, N, K, RM2, V>>
524  : matrix<T, N, M, RM1, V> {};
525 //------------------------------------------------------------------------------
528 template <typename T, int M, int N, int K, bool RM1, bool RM2, bool V>
529 static inline auto multiply(
530  const matrix<T, K, M, RM1, V>& m1,
531  const matrix<T, N, K, RM2, V>& m2) noexcept -> matrix<T, N, M, RM1, V> {
533 
534  for(int i = 0; i < M; ++i) {
535  for(int j = 0; j < N; ++j) {
536  T s = T(0);
537 
538  for(int k = 0; k < K; ++k) {
539  s += get_rm(m1, i, k) * get_rm(m2, k, j);
540  }
541 
542  set_rm(m3, i, j, s);
543  }
544  }
545  return m3;
546 }
547 //------------------------------------------------------------------------------
548 // are_multiplicable
549 template <typename T, int C, int R, bool RM, bool V>
550 struct are_multiplicable<matrix<T, C, R, RM, V>, vector<T, C, V>>
551  : std::true_type {};
552 //------------------------------------------------------------------------------
553 // multiplication_result MxV
554 template <typename T, int C, int R, bool RM, bool V>
555 struct multiplication_result<matrix<T, C, R, RM, V>, vector<T, C, V>>
556  : vector<T, R, V> {};
557 //------------------------------------------------------------------------------
560 template <typename T, int C, int R, bool RM, bool V>
561 static inline auto
562 multiply(const matrix<T, C, R, RM, V>& m, const vector<T, C, V>& v) noexcept
563  -> vector<T, R, V> {
564  vector<T, R, V> r{};
565 
566  for(int i = 0; i < R; ++i) {
567  T s = T(0);
568  for(int j = 0; j < C; ++j) {
569  s += get_rm(m, i, j) * v._v[j];
570  }
571  r._v[i] = s;
572  }
573  return r;
574 }
575 //------------------------------------------------------------------------------
582 template <
583  typename MC1,
584  typename MC2,
585  typename = std::enable_if_t<
586  is_matrix_constructor<MC1>::value && is_matrix_constructor<MC2>::value &&
587  are_multiplicable<constructed_matrix_t<MC1>, constructed_matrix_t<MC2>>::value>>
588 static inline auto operator*(const MC1& mc1, const MC2& mc2) noexcept {
589  return multiply(mc1, mc2);
590 }
591 //------------------------------------------------------------------------------
592 } // namespace math
593 //------------------------------------------------------------------------------
594 template <typename T, int C, int R, bool RM, bool V>
595 struct is_known_matrix_type<math::matrix<T, C, R, RM, V>>
596  : std::is_scalar<T> {};
597 //------------------------------------------------------------------------------
598 template <typename T, int C, int R, bool RM, bool V>
599 struct canonical_compound_type<math::matrix<T, C, R, RM, V>>
600  : type_identity<std::remove_cv_t<T[C][R]>> {};
601 //------------------------------------------------------------------------------
602 template <typename T, int C, int R, bool RM, bool V>
603 struct compound_view_maker<math::matrix<T, C, R, RM, V>> {
604  auto operator()(const math::matrix<T, C, R, RM, V>& m) const noexcept {
605  return vect::view < T, RM ? C : R, V > ::apply(m._v);
606  }
607 };
608 //------------------------------------------------------------------------------
609 template <typename T, int C, int R, bool RM, bool V>
610 struct is_row_major<math::matrix<T, C, R, RM, V>> : bool_constant<RM> {};
611 //------------------------------------------------------------------------------
612 } // namespace eagine
613 
614 #endif // EAGINE_MATH_MATRIX_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto operator[](int i) const noexcept -> const vector< T, RM ? C :R, V >
Subscript operator.
Definition: matrix.hpp:69
static constexpr auto make_column_major(matrix< T, C, R, false, V > m) noexcept -> matrix< T, C, R, false, V >
Returns a matrix ordered as column-major.
Definition: matrix.hpp:338
static constexpr auto columns(const matrix< T, C, R, RM, V > &) noexcept
Returns then number of matrix columns.
Definition: matrix.hpp:94
static auto from(const matrix< P, M, N, RM, W > &m) noexcept -> std::enable_if_t<(C<=M) &&(R<=N), matrix >
Creates a matrix from another matrix type.
Definition: matrix.hpp:63
T element_type
Element type.
Definition: matrix.hpp:28
Basic N-dimensional vector implementation template.
Definition: fwd.hpp:19
static constexpr auto row_major(const matrix< T, C, R, RM, V > &) noexcept
Indicates if a matrix is row-major.
Definition: matrix.hpp:101
static constexpr auto rows(const matrix< T, C, R, RM, V > &) noexcept
Returns then number of matrix rows.
Definition: matrix.hpp:87
static constexpr auto dimension(const matrix< T, N, N, RM, V > &) noexcept
Returns the dimension of a square matrix.
Definition: matrix.hpp:108
constexpr auto is_matrix_constructor_v
Trait indicating if a type X is a matrix constructor.
Definition: matrix.hpp:482
typename constructed_matrix< X >::type constructed_matrix_t
Trait returning the matrix type constructed by constructor type X.
Definition: matrix.hpp:496
Indicates if the specified type X is a matrix constructor.
Definition: matrix.hpp:474
static auto reorder(const matrix< T, C, R, RM, V > &m) noexcept -> matrix< T, C, R, !RM, V >
Returns a matrix reordered (switches row/column major).
Definition: matrix.hpp:314
static auto set_cm(matrix< T, C, R, false, V > &m, T v) noexcept -> std::enable_if_t<(CI< C &&RI< R)>
Sets the matrix element at [CI, RI]. Column-major implementation.
Definition: matrix.hpp:183
Gets the constructed matrix type for a matrix constructor type.
Definition: matrix.hpp:491
std::integral_constant< bool, B > bool_constant
Alias for boolean constant type.
Definition: int_constant.hpp:20
static constexpr auto make_row_major(matrix< T, C, R, true, V > m) noexcept -> matrix< T, C, R, true, V >
Returns a matrix ordered as row-major.
Definition: matrix.hpp:322
typename reordered_matrix< X >::type reordered_matrix_t
Trait returns a reordered (switch row/column-major) type for a matrix type.
Definition: matrix.hpp:304
static constexpr auto get_rm(const matrix< T, C, R, false, V > &m) noexcept -> std::enable_if_t<(CI< C &&RI< R), T >
Returns the matrix element at [RI, CI]. Column-major implementation.
Definition: matrix.hpp:149
static constexpr auto major_vector(const matrix< T, C, R, RM, V > &m) noexcept -> std::enable_if_t<(I<(RM ? R :C)), vector< T,(RM ? C :R), V >>
Returns the I-th major vector of a matrix.
Definition: matrix.hpp:354
static auto operator*(const MC1 &mc1, const MC2 &mc2) noexcept
Multiplication operator for matrix constructors.
Definition: matrix.hpp:588
static constexpr auto column(const matrix< T, C, R, false, V > &m) noexcept -> vector< T, R, V >
Returns the I-th column vector of a matrix. Column-major implementation.
Definition: matrix.hpp:428
const auto is_row_major_v
Trait indicating if a matrix type is row-major.
Definition: matrix.hpp:82
static constexpr auto row(const matrix< T, C, R, true, V > &m) noexcept -> vector< T, C, V >
Returns the I-th row vector of a matrix. Row-major implementation.
Definition: matrix.hpp:381
static auto set_rm(matrix< T, C, R, false, V > &m, T v) noexcept -> std::enable_if_t<(CI< C &&RI< R)>
Sets the matrix element at [RI, CI]. Column-major implementation.
Definition: matrix.hpp:217
static auto from(const P *dt, span_size_t sz) noexcept -> matrix
Creates a matrix from data pointer and size.
Definition: matrix.hpp:49
static auto multiply(const matrix< T, K, M, RM1, V > &m1, const matrix< T, N, K, RM2, V > &m2) noexcept -> matrix< T, N, M, RM1, V >
Matrix multiplication function.
Definition: matrix.hpp:529
static constexpr auto get_cm(const matrix< T, C, R, false, V > &m) noexcept -> std::enable_if_t<(CI< C &&RI< R), T >
Returns the matrix element at [CI, RI]. Column-major implementation.
Definition: matrix.hpp:115
std::integral_constant< int, I > int_constant
Alias for signed int constant type.
Definition: int_constant.hpp:25
static auto minor_vector(const matrix< T, C, R, RM, V > &m) noexcept -> std::enable_if_t<(I<(RM ? C :R)), vector< T,(RM ? R :C), V >>
Returns the I-th minor vector of a matrix.
Definition: matrix.hpp:362
static auto transpose(const matrix< T, C, R, RM, V > &m) noexcept -> matrix< T, R, C, RM, V >
Transposes a matrix.
Definition: matrix.hpp:292
Basic RxC matrix implementation template.
Definition: fwd.hpp:25

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).