22 #include <cuda/CudaGlobal.hpp> 29 # include <QTextStream> 35 enum MatrixLayout { C_STYLE, GL_STYLE };
44 template <
size_t nRows,
size_t nCols,
typename T =
double>
class Matrix {
50 typedef T& reference_type;
51 typedef const T& const_reference_type;
52 typedef T* pointer_type;
53 typedef const T* const_pointer_type;
57 static const size_t numcols = nCols;
58 static const size_t numrows = nRows;
66 for(
size_t i = 0; i < nRows; i++)
67 for(
size_t j = 0; j < nCols; j++)
78 for(
size_t i = 0; i < nRows; i++)
79 for(
size_t j = 0; j < nCols; j++)
80 rows[i][j] = T(mat(i, j));
90 for(
size_t i = 0; i < nRows; i++)
103 template <
typename T1> CU_HOST_DEVICE
Matrix(
const T1* values, MatrixLayout layout = C_STYLE)
107 for(
size_t i = 0; i < nRows; i++) {
112 for(
size_t j = 0; j < nCols; j++)
113 for(
size_t i = 0; i < nRows; i++) {
114 rows[i][j] = T(values[i + j * nRows]);
130 Matrix(
const T* values, MatrixLayout layout = C_STYLE)
134 for(
size_t i = 0; i < nRows; i++) {
139 for(
size_t i = 0; i < nRows; i++)
140 for(
size_t j = 0; j < nCols; j++) {
141 rows[i][j] = values[i + j * nRows];
155 for(
size_t i = 0; i < nRows; i++)
156 for(
size_t j = 0; j < nCols; j++)
157 rows[i][j] = (i == j) ? value : 0;
203 return rows[0].
data();
214 for(
size_t i = 0; i < nRows; i++)
215 ans.rows[i] = -rows[i];
228 for(
size_t i = 0; i < nRows; i++)
229 ans.rows[i] = rows[i] + mat.rows[i];
242 for(
size_t i = 0; i < nRows; i++)
243 ans.rows[i] = rows[i] - mat.rows[i];
256 for(
size_t i = 0; i < nRows; i++)
257 ans[i] = rows[i] * scalar;
270 for(
size_t i = 0; i < nRows; i++)
271 ans[i] = rows[i] / scalar;
284 for(
size_t i = 0; i < nRows; i++)
285 ans[i] = scalar * mat.rows[i];
297 for(
size_t i = 0; i < nRows; ++i) {
299 for(
size_t j = 0; j < nCols; ++j)
300 value += rows[i][j] * vec[j];
309 for(
size_t i = 0; i < nRows; i++)
310 rows[i] = mat.rows[i];
317 return ((*
this) = (*
this) + mat);
322 return ((*
this) = (*
this) - mat);
326 Matrix& operator*=(
const T& scalar) {
327 return ((*
this) = (*
this) * scalar);
331 Matrix& operator/=(
const T& scalar) {
332 return ((*
this) = (*
this) / scalar);
337 return ((*
this) = (*
this) * mat);
340 bool operator==(
const Matrix& mat)
const 342 for(
size_t i = 0; i < nRows; i++)
343 if(rows[i] != mat.rows[i])
350 bool operator!=(
const Matrix& mat)
const {
351 return (!((*
this) == mat));
357 for(
size_t i = 0; i < nRows; i++) {
368 for(
size_t i = 0; i < nRows && !in.
atEnd(); i++)
375 friend std::ostream& operator<<(std::ostream& out,
const Matrix& mat)
377 for(
size_t i = 0; i < nRows; i++) {
387 friend std::istream& operator>>(std::istream& in,
Matrix& mat)
389 for(
size_t i = 0; i < nRows && in; i++)
446 for(
size_t i = 0; i < nRows; i++)
447 for(
size_t j = 0; j < nCols; j++)
460 for(
size_t i = 0; i < nRows; ++i) {
461 for(
size_t j = 0; j < nCols; ++j) {
478 for(
size_t i = 0; i < nRows; ++i)
479 for(
size_t j = 0; j < nCols; ++j)
480 t[i][j] = rows[j][i];
493 T ca = std::cos(angle);
494 T sa = std::sin(angle);
499 r[0].set(ca + (1 - ca) * x * x, (1 - ca) * x * y - sa * z, (1 - ca) * z * x + sa * y);
500 r[1].set((1 - ca) * y * x + sa * z, ca + (1 - ca) * y * y, (1 - ca) * z * y - sa * x);
501 r[2].set((1 - ca) * x * z - sa * y, (1 - ca) * y * z + sa * x, ca + (1 - ca) * z * z);
514 T ca = std::cos(angle);
515 T sa = std::sin(angle);
517 T x = direction.
x() / direction.
t();
518 T y = direction.
y() / direction.
t();
519 T z = direction.
z() / direction.
t();
520 r[0].set(ca + (1 - ca) * x * x, (1 - ca) * x * y - sa * z, (1 - ca) * z * x + sa * y, 0);
521 r[1].set((1 - ca) * y * x + sa * z, ca + (1 - ca) * y * y, (1 - ca) * z * y - sa * x, 0);
522 r[2].set((1 - ca) * x * z - sa * y, (1 - ca) * y * z + sa * x, ca + (1 - ca) * z * z, 0);
523 r[3].set(0, 0, 0, 1);
534 for(
size_t i = 0; i < min(nRows, nCols); ++i) {
541 void fillArray(T* array, MatrixLayout layout = C_STYLE)
545 memcpy(array, &rows[0][0],
sizeof(T) * nRows * nCols);
549 for(
size_t c = 0; c < nCols; ++c)
550 for(
size_t r = 0; r < nRows; ++r, ++k)
551 array[k] = rows[r][c];
564 for(
size_t i = 0; i < nRows; ++i)
565 res[i] = (*
this)(i, i);
574 template <
size_t nRows,
size_t nCols,
typename T>
581 template <
size_t nRows,
size_t nSize,
size_t nCols,
typename T>
608 template <
size_t nRows,
typename T>
656 template <
size_t nRows,
size_t nCols,
typename T>
683 template <
size_t nRows,
size_t nCols,
typename T>
687 for(
size_t i = 0; i < nRows; ++i) {
690 for(
size_t j = 0; j < nCols; ++j) {
691 rrow[j] = (*fct)(mrow[j]);
702 template <
size_t nRows,
size_t nCols,
typename T>
706 for(
size_t i = 0; i < nRows; ++i) {
709 for(
size_t j = 0; j < nCols; ++j) {
710 rrow[j] = (*fct)(mrow[j]);
721 template <
size_t nRows,
size_t nCols,
typename T>
725 for(
size_t i = 0; i < nRows; ++i) {
728 for(
size_t j = 0; j < nCols; ++j) {
729 rrow[j] = (*fct)(mrow[j]);
740 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
744 for(
size_t i = 0; i < nRows; ++i) {
747 for(
size_t j = 0; j < nCols; ++j) {
748 rrow[j] = (*fct)(mrow[j]);
759 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
763 for(
size_t i = 0; i < nRows; ++i) {
766 for(
size_t j = 0; j < nCols; ++j) {
767 rrow[j] = (*fct)(mrow[j]);
778 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
782 for(
size_t i = 0; i < nRows; ++i) {
785 for(
size_t j = 0; j < nCols; ++j) {
786 rrow[j] = (*fct)(mrow[j]);
797 template <
size_t nRows,
size_t nCols,
typename T>
802 for(
size_t i = 0; i < nRows; ++i) {
806 for(
size_t j = 0; j < nCols; ++j) {
807 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
818 template <
size_t nRows,
size_t nCols,
typename T>
823 for(
size_t i = 0; i < nRows; ++i) {
827 for(
size_t j = 0; j < nCols; ++j) {
828 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
839 template <
size_t nRows,
size_t nCols,
typename T>
844 for(
size_t i = 0; i < nRows; ++i) {
848 for(
size_t j = 0; j < nCols; ++j) {
849 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
860 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
865 for(
size_t i = 0; i < nRows; ++i) {
869 for(
size_t j = 0; j < nCols; ++j) {
870 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
881 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
886 for(
size_t i = 0; i < nRows; ++i) {
890 for(
size_t j = 0; j < nCols; ++j) {
891 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
902 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
907 for(
size_t i = 0; i < nRows; ++i) {
911 for(
size_t j = 0; j < nCols; ++j) {
912 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
918 template <
size_t nRows,
size_t nCols,
typename T>
922 for(
size_t i = 0; i < nCols; ++i) {
924 for(
size_t j = 0; j < nRows; ++j)
925 value += mat(j, i) * vec[j];
931 template <
size_t nRows,
size_t intSize,
size_t nCols,
typename T>
936 for(
size_t i = 0; i < nRows; i++)
937 for(
size_t j = 0; j < nCols; j++) {
939 for(
size_t k = 0; k < intSize; k++)
940 acc += mat1(i, k) * mat2(k, j);
952 return mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0);
957 return mat(0, 0) * mat(1, 1) * mat(2, 2) + mat(0, 1) * mat(1, 2) * mat(2, 0) + mat(0, 2) * mat(1, 0) * mat(2, 1)
958 - mat(0, 0) * mat(1, 2) * mat(2, 1) - mat(0, 1) * mat(1, 0) * mat(2, 2) - mat(0, 2) * mat(1, 1) * mat(2, 0);
965 for(
size_t i = 0; i < nRows; i++) {
966 acc += mat(i, 0) *
cofactor(mat, i, 0);
971 template <
size_t nRows,
typename T>
975 Matrix<nRows - 1, nRows - 1, T> ans;
976 for(
size_t i1 = 0, i2 = 0; i1 < nRows; i1++, i2++) {
980 for(
size_t j1 = 0, j2 = 0; j1 < nRows; j1++, j2++) {
984 ans(i2, j2) = mat(i1, j1);
998 return inv * matrix_minor(mat, i, j);
1004 ans[0][0] = 1 / mat(0, 0);
1015 ans(0, 0) = mat(1, 1) / d;
1016 ans(0, 1) = mat(0, 1) / -d;
1017 ans(1, 0) = mat(1, 0) / -d;
1018 ans(1, 1) = mat(0, 0) / d;
1029 ans(0, 0) = (mat(1, 1) * mat(2, 2) - mat(1, 2) * mat(2, 1)) / d;
1030 ans(1, 1) = (mat(0, 0) * mat(2, 2) - mat(0, 2) * mat(2, 0)) / d;
1031 ans(2, 2) = (mat(1, 1) * mat(0, 0) - mat(1, 0) * mat(0, 1)) / d;
1032 ans(1, 0) = (mat(1, 2) * mat(2, 0) - mat(1, 0) * mat(2, 2)) / d;
1033 ans(0, 1) = (mat(2, 1) * mat(0, 2) - mat(0, 1) * mat(2, 2)) / d;
1034 ans(2, 0) = (mat(1, 0) * mat(2, 1) - mat(1, 1) * mat(2, 0)) / d;
1035 ans(0, 2) = (mat(0, 1) * mat(1, 2) - mat(1, 1) * mat(0, 2)) / d;
1036 ans(1, 2) = (mat(0, 2) * mat(1, 0) - mat(0, 0) * mat(1, 2)) / d;
1037 ans(2, 1) = (mat(2, 0) * mat(0, 1) - mat(0, 0) * mat(2, 1)) / d;
1045 inv(0, 0) = (m(1, 1) * m(2, 2) * m(3, 3) - m(1, 1) * m(3, 2) * m(2, 3) - m(1, 2) * m(2, 1) * m(3, 3)
1046 + m(1, 2) * m(3, 1) * m(2, 3) + m(1, 3) * m(2, 1) * m(3, 2) - m(1, 3) * m(3, 1) * m(2, 2));
1048 inv(0, 1) = (-m(0, 1) * m(2, 2) * m(3, 3) + m(0, 1) * m(3, 2) * m(2, 3) + m(0, 2) * m(2, 1) * m(3, 3)
1049 - m(0, 2) * m(3, 1) * m(2, 3) - m(0, 3) * m(2, 1) * m(3, 2) + m(0, 3) * m(3, 1) * m(2, 2));
1051 inv(0, 2) = (m(0, 1) * m(1, 2) * m(3, 3) - m(0, 1) * m(3, 2) * m(1, 3) - m(0, 2) * m(1, 1) * m(3, 3)
1052 + m(0, 2) * m(3, 1) * m(1, 3) + m(0, 3) * m(1, 1) * m(3, 2) - m(0, 3) * m(3, 1) * m(1, 2));
1054 inv(0, 3) = (-m(0, 1) * m(1, 2) * m(2, 3) + m(0, 1) * m(2, 2) * m(1, 3) + m(0, 2) * m(1, 1) * m(2, 3)
1055 - m(0, 2) * m(2, 1) * m(1, 3) - m(0, 3) * m(1, 1) * m(2, 2) + m(0, 3) * m(2, 1) * m(1, 2));
1057 inv(1, 0) = (-m(1, 0) * m(2, 2) * m(3, 3) + m(1, 0) * m(3, 2) * m(2, 3) + m(1, 2) * m(2, 0) * m(3, 3)
1058 - m(1, 2) * m(3, 0) * m(2, 3) - m(1, 3) * m(2, 0) * m(3, 2) + m(1, 3) * m(3, 0) * m(2, 2));
1060 inv(1, 1) = (m(0, 0) * m(2, 2) * m(3, 3) - m(0, 0) * m(3, 2) * m(2, 3) - m(0, 2) * m(2, 0) * m(3, 3)
1061 + m(0, 2) * m(3, 0) * m(2, 3) + m(0, 3) * m(2, 0) * m(3, 2) - m(0, 3) * m(3, 0) * m(2, 2));
1063 inv(1, 2) = (-m(0, 0) * m(1, 2) * m(3, 3) + m(0, 0) * m(3, 2) * m(1, 3) + m(0, 2) * m(1, 0) * m(3, 3)
1064 - m(0, 2) * m(3, 0) * m(1, 3) - m(0, 3) * m(1, 0) * m(3, 2) + m(0, 3) * m(3, 0) * m(1, 2));
1066 inv(1, 3) = (m(0, 0) * m(1, 2) * m(2, 3) - m(0, 0) * m(2, 2) * m(1, 3) - m(0, 2) * m(1, 0) * m(2, 3)
1067 + m(0, 2) * m(2, 0) * m(1, 3) + m(0, 3) * m(1, 0) * m(2, 2) - m(0, 3) * m(2, 0) * m(1, 2));
1069 inv(2, 0) = (m(1, 0) * m(2, 1) * m(3, 3) - m(1, 0) * m(3, 1) * m(2, 3) - m(1, 1) * m(2, 0) * m(3, 3)
1070 + m(1, 1) * m(3, 0) * m(2, 3) + m(1, 3) * m(2, 0) * m(3, 1) - m(1, 3) * m(3, 0) * m(2, 1));
1072 inv(2, 1) = (-m(0, 0) * m(2, 1) * m(3, 3) + m(0, 0) * m(3, 1) * m(2, 3) + m(0, 1) * m(2, 0) * m(3, 3)
1073 - m(0, 1) * m(3, 0) * m(2, 3) - m(0, 3) * m(2, 0) * m(3, 1) + m(0, 3) * m(3, 0) * m(2, 1));
1075 inv(2, 2) = (m(0, 0) * m(1, 1) * m(3, 3) - m(0, 0) * m(3, 1) * m(1, 3) - m(0, 1) * m(1, 0) * m(3, 3)
1076 + m(0, 1) * m(3, 0) * m(1, 3) + m(0, 3) * m(1, 0) * m(3, 1) - m(0, 3) * m(3, 0) * m(1, 1));
1078 inv(2, 3) = (-m(0, 0) * m(1, 1) * m(2, 3) + m(0, 0) * m(2, 1) * m(1, 3) + m(0, 1) * m(1, 0) * m(2, 3)
1079 - m(0, 1) * m(2, 0) * m(1, 3) - m(0, 3) * m(1, 0) * m(2, 1) + m(0, 3) * m(2, 0) * m(1, 1));
1081 inv(3, 0) = (-m(1, 0) * m(2, 1) * m(3, 2) + m(1, 0) * m(3, 1) * m(2, 2) + m(1, 1) * m(2, 0) * m(3, 2)
1082 - m(1, 1) * m(3, 0) * m(2, 2) - m(1, 2) * m(2, 0) * m(3, 1) + m(1, 2) * m(3, 0) * m(2, 1));
1084 inv(3, 1) = (m(0, 0) * m(2, 1) * m(3, 2) - m(0, 0) * m(3, 1) * m(2, 2) - m(0, 1) * m(2, 0) * m(3, 2)
1085 + m(0, 1) * m(3, 0) * m(2, 2) + m(0, 2) * m(2, 0) * m(3, 1) - m(0, 2) * m(3, 0) * m(2, 1));
1087 inv(3, 2) = (-m(0, 0) * m(1, 1) * m(3, 2) + m(0, 0) * m(3, 1) * m(1, 2) + m(0, 1) * m(1, 0) * m(3, 2)
1088 - m(0, 1) * m(3, 0) * m(1, 2) - m(0, 2) * m(1, 0) * m(3, 1) + m(0, 2) * m(3, 0) * m(1, 1));
1090 inv(3, 3) = (m(0, 0) * m(1, 1) * m(2, 2) - m(0, 0) * m(2, 1) * m(1, 2) - m(0, 1) * m(1, 0) * m(2, 2)
1091 + m(0, 1) * m(2, 0) * m(1, 2) + m(0, 2) * m(1, 0) * m(2, 1) - m(0, 2) * m(2, 0) * m(1, 1));
1093 T det = m(0, 0) * inv(0, 0) + m(1, 0) * inv(0, 1) + m(2, 0) * inv(0, 2) + m(3, 0) * inv(0, 3);
1095 T inv_det = 1.0 /
det;
1097 return inv_det * inv;
1106 for(
size_t i = 0; i < nRows; ++i)
1107 for(
size_t j = 0; j < nRows; ++j) {
1108 ans(i, j) =
cofactor(mat, j, i) / d;
1113 template <
size_t nRows,
size_t nCols,
typename T>
1117 for(
size_t i = 0; i < nRows; i++)
1118 for(
size_t j = 0; j < nCols; j++)
1119 ans(j, i) = mat(i, j);
1126 for(
size_t i = 0; i < nRows; i++)
1127 for(
size_t j = 0; j < nCols; j++) {
1128 const T& v = mat(i, j);
1136 return std::sqrt(
normsq(mat));
CU_HOST_DEVICE Matrix & zero(void)
Set the matrix to all zero.
Definition: Matrix.hpp:444
CU_HOST_DEVICE void t(const T &v)
Short access to the fourth element.
Definition: Vector.hpp:688
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:722
CU_HOST_DEVICE T cofactor(const Matrix< nRows, nRows, T > &mat, size_t i, size_t j)
Returns the cofactor of the matrix for position (i,j)
Definition: Matrix.hpp:992
CU_HOST_DEVICE Matrix(const T1 *values, MatrixLayout layout=C_STYLE)
Fill in the matrix with the values.
Definition: Matrix.hpp:103
CU_HOST_DEVICE const T * c_data() const
Returns a constant raw pointer on the data.
Definition: Vector.hpp:272
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:882
CU_HOST_DEVICE friend Matrix operator*(const T &scalar, const Matrix &mat)
Matrix-scalar multiplication.
Definition: Matrix.hpp:280
CU_HOST_DEVICE T operator()(size_t i, size_t j) const
Return the value at row i, column j.
Definition: Matrix.hpp:426
CU_HOST_DEVICE Matrix operator-(void) const
Matrix subtraction.
Definition: Matrix.hpp:210
CU_HOST_DEVICE Matrix & operator=(const T &value)
Set the matrix to a diagonal matrix.
Definition: Matrix.hpp:458
static CU_HOST_DEVICE Matrix< 4, 4, T > rotation(const Vector< 4, T > &direction, T angle)
Creates the 4x4 matrix corresponding to a rotation.
Definition: Matrix.hpp:512
CU_HOST_DEVICE T trace() const
Trace of the matrix.
Definition: Matrix.hpp:531
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:661
CU_HOST_DEVICE const T * c_data() const
Returns a constant raw pointer on the data.
Definition: Matrix.hpp:192
CU_HOST_DEVICE Vector< nCols, T > & operator[](size_t idx)
Returns the nth row.
Definition: Matrix.hpp:400
static CU_HOST_DEVICE Matrix< 3, 3, T > rotation(const Vector< 3, T > &direction, T angle)
Creates the 3x3 matrix corresponding to a rotation.
Definition: Matrix.hpp:491
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(const T &(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:840
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:779
static CU_HOST_DEVICE size_t nbRows()
Returns the number of rows of the matrix.
Definition: Matrix.hpp:174
CU_HOST_DEVICE Matrix(const Vector< nCols, T1 > *vecs)
Fill the matrix with the array of vectors.
Definition: Matrix.hpp:88
T CU_HOST_DEVICE det(const Matrix< 1, 1, T > &mat)
Determinant of the matrix.
Definition: Matrix.hpp:946
CU_HOST_DEVICE Matrix(const Matrix< nRows, nCols, T1 > &mat)
Copy a matrix.
Definition: Matrix.hpp:76
static CU_HOST_DEVICE Vector< 2, size_t > size()
Returns the size of the matrix.
Definition: Matrix.hpp:166
CU_HOST_DEVICE T * data()
Returns a raw pointer on the data.
Definition: Matrix.hpp:202
static CU_HOST_DEVICE size_t nbColumns()
Returns the number of columns of the matrix.
Definition: Matrix.hpp:182
CU_HOST_DEVICE Matrix(const T &value)
Create a diagonal matrix.
Definition: Matrix.hpp:153
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(T1), const Matrix< nRows, nCols, T1 > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:760
CU_HOST_DEVICE Matrix(const T *values, MatrixLayout layout=C_STYLE)
Fill in the matrix with the values.
Definition: Matrix.hpp:130
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(T, T), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:798
CU_HOST_DEVICE Matrix operator*(const T &scalar) const
Matrix-scalar multiplication.
Definition: Matrix.hpp:252
CU_HOST_DEVICE Matrix operator+(const Matrix &mat) const
Matrix addition.
Definition: Matrix.hpp:224
CU_HOST_DEVICE T * data()
Returns a raw pointer on the data.
Definition: Vector.hpp:234
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:670
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(const T &(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:741
CU_HOST_DEVICE Vector< nRows, T > diag() const
Return the diagonal vector, if the matrix is square.
Definition: Matrix.hpp:560
CU_HOST_DEVICE Matrix< nCols, nRows, T > transpose(const Matrix< nRows, nCols, T > &mat)
Transpose a matrix.
Definition: Matrix.hpp:1114
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(const T &(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:903
CU_HOST_DEVICE Matrix< nCols, nRows, T > operator~()
Transpose the matrix.
Definition: Matrix.hpp:475
#define STATIC_ASSERT(B)
Assertion that works at compile time.
Definition: StaticAssert.hpp:57
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(const T &(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:684
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(T), const Matrix< nRows, nCols, T > &m)
Apply a unary function to each element of the matrix.
Definition: Matrix.hpp:703
static CU_HOST_DEVICE Matrix identity()
Returns an identity matrix.
Definition: Matrix.hpp:434
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(T1, T2), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:861
Define the STATIC_ASSERT macro.
Class representing a fixed-size matrix.
Definition: Matrix.hpp:44
Common definitions and utilities This file is shared by cuda, do not include headers that nvcc can't ...
CU_HOST_DEVICE T & operator()(size_t i, size_t j)
Return the value at row i, column j.
Definition: Matrix.hpp:418
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:679
CU_HOST_DEVICE T norm(const Matrix< nRows, nCols, T > &mat)
Return the norm of the matrix.
Definition: Matrix.hpp:1134
CU_HOST_DEVICE Matrix operator/(const T &scalar) const
Matrix-scalar division.
Definition: Matrix.hpp:266
CU_HOST_DEVICE Matrix(void)
Create a matrix filled with 0s.
Definition: Matrix.hpp:64
CU_HOST_DEVICE T normsq(const Matrix< nRows, nCols, T > &mat)
Return the square norm of the matrix.
Definition: Matrix.hpp:1123
CU_HOST_DEVICE Vector< nCols, T > operator[](size_t idx) const
Returns the nth row.
Definition: Matrix.hpp:410
CU_HOST_DEVICE Matrix< 1, 1, T > inverse(const Matrix< 1, 1, T > &mat)
Inverse the matrix.
Definition: Matrix.hpp:1001
CU_HOST_DEVICE Matrix< nRows, nCols, T > map(T(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
Apply a binary function to each element of the matrix.
Definition: Matrix.hpp:819
CU_HOST_DEVICE Vector< nRows, T > operator*(const Vector< nCols, T > &vec) const
Matrix*Column Vector.
Definition: Matrix.hpp:294
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can't...