Blender V5.3
BLI_math_matrix_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
33
34#include <ostream>
35#include <type_traits>
36
37#include "BLI_unroll.hh"
38
40#include "BLI_utildefines.hh"
41#include "BLI_utility_mixins.hh"
42
43namespace blender {
44
45template<typename T,
46 int NumCol,
47 int NumRow,
48 int SrcNumCol,
49 int SrcNumRow,
50 int SrcStartCol,
51 int SrcStartRow,
52 int Alignment>
53struct MatView;
54
55template<typename T,
56 int NumCol,
57 int NumRow,
58 int SrcNumCol,
59 int SrcNumRow,
60 int SrcStartCol,
61 int SrcStartRow,
62 int Alignment>
63struct MutableMatView;
64
65template<
66 /* Number type. */
67 typename T,
68 /* Number of column in the matrix. */
69 int NumCol,
70 /* Number of row in the matrix. */
71 int NumRow,
72 /* Alignment in bytes. Do not align matrices whose size is not a multiple of 4 component.
73 * This is in order to avoid padding when using arrays of matrices. */
74 int Alignment = (((NumCol * NumRow) % 4 == 0) ? 4 : 1) * sizeof(T)>
75struct alignas(Alignment) MatBase : public vec_struct_base<VecBase<T, NumRow>, NumCol, false> {
76
77 using base_type = T;
81 using loc_type = VecBase<T, (NumRow < NumCol) ? NumRow : (NumRow - 1)>;
82 static constexpr int min_dim = (NumRow < NumCol) ? NumRow : NumCol;
83 static constexpr int col_len = NumCol;
84 static constexpr int row_len = NumRow;
85
91 MatBase() = default;
92
94 requires(NumCol == 2)
95 {
96 (*this)[0] = _x;
97 (*this)[1] = _y;
98 }
99
101 requires(NumCol == 3)
102 {
103 (*this)[0] = _x;
104 (*this)[1] = _y;
105 (*this)[2] = _z;
106 }
107
109 requires(NumCol == 4)
110 {
111 (*this)[0] = _x;
112 (*this)[1] = _y;
113 (*this)[2] = _z;
114 (*this)[3] = _w;
115 }
116
118
119 template<typename U, int OtherNumCol, int OtherNumRow>
121 {
122 if constexpr ((OtherNumRow >= NumRow) && (OtherNumCol >= NumCol)) {
123 unroll<NumCol>([&](auto i) { (*this)[i] = col_type(other[i]); });
124 }
125 else {
126 /* Allow enlarging following GLSL standard (i.e: mat4x4(mat3x3())). */
127 unroll<NumCol>([&](auto i) {
128 unroll<NumRow>([&](auto j) {
129 if (i < OtherNumCol && j < OtherNumRow) {
130 (*this)[i][j] = other[i][j];
131 }
132 else if (i == j) {
133 (*this)[i][j] = T(1);
134 }
135 else {
136 (*this)[i][j] = T(0);
137 }
138 });
139 });
140 }
141 }
142
144
145 explicit MatBase(const T *ptr)
146 {
147 unroll<NumCol>([&](auto i) { (*this)[i] = reinterpret_cast<const col_type *>(ptr)[i]; });
148 }
149
150 template<typename U>
151 explicit MatBase(const U *ptr)
152 requires(std::is_convertible_v<U, T>)
153 {
154 unroll<NumCol>([&](auto i) { (*this)[i] = ptr[i]; });
155 }
156
157 explicit MatBase(const T (*ptr)[NumCol]) : MatBase(static_cast<const T *>(ptr[0])) {}
158
160
161 template<typename U> explicit MatBase(const MatBase<U, NumRow, NumCol> &vec)
162 {
163 unroll<NumCol>([&](auto i) { (*this)[i] = col_type(vec[i]); });
164 }
165
167
168 using c_style_mat = T[NumCol][NumRow];
169
171 const c_style_mat &ptr() const
172 {
173 return *reinterpret_cast<const c_style_mat *>(this);
174 }
175
178 {
179 return *reinterpret_cast<c_style_mat *>(this);
180 }
181
183 const T *base_ptr() const
184 {
185 return reinterpret_cast<const T *>(this);
186 }
187
190 {
191 return reinterpret_cast<T *>(this);
192 }
193
195
196 template<int ViewNumCol = NumCol,
197 int ViewNumRow = NumRow,
198 int SrcStartCol = 0,
199 int SrcStartRow = 0>
206
207 template<int ViewNumCol = NumCol,
208 int ViewNumRow = NumRow,
209 int SrcStartCol = 0,
210 int SrcStartRow = 0>
213 {
214 return MutableMatView<T,
215 ViewNumCol,
216 ViewNumRow,
217 NumCol,
218 NumRow,
219 SrcStartCol,
220 SrcStartRow,
221 Alignment>(*this);
222 }
223
225
226 const col_type &operator[](int index) const
227 {
228 BLI_assert(index >= 0);
229 BLI_assert(index < NumCol);
230 return reinterpret_cast<const col_type *>(this)[index];
231 }
232
234 {
235 BLI_assert(index >= 0);
236 BLI_assert(index < NumCol);
237 return reinterpret_cast<col_type *>(this)[index];
238 }
239
241
243 {
244 BLI_STATIC_ASSERT(NumCol >= 1, "Wrong Matrix dimension");
245 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
246 return *reinterpret_cast<vec3_type *>(&(*this)[0]);
247 }
248
250 {
251 BLI_STATIC_ASSERT(NumCol >= 2, "Wrong Matrix dimension");
252 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
253 return *reinterpret_cast<vec3_type *>(&(*this)[1]);
254 }
255
257 {
258 BLI_STATIC_ASSERT(NumCol >= 3, "Wrong Matrix dimension");
259 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
260 return *reinterpret_cast<vec3_type *>(&(*this)[2]);
261 }
262
264 {
265 BLI_STATIC_ASSERT(NumCol >= 3, "Wrong Matrix dimension");
266 BLI_STATIC_ASSERT(NumRow >= 2, "Wrong Matrix dimension");
267 return *reinterpret_cast<loc_type *>(&(*this)[NumCol - 1]);
268 }
269
270 const vec3_type &x_axis() const
271 {
272 BLI_STATIC_ASSERT(NumCol >= 1, "Wrong Matrix dimension");
273 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
274 return *reinterpret_cast<const vec3_type *>(&(*this)[0]);
275 }
276
277 const vec3_type &y_axis() const
278 {
279 BLI_STATIC_ASSERT(NumCol >= 2, "Wrong Matrix dimension");
280 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
281 return *reinterpret_cast<const vec3_type *>(&(*this)[1]);
282 }
283
284 const vec3_type &z_axis() const
285 {
286 BLI_STATIC_ASSERT(NumCol >= 3, "Wrong Matrix dimension");
287 BLI_STATIC_ASSERT(NumRow >= 3, "Wrong Matrix dimension");
288 return *reinterpret_cast<const vec3_type *>(&(*this)[2]);
289 }
290
291 const loc_type &location() const
292 {
293 BLI_STATIC_ASSERT(NumCol >= 3, "Wrong Matrix dimension");
294 BLI_STATIC_ASSERT(NumRow >= 2, "Wrong Matrix dimension");
295 return *reinterpret_cast<const loc_type *>(&(*this)[NumCol - 1]);
296 }
297
299
300 friend MatBase operator+(const MatBase &a, const MatBase &b)
301 {
303 unroll<NumCol>([&](auto i) { result[i] = a[i] + b[i]; });
304 return result;
305 }
306
307 friend MatBase operator+(const MatBase &a, T b)
308 {
310 unroll<NumCol>([&](auto i) { result[i] = a[i] + b; });
311 return result;
312 }
313
314 friend MatBase operator+(T a, const MatBase &b)
315 {
316 return b + a;
317 }
318
320 {
321 unroll<NumCol>([&](auto i) { (*this)[i] += b[i]; });
322 return *this;
323 }
324
326 {
327 unroll<NumCol>([&](auto i) { (*this)[i] += b; });
328 return *this;
329 }
330
331 friend MatBase operator-(const MatBase &a)
332 {
334 unroll<NumCol>([&](auto i) { result[i] = -a[i]; });
335 return result;
336 }
337
338 friend MatBase operator-(const MatBase &a, const MatBase &b)
339 {
341 unroll<NumCol>([&](auto i) { result[i] = a[i] - b[i]; });
342 return result;
343 }
344
345 friend MatBase operator-(const MatBase &a, T b)
346 {
348 unroll<NumCol>([&](auto i) { result[i] = a[i] - b; });
349 return result;
350 }
351
352 friend MatBase operator-(T a, const MatBase &b)
353 {
355 unroll<NumCol>([&](auto i) { result[i] = a - b[i]; });
356 return result;
357 }
358
360 {
361 unroll<NumCol>([&](auto i) { (*this)[i] -= b[i]; });
362 return *this;
363 }
364
366 {
367 unroll<NumCol>([&](auto i) { (*this)[i] -= b; });
368 return *this;
369 }
370
372 friend MatBase operator*(const MatBase &a, T b)
373 {
375 unroll<NumCol>([&](auto i) { result[i] = a[i] * b; });
376 return result;
377 }
378
380 friend MatBase operator*(T a, const MatBase &b)
381 {
382 return b * a;
383 }
384
387 {
388 const MatBase &a = *this;
389 *this = a * b;
390 return *this;
391 }
392
395 {
396 unroll<NumCol>([&](auto i) { (*this)[i] *= b; });
397 return *this;
398 }
399
401
402 friend col_type operator*(const MatBase &a, const row_type &b)
403 {
404 /* This is the reference implementation.
405 * Might be overloaded with vectorized / optimized code. */
406 col_type result(0);
407 unroll<NumCol>([&](auto c) { result += b[c] * a[c]; });
408 return result;
409 }
410
412 friend row_type operator*(const col_type &a, const MatBase &b)
413 {
414 /* This is the reference implementation.
415 * Might be overloaded with vectorized / optimized code. */
416 row_type result(0);
417 unroll<NumCol>([&](auto c) { unroll<NumRow>([&](auto r) { result[c] += b[c][r] * a[r]; }); });
418 return result;
419 }
420
422
423 friend bool operator==(const MatBase &a, const MatBase &b)
424 {
425 for (int i = 0; i < NumCol; i++) {
426 if (a[i] != b[i]) {
427 return false;
428 }
429 }
430 return true;
431 }
432
433 friend bool operator!=(const MatBase &a, const MatBase &b)
434 {
435 return !(a == b);
436 }
437
439
440 static MatBase diagonal(T value)
441 {
442 MatBase result{};
443 unroll<min_dim>([&](auto i) { result[i][i] = value; });
444 return result;
445 }
446
447 static MatBase all(T value)
448 {
450 unroll<NumCol>([&](auto i) { result[i] = col_type(value); });
451 return result;
452 }
453
455 {
456 return diagonal(1);
457 }
458
459 static MatBase zero()
460 {
461 return all(0);
462 }
463
465 {
466 uint64_t h = 435109;
467 unroll<NumCol * NumRow>([&](auto i) {
468 T value = (reinterpret_cast<const T *>(this))[i];
469 h = h * 33 + get_default_hash(value);
470 });
471 return h;
472 }
473
475 {
476 unroll<NumCol * NumRow>([&](auto i) {
477 const T &value = (reinterpret_cast<const T *>(this))[i];
479 });
480 }
481
482 friend std::ostream &operator<<(std::ostream &stream, const MatBase &mat)
483 {
484 stream << "(\n";
485 for (int i = 0; i < NumRow; i++) {
486 stream << "(";
487 for (int j = 0; j < NumCol; j++) {
489 stream << mat[j][i];
490 if (j < NumCol - 1) {
491 stream << ", ";
492 }
493 }
494 stream << ")";
495 if (i < NumRow - 1) {
496 stream << ",";
497 }
498 stream << "\n";
499 }
500
501 stream << ")\n";
502 return stream;
503 }
504};
505
506template<typename T,
508 int NumCol,
509 int NumRow,
511 int SrcNumCol,
512 int SrcNumRow,
514 int SrcStartCol,
515 int SrcStartRow,
517 int SrcAlignment>
523
524 const SrcMatT &mat;
525
526 MatView() = delete;
527
528 MatView(const SrcMatT &src) : mat(src)
529 {
530 BLI_STATIC_ASSERT(SrcStartCol >= 0, "View does not fit source matrix dimensions");
531 BLI_STATIC_ASSERT(SrcStartRow >= 0, "View does not fit source matrix dimensions");
532 BLI_STATIC_ASSERT(SrcStartCol + NumCol <= SrcNumCol,
533 "View does not fit source matrix dimensions");
534 BLI_STATIC_ASSERT(SrcStartRow + NumRow <= SrcNumRow,
535 "View does not fit source matrix dimensions");
536 }
537
539 explicit MatView(const float (*src)[SrcNumRow])
540 : MatView(*reinterpret_cast<const SrcMatT *>(&src[0][0])) {};
541
543
544 const col_type &operator[](int index) const
545 {
546 BLI_assert(index >= 0);
547 BLI_assert(index < NumCol);
548 return *reinterpret_cast<const col_type *>(&mat[index + SrcStartCol][SrcStartRow]);
549 }
550
552
553 operator MatT() const
554 {
555 MatT mat;
556 unroll<NumCol>([&](auto c) { mat[c] = (*this)[c]; });
557 return mat;
558 }
559
561
562 friend MatT operator+(const MatView &a, T b)
563 {
564 MatT result;
565 unroll<NumCol>([&](auto i) { result[i] = a[i] + b; });
566 return result;
567 }
568
569 friend MatT operator+(T a, const MatView &b)
570 {
571 return b + a;
572 }
573
574 friend MatT operator-(const MatView &a)
575 {
576 MatT result;
577 unroll<NumCol>([&](auto i) { result[i] = -a[i]; });
578 return result;
579 }
580
581 template<int OtherSrcNumCol,
582 int OtherSrcNumRow,
583 int OtherSrcStartCol,
584 int OtherSrcStartRow,
585 int OtherSrcAlignment>
586 friend MatT operator-(const MatView &a,
587 const MatView<T,
588 NumCol,
589 NumRow,
590 OtherSrcNumCol,
591 OtherSrcNumRow,
592 OtherSrcStartCol,
593 OtherSrcStartRow,
594 OtherSrcAlignment> &b)
595 {
596 MatT result;
597 unroll<NumCol>([&](auto i) { result[i] = a[i] - b[i]; });
598 return result;
599 }
600
601 friend MatT operator-(const MatView &a, const MatT &b)
602 {
603 return a - b.view();
604 }
605
606 template<int OtherSrcNumCol,
607 int OtherSrcNumRow,
608 int OtherSrcStartCol,
609 int OtherSrcStartRow,
610 int OtherSrcAlignment>
611 friend MatT operator-(const MatView<T,
612 NumCol,
613 NumRow,
614 OtherSrcNumCol,
615 OtherSrcNumRow,
616 OtherSrcStartCol,
617 OtherSrcStartRow,
618 OtherSrcAlignment> &a,
619 const MatView &b)
620 {
621 MatT result;
622 unroll<NumCol>([&](auto i) { result[i] = a[i] - b[i]; });
623 return result;
624 }
625
626 friend MatT operator-(const MatT &a, const MatView &b)
627 {
628 return a.view() - b;
629 }
630
631 friend MatT operator-(const MatView &a, T b)
632 {
633 MatT result;
634 unroll<NumCol>([&](auto i) { result[i] = a[i] - b; });
635 return result;
636 }
637
638 friend MatView operator-(T a, const MatView &b)
639 {
641 unroll<NumCol>([&](auto i) { result[i] = a - b[i]; });
642 return result;
643 }
644
645 MatT operator*(const MatT &b) const
646 {
647 return *this * b.view();
648 }
649
651 friend MatT operator*(const MatView &a, T b)
652 {
653 MatT result;
654 unroll<NumCol>([&](auto i) { result[i] = a[i] * b; });
655 return result;
656 }
657
659 friend MatT operator*(T a, const MatView &b)
660 {
661 return b * a;
662 }
663
665
666 friend col_type operator*(const MatView &a, const row_type &b)
667 {
668 /* This is the reference implementation.
669 * Might be overloaded with vectorized / optimized code. */
670 col_type result(0);
671 unroll<NumCol>([&](auto c) { result += b[c] * a[c]; });
672 return result;
673 }
674
676 friend row_type operator*(const col_type &a, const MatView &b)
677 {
678 /* This is the reference implementation.
679 * Might be overloaded with vectorized / optimized code. */
680 row_type result(0);
681 unroll<NumCol>([&](auto c) { unroll<NumRow>([&](auto r) { result[c] += b[c][r] * a[r]; }); });
682 return result;
683 }
684
686
687 friend bool operator==(const MatView &a, const MatView &b)
688 {
689 for (int i = 0; i < NumCol; i++) {
690 if (a[i] != b[i]) {
691 return false;
692 }
693 }
694 return true;
695 }
696
697 friend bool operator!=(const MatView &a, const MatView &b)
698 {
699 return !(a == b);
700 }
701
703
704 friend std::ostream &operator<<(std::ostream &stream, const MatView &mat)
705 {
706 return stream << mat.mat;
707 }
708};
709
710template<typename T,
712 int NumCol,
713 int NumRow,
715 int SrcNumCol,
716 int SrcNumRow,
718 int SrcStartCol,
719 int SrcStartRow,
721 int SrcAlignment>
723 : MatView<T, NumCol, NumRow, SrcNumCol, SrcNumRow, SrcStartCol, SrcStartRow, SrcAlignment> {
724
726 using MatViewT =
731
732 public:
733 MutableMatView() = delete;
734
735 MutableMatView(SrcMatT &src) : MatViewT(const_cast<const SrcMatT &>(src)) {};
736
738 explicit MutableMatView(float src[SrcNumCol][SrcNumRow])
739 : MutableMatView(*reinterpret_cast<SrcMatT *>(&src[0][0])) {};
740
742
744 {
745 return const_cast<col_type &>(static_cast<MatViewT &>(*this)[index]);
746 }
747
749
750 operator MatViewT() const
751 {
752 return MatViewT(this->mat);
753 }
754
756
757 template<int OtherSrcNumCol,
758 int OtherSrcNumRow,
759 int OtherSrcStartCol,
760 int OtherSrcStartRow,
761 int OtherSrcAlignment>
763 NumCol,
764 NumRow,
765 OtherSrcNumCol,
766 OtherSrcNumRow,
767 OtherSrcStartCol,
768 OtherSrcStartRow,
769 OtherSrcAlignment> &other)
770 {
772 (reinterpret_cast<const void *>(&other.mat[0][0]) !=
773 reinterpret_cast<const void *>(&this->mat[0][0])) ||
774 /* Make sure assignment won't overwrite the source. OtherSrc* is the source. */
775 ((OtherSrcStartCol > SrcStartCol) || (OtherSrcStartCol + NumCol <= SrcStartCol) ||
776 (OtherSrcStartRow > SrcStartRow + NumRow) ||
777 (OtherSrcStartRow + NumRow <= SrcStartRow)),
778 "Operation is undefined if views overlap.");
779 unroll<NumCol>([&](auto i) { (*this)[i] = other[i]; });
780 return *this;
781 }
782
784 {
785 *this = other.view();
786 return *this;
787 }
788
790
791 template<int OtherSrcNumCol,
792 int OtherSrcNumRow,
793 int OtherSrcStartCol,
794 int OtherSrcStartRow,
795 int OtherSrcAlignment>
797 NumCol,
798 NumRow,
799 OtherSrcNumCol,
800 OtherSrcNumRow,
801 OtherSrcStartCol,
802 OtherSrcStartRow,
803 OtherSrcAlignment> &b) &
804 {
805 unroll<NumCol>([&](auto i) { (*this)[i] += b[i]; });
806 return *this;
807 }
808
810 {
811 return *this += b.view();
812 }
813
815 {
816 unroll<NumCol>([&](auto i) { (*this)[i] += b; });
817 return *this;
818 }
819
820 template<int OtherSrcNumCol,
821 int OtherSrcNumRow,
822 int OtherSrcStartCol,
823 int OtherSrcStartRow,
824 int OtherSrcAlignment>
826 NumCol,
827 NumRow,
828 OtherSrcNumCol,
829 OtherSrcNumRow,
830 OtherSrcStartCol,
831 OtherSrcStartRow,
832 OtherSrcAlignment> &b) &
833 {
834 unroll<NumCol>([&](auto i) { (*this)[i] -= b[i]; });
835 return *this;
836 }
837
839 {
840 return *this -= b.view();
841 }
842
844 {
845 unroll<NumCol>([&](auto i) { (*this)[i] -= b; });
846 return *this;
847 }
848
850 template<int OtherSrcNumCol,
851 int OtherSrcNumRow,
852 int OtherSrcStartCol,
853 int OtherSrcStartRow,
854 int OtherSrcAlignment>
856 NumCol,
857 NumRow,
858 OtherSrcNumCol,
859 OtherSrcNumRow,
860 OtherSrcStartCol,
861 OtherSrcStartRow,
862 OtherSrcAlignment> &b) &
863 {
864 *this = *static_cast<MatViewT *>(this) * b;
865 return *this;
866 }
867
869 {
870 return *this *= b.view();
871 }
872
875 {
876 unroll<NumCol>([&](auto i) { (*this)[i] *= b; });
877 return *this;
878 }
879
881
883 {
884 /* This is the reference implementation.
885 * Might be overloaded with vectorized / optimized code. */
886 col_type result(0);
887 unroll<NumCol>([&](auto c) { result += b[c] * a[c]; });
888 return result;
889 }
890
893 {
894 /* This is the reference implementation.
895 * Might be overloaded with vectorized / optimized code. */
896 row_type result(0);
897 unroll<NumCol>([&](auto c) { unroll<NumRow>([&](auto r) { result[c] += b[c][r] * a[r]; }); });
898 return result;
899 }
900};
901
902namespace detail {
903
905template<typename T,
906 int A_NumCol,
907 int A_NumRow,
908 int B_NumCol,
909 int B_NumRow,
910 typename MatA,
911 typename MatB>
913{
914 static_assert(A_NumCol == B_NumRow);
915 /* This is the reference implementation.
916 * Might be overloaded with vectorized / optimized code. */
918 unroll<B_NumCol>([&](auto j) {
919 unroll<A_NumRow>([&](auto i) {
920 /* Same as dot product, but avoid dependency on vector math. */
921 unroll<A_NumCol>([&](auto k) { result[j][i] += a[k][i] * b[j][k]; });
922 });
923 });
924 return result;
925}
926
927} // namespace detail
928
929template<typename T, int A_NumCol, int A_NumRow, int B_NumCol, int B_NumRow>
935
936template<typename T,
937 int A_NumCol,
938 int A_NumRow,
939 int A_SrcNumCol,
940 int A_SrcNumRow,
941 int A_SrcStartCol,
942 int A_SrcStartRow,
943 int A_SrcAlignment,
944 int B_NumCol,
945 int B_NumRow,
946 int B_SrcNumCol,
947 int B_SrcNumRow,
948 int B_SrcStartCol,
949 int B_SrcStartRow,
950 int B_SrcAlignment>
952 A_NumCol,
953 A_NumRow,
954 A_SrcNumCol,
955 A_SrcNumRow,
956 A_SrcStartCol,
957 A_SrcStartRow,
958 A_SrcAlignment> &a,
959 const MatView<T,
960 B_NumCol,
961 B_NumRow,
962 B_SrcNumCol,
963 B_SrcNumRow,
964 B_SrcStartCol,
965 B_SrcStartRow,
966 B_SrcAlignment> &b)
967{
969}
970template<typename T,
971 int A_NumCol,
972 int A_NumRow,
973 int A_SrcNumCol,
974 int A_SrcNumRow,
975 int A_SrcStartCol,
976 int A_SrcStartRow,
977 int A_SrcAlignment,
978 int B_NumCol,
979 int B_NumRow>
981 A_NumCol,
982 A_NumRow,
983 A_SrcNumCol,
984 A_SrcNumRow,
985 A_SrcStartCol,
986 A_SrcStartRow,
987 A_SrcAlignment> &a,
989{
991}
992
993template<typename T,
994 int A_NumCol,
995 int A_NumRow,
996 int B_NumCol,
997 int B_NumRow,
998 int B_SrcNumCol,
999 int B_SrcNumRow,
1000 int B_SrcStartCol,
1001 int B_SrcStartRow,
1002 int B_SrcAlignment>
1004 const MatView<T,
1005 B_NumCol,
1006 B_NumRow,
1007 B_SrcNumCol,
1008 B_SrcNumRow,
1009 B_SrcStartCol,
1010 B_SrcStartRow,
1011 B_SrcAlignment> &b)
1012{
1014}
1015
1025
1026/* These types are reserved to wrap C matrices without copy. Note the un-alignment. */
1027/* TODO: It would be preferable to align all C matrices inside DNA structs. */
1028using float4x4_view = MatView<float, 4, 4, 4, 4, 0, 0, alignof(float)>;
1029using float4x4_mutableview = MutableMatView<float, 4, 4, 4, 4, 0, 0, alignof(float)>;
1030
1040
1041/* Specialization for SSE optimization. */
1042template<> float4x4 operator*(const float4x4 &a, const float4x4 &b);
1043template<> float3x3 operator*(const float3x3 &a, const float3x3 &b);
1044
1045extern template float2x2 operator*(const float2x2 &a, const float2x2 &b);
1046extern template double2x2 operator*(const double2x2 &a, const double2x2 &b);
1047extern template double3x3 operator*(const double3x3 &a, const double3x3 &b);
1048extern template double4x4 operator*(const double4x4 &a, const double4x4 &b);
1049
1050} // namespace blender
#define BLI_assert_msg(a, msg)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
#define T
MatBase< T, B_NumCol, A_NumRow > matrix_mul_impl(const MatA &a, const MatB &b)
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
MatBase< double, 4, 2 > double4x2
MatBase< float, 2, 2 > float2x2
MatBase< float, 2, 3 > float2x3
MatBase< float, 4, 4 > float4x4
MatBase< float, 2, 4 > float2x4
MatBase< double, 3, 3 > double3x3
MatBase< float, 3, 4 > float3x4
MatBase< double, 3, 4 > double3x4
MatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_view
MatBase< double, 2, 2 > double2x2
MatBase< float, 4, 2 > float4x2
MatBase< float, 3, 2 > float3x2
MatBase< float, 4, 3 > float4x3
MatBase< float, 3, 3 > float3x3
MutableMatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_mutableview
MatBase< double, 2, 4 > double2x4
MatBase< double, 3, 2 > double3x2
MatBase< double, 4, 3 > double4x3
void hash_unique_default(const T &value, UniqueHashBytes &hash)
MatBase< double, 2, 3 > double2x3
MatBase< T, B_NumCol, A_NumRow > operator*(const MatBase< T, A_NumCol, A_NumRow > &a, const MatBase< T, B_NumCol, B_NumRow > &b)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
MatBase< double, 4, 4 > double4x4
constexpr void unroll(Fn fn)
Definition BLI_unroll.hh:27
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
friend MatBase operator-(const MatBase &a)
MatBase(col_type _x, col_type _y, col_type _z, col_type _w)
static MatBase diagonal(T value)
friend MatBase operator*(const MatBase &a, T b)
MatBase(col_type _x, col_type _y)
friend MatBase operator-(T a, const MatBase &b)
friend MatBase operator+(T a, const MatBase &b)
MatBase(const MatBase< U, NumRow, NumCol > &vec)
VecBase< T, NumRow > col_type
MatBase(const T(*ptr)[NumCol])
col_type & operator[](int index)
T[NumCol][NumRow] c_style_mat
friend col_type operator*(const MatBase &a, const row_type &b)
MutableMatView< T, ViewNumCol, ViewNumRow, NumCol, NumRow, SrcStartCol, SrcStartRow, Alignment > view()
friend MatBase operator+(const MatBase &a, T b)
const vec3_type & z_axis() const
friend MatBase operator*(T a, const MatBase &b)
const vec3_type & x_axis() const
friend MatBase operator-(const MatBase &a, T b)
const col_type & operator[](int index) const
MatBase & operator*=(const MatBase &b) &
MatBase(col_type _x, col_type _y, col_type _z)
friend row_type operator*(const col_type &a, const MatBase &b)
friend MatBase operator+(const MatBase &a, const MatBase &b)
VecBase< T, 3 > vec3_type
friend std::ostream & operator<<(std::ostream &stream, const MatBase &mat)
VecBase< T,(NumRow< NumCol) ? NumRow :(NumRow - 1)> loc_type
MatBase & operator-=(const MatBase &b) &
MatBase()=default
VecBase< T, NumCol > row_type
friend MatBase operator-(const MatBase &a, const MatBase &b)
const vec3_type & y_axis() const
MatBase & operator+=(const MatBase &b) &
MatBase & operator+=(T b) &
MatBase(const MatBase< U, OtherNumCol, OtherNumRow > &other)
friend bool operator!=(const MatBase &a, const MatBase &b)
const MatView< T, ViewNumCol, ViewNumRow, NumCol, NumRow, SrcStartCol, SrcStartRow, Alignment > view() const
friend bool operator==(const MatBase &a, const MatBase &b)
static MatBase all(T value)
void hash_unique(UniqueHashBytes &hash) const
MatBase & operator-=(T b) &
MatBase & operator*=(T b) &
const loc_type & location() const
const T * base_ptr() const
static MatBase identity()
friend MatT operator-(const MatView &a, const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &b)
const col_type & operator[](int index) const
friend MatT operator-(const MatT &a, const MatView &b)
MatT operator*(const MatT &b) const
MatView(const SrcMatT &src)
friend MatT operator*(const MatView &a, T b)
MatBase< T, SrcNumCol, SrcNumRow, SrcAlignment > SrcMatT
friend bool operator!=(const MatView &a, const MatView &b)
friend MatT operator-(const MatView &a, T b)
friend MatT operator-(const MatView &a)
friend std::ostream & operator<<(std::ostream &stream, const MatView &mat)
friend col_type operator*(const MatView &a, const row_type &b)
MatBase< T, NumCol, NumRow > MatT
friend bool operator==(const MatView &a, const MatView &b)
friend MatT operator-(const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &a, const MatView &b)
friend row_type operator*(const col_type &a, const MatView &b)
friend MatT operator+(const MatView &a, T b)
friend MatT operator+(T a, const MatView &b)
friend MatT operator-(const MatView &a, const MatT &b)
MatView(const float(*src)[SrcNumRow])
VecBase< T, NumCol > row_type
friend MatT operator*(T a, const MatView &b)
VecBase< T, NumRow > col_type
friend MatView operator-(T a, const MatView &b)
friend col_type operator*(MutableMatView &a, const row_type &b)
friend row_type operator*(const col_type &a, MutableMatView &b)
MutableMatView & operator+=(const MatT &b) &
MutableMatView & operator*=(const MatT &b) &
col_type & operator[](int index)
MutableMatView & operator+=(T b) &
MatBase< T, NumCol, NumRow > MatT
MutableMatView & operator*=(const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &b) &
MutableMatView & operator+=(const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &b) &
MutableMatView & operator-=(const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &b) &
MutableMatView & operator=(const MatView< T, NumCol, NumRow, OtherSrcNumCol, OtherSrcNumRow, OtherSrcStartCol, OtherSrcStartRow, OtherSrcAlignment > &other)
MutableMatView(float src[SrcNumCol][SrcNumRow])
MutableMatView & operator-=(const MatT &b) &
MatBase< T, SrcNumCol, SrcNumRow, SrcAlignment > SrcMatT
MatView< T, NumCol, NumRow, SrcNumCol, SrcNumRow, SrcStartCol, SrcStartRow, SrcAlignment > MatViewT
MutableMatView & operator=(const MatT &other)
MutableMatView & operator*=(T b) &
MutableMatView & operator-=(T b) &