74 int Alignment = (((NumCol * NumRow) % 4 == 0) ? 4 : 1) *
sizeof(
T)>
82 static constexpr int min_dim = (NumRow < NumCol) ? NumRow : NumCol;
89#define BLI_ENABLE_IF_MAT(_size, _test) int S = _size, BLI_ENABLE_IF((S _test))
104 template<BLI_ENABLE_IF_MAT(NumCol, == 4)>
115 template<
typename U,
int OtherNumCol,
int OtherNumRow>
118 if constexpr ((OtherNumRow >= NumRow) && (OtherNumCol >= NumCol)) {
125 if (
i < OtherNumCol && j < OtherNumRow) {
126 (*this)[
i][j] = other[
i][j];
129 (*this)[
i][j] =
T(1);
132 (*this)[
i][j] =
T(0);
139#undef BLI_ENABLE_IF_MAT
148 template<
typename U, BLI_ENABLE_IF((std::is_convertible_v<U, T>))>
explicit MatBase(
const U *
ptr)
169 return *
reinterpret_cast<const c_style_mat *
>(
this);
181 return reinterpret_cast<const T *
>(
this);
187 return reinterpret_cast<T *
>(
this);
192 template<
int ViewNumCol = NumCol,
193 int ViewNumRow = NumRow,
203 template<
int ViewNumCol = NumCol,
204 int ViewNumRow = NumRow,
226 return reinterpret_cast<const col_type *
>(
this)[index];
233 return reinterpret_cast<col_type *
>(
this)[index];
242 return *
reinterpret_cast<vec3_type *
>(&(*this)[0]);
249 return *
reinterpret_cast<vec3_type *
>(&(*this)[1]);
256 return *
reinterpret_cast<vec3_type *
>(&(*this)[2]);
263 return *
reinterpret_cast<loc_type *
>(&(*this)[NumCol - 1]);
270 return *
reinterpret_cast<const vec3_type *
>(&(*this)[0]);
277 return *
reinterpret_cast<const vec3_type *
>(&(*this)[1]);
284 return *
reinterpret_cast<const vec3_type *
>(&(*this)[2]);
291 return *
reinterpret_cast<const loc_type *
>(&(*this)[NumCol - 1]);
421 for (
int i = 0;
i < NumCol;
i++) {
464 T value = (
reinterpret_cast<const T *
>(
this))[
i];
473 for (
int i = 0;
i < NumRow;
i++) {
475 for (
int j = 0; j < NumCol; j++) {
478 if (j < NumCol - 1) {
483 if (
i < NumRow - 1) {
518 BLI_STATIC_ASSERT(SrcStartCol >= 0,
"View does not fit source matrix dimensions");
519 BLI_STATIC_ASSERT(SrcStartRow >= 0,
"View does not fit source matrix dimensions");
521 "View does not fit source matrix dimensions");
523 "View does not fit source matrix dimensions");
527 explicit MatView(
const float (*src)[SrcNumRow])
536 return *
reinterpret_cast<const col_type *
>(&
mat[index + SrcStartCol][SrcStartRow]);
569 template<
int OtherSrcNumCol,
571 int OtherSrcStartCol,
572 int OtherSrcStartRow,
573 int OtherSrcAlignment>
582 OtherSrcAlignment> &
b)
594 template<
int OtherSrcNumCol,
596 int OtherSrcStartCol,
597 int OtherSrcStartRow,
598 int OtherSrcAlignment>
606 OtherSrcAlignment> &a,
635 return *
this *
b.view();
677 for (
int i = 0;
i < NumCol;
i++) {
694 return stream <<
mat.mat;
711 :
MatView<T, NumCol, NumRow, SrcNumCol, SrcNumRow, SrcStartCol, SrcStartRow, SrcAlignment> {
745 template<
int OtherSrcNumCol,
747 int OtherSrcStartCol,
748 int OtherSrcStartRow,
749 int OtherSrcAlignment>
757 OtherSrcAlignment> &other)
760 (
reinterpret_cast<const void *
>(&other.mat[0][0]) !=
761 reinterpret_cast<const void *
>(&this->mat[0][0])) ||
763 ((OtherSrcStartCol > SrcStartCol) || (OtherSrcStartCol + NumCol <= SrcStartCol) ||
764 (OtherSrcStartRow > SrcStartRow + NumRow) ||
765 (OtherSrcStartRow + NumRow <= SrcStartRow)),
766 "Operation is undefined if views overlap.");
773 *
this = other.
view();
779 template<
int OtherSrcNumCol,
781 int OtherSrcStartCol,
782 int OtherSrcStartRow,
783 int OtherSrcAlignment>
791 OtherSrcAlignment> &
b) &
799 return *
this +=
b.view();
808 template<
int OtherSrcNumCol,
810 int OtherSrcStartCol,
811 int OtherSrcStartRow,
812 int OtherSrcAlignment>
820 OtherSrcAlignment> &
b) &
828 return *
this -=
b.view();
838 template<
int OtherSrcNumCol,
840 int OtherSrcStartCol,
841 int OtherSrcStartRow,
842 int OtherSrcAlignment>
850 OtherSrcAlignment> &
b) &
852 *
this = *
static_cast<MatViewT *
>(
this) *
b;
858 return *
this *=
b.view();
902 static_assert(A_NumCol == B_NumRow);
917template<
typename T,
int A_NumCol,
int A_NumRow,
int B_NumCol,
int B_NumRow>
#define BLI_STATIC_ASSERT(a, msg)
#define BLI_assert_msg(a, msg)
unsigned long long int uint64_t
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
bool all(VecOp< bool, D >) RET
ccl_device_inline Extrema< T > operator*(const Extrema< T > a, const T b)
MatBase< T, B_NumCol, A_NumRow > matrix_mul_impl(const MatA &a, const MatB &b)
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
std::conditional_t< sizeof(T)==sizeof(uint8_t), uint8_t, std::conditional_t< sizeof(T)==sizeof(uint16_t), uint16_t, std::conditional_t< sizeof(T)==sizeof(uint32_t), uint32_t, std::conditional_t< sizeof(T)==sizeof(uint64_t), uint64_t, void > > > > as_uint_type
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
MatBase< double, 2, 3 > double2x3
MatBase< double, 4, 4 > double4x4
friend MatBase operator-(const MatBase &a)
static MatBase diagonal(T value)
friend MatBase operator*(const MatBase &a, T b)
friend MatBase operator-(T a, const MatBase &b)
friend MatBase operator+(T a, const MatBase &b)
MatBase(col_type _x, col_type _y, col_type _z)
static constexpr int col_len
MatBase(const MatBase< U, NumRow, NumCol > &vec)
VecBase< T, NumRow > col_type
MatBase(col_type _x, col_type _y, col_type _z, col_type _w)
static constexpr int row_len
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()
static constexpr int min_dim
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) &
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) &
const c_style_mat & ptr() const
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)
MatBase & operator-=(T b) &
MatBase & operator*=(T b) &
const loc_type & location() const
const T * base_ptr() const
static MatBase identity()
MatBase(col_type _x, col_type _y)
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(SrcMatT &src)
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) &
VecBase< T, NumCol > row_type
MutableMatView & operator-=(T b) &
VecBase< T, NumRow > col_type