12 #include <cuda/CudaGlobal.hpp>
19 # include <QTextStream>
25 enum MatrixLayout { C_STYLE, GL_STYLE };
34 template <
size_t nRows,
size_t nCols,
typename T =
double>
class Matrix {
40 typedef T& reference_type;
41 typedef const T& const_reference_type;
42 typedef T* pointer_type;
43 typedef const T* const_pointer_type;
47 static const size_t numcols = nCols;
48 static const size_t numrows = nRows;
56 for(
size_t i = 0; i < nRows; i++)
57 for(
size_t j = 0; j < nCols; j++)
68 for(
size_t i = 0; i < nRows; i++)
69 for(
size_t j = 0; j < nCols; j++)
70 rows[i][j] = T(mat(i, j));
80 for(
size_t i = 0; i < nRows; i++)
93 template <
typename T1> CU_HOST_DEVICE
Matrix(
const T1* values, MatrixLayout layout = C_STYLE)
97 for(
size_t i = 0; i < nRows; i++) {
102 for(
size_t j = 0; j < nCols; j++)
103 for(
size_t i = 0; i < nRows; i++) {
104 rows[i][j] = T(values[i + j * nRows]);
120 Matrix(
const T* values, MatrixLayout layout = C_STYLE)
124 for(
size_t i = 0; i < nRows; i++) {
129 for(
size_t i = 0; i < nRows; i++)
130 for(
size_t j = 0; j < nCols; j++) {
131 rows[i][j] = values[i + j * nRows];
145 for(
size_t i = 0; i < nRows; i++)
146 for(
size_t j = 0; j < nCols; j++)
147 rows[i][j] = (i == j) ? value : 0;
193 return rows[0].
data();
204 for(
size_t i = 0; i < nRows; i++)
205 ans.rows[i] = -rows[i];
218 for(
size_t i = 0; i < nRows; i++)
219 ans.rows[i] = rows[i] + mat.rows[i];
232 for(
size_t i = 0; i < nRows; i++)
233 ans.rows[i] = rows[i] - mat.rows[i];
246 for(
size_t i = 0; i < nRows; i++)
247 ans[i] = rows[i] * scalar;
260 for(
size_t i = 0; i < nRows; i++)
261 ans[i] = rows[i] / scalar;
274 for(
size_t i = 0; i < nRows; i++)
275 ans[i] = scalar * mat.rows[i];
287 for(
size_t i = 0; i < nRows; ++i) {
289 for(
size_t j = 0; j < nCols; ++j)
290 value += rows[i][j] * vec[j];
299 for(
size_t i = 0; i < nRows; i++)
300 rows[i] = mat.rows[i];
307 return ((*
this) = (*
this) + mat);
312 return ((*
this) = (*
this) - mat);
316 Matrix& operator*=(
const T& scalar) {
317 return ((*
this) = (*
this) * scalar);
321 Matrix& operator/=(
const T& scalar) {
322 return ((*
this) = (*
this) / scalar);
327 return ((*
this) = (*
this) * mat);
330 bool operator==(
const Matrix& mat)
const
332 for(
size_t i = 0; i < nRows; i++)
333 if(rows[i] != mat.rows[i])
340 bool operator!=(
const Matrix& mat)
const {
341 return (!((*
this) == mat));
347 for(
size_t i = 0; i < nRows; i++) {
358 for(
size_t i = 0; i < nRows && !in.
atEnd(); i++)
365 friend std::ostream& operator<<(std::ostream& out,
const Matrix& mat)
367 for(
size_t i = 0; i < nRows; i++) {
377 friend std::istream& operator>>(std::istream& in,
Matrix& mat)
379 for(
size_t i = 0; i < nRows && in; i++)
436 for(
size_t i = 0; i < nRows; i++)
437 for(
size_t j = 0; j < nCols; j++)
450 for(
size_t i = 0; i < nRows; ++i) {
451 for(
size_t j = 0; j < nCols; ++j) {
468 for(
size_t i = 0; i < nRows; ++i)
469 for(
size_t j = 0; j < nCols; ++j)
470 t[i][j] = rows[j][i];
483 T ca = std::cos(angle);
484 T sa = std::sin(angle);
489 r[0].set(ca + (1 - ca) * x * x, (1 - ca) * x * y - sa * z, (1 - ca) * z * x + sa * y);
490 r[1].set((1 - ca) * y * x + sa * z, ca + (1 - ca) * y * y, (1 - ca) * z * y - sa * x);
491 r[2].set((1 - ca) * x * z - sa * y, (1 - ca) * y * z + sa * x, ca + (1 - ca) * z * z);
504 T ca = std::cos(angle);
505 T sa = std::sin(angle);
507 T x = direction.
x() / direction.
t();
508 T y = direction.
y() / direction.
t();
509 T z = direction.
z() / direction.
t();
510 r[0].set(ca + (1 - ca) * x * x, (1 - ca) * x * y - sa * z, (1 - ca) * z * x + sa * y, 0);
511 r[1].set((1 - ca) * y * x + sa * z, ca + (1 - ca) * y * y, (1 - ca) * z * y - sa * x, 0);
512 r[2].set((1 - ca) * x * z - sa * y, (1 - ca) * y * z + sa * x, ca + (1 - ca) * z * z, 0);
513 r[3].set(0, 0, 0, 1);
524 for(
size_t i = 0; i < min(nRows, nCols); ++i) {
531 void fillArray(T* array, MatrixLayout layout = C_STYLE)
535 memcpy(array, &rows[0][0],
sizeof(T) * nRows * nCols);
539 for(
size_t c = 0; c < nCols; ++c)
540 for(
size_t r = 0; r < nRows; ++r, ++k)
541 array[k] = rows[r][c];
554 for(
size_t i = 0; i < nRows; ++i)
555 res[i] = (*
this)(i, i);
564 template <
size_t nRows,
size_t nCols,
typename T>
565 CU_HOST_DEVICE Vector<nCols, T> operator*(
const Vector<nCols, T>& vec,
const Matrix<nRows, nCols, T>& mat);
571 template <
size_t nRows,
size_t nSize,
size_t nCols,
typename T>
572 CU_HOST_DEVICE Matrix<nRows, nCols, T> operator*(
const Matrix<nRows, nSize, T>& mat1,
573 const Matrix<nSize, nCols, T>&
mat2);
579 template <
typename T> T CU_HOST_DEVICE det(
const Matrix<1, 1, T>& mat);
584 template <
typename T> T CU_HOST_DEVICE det(
const Matrix<2, 2, T>& mat);
589 template <
typename T> T CU_HOST_DEVICE det(
const Matrix<3, 3, T>& mat);
596 template <
size_t nRows,
typename T> T CU_HOST_DEVICE det(
const Matrix<nRows, nRows, T>& mat);
598 template <
size_t nRows,
typename T>
599 CU_HOST_DEVICE T matrix_minor(
const Matrix<nRows, nRows, T>& mat,
size_t i,
size_t j);
605 template <
size_t nRows,
typename T> CU_HOST_DEVICE T cofactor(
const Matrix<nRows, nRows, T>& mat,
size_t i,
size_t j);
612 template <
typename T> CU_HOST_DEVICE Matrix<1, 1, T> inverse(
const Matrix<1, 1, T>& mat);
618 template <
typename T> CU_HOST_DEVICE Matrix<2, 2, T> inverse(
const Matrix<2, 2, T>& mat);
624 template <
typename T> CU_HOST_DEVICE Matrix<3, 3, T> inverse(
const Matrix<3, 3, T>& mat);
630 template <
typename T> CU_HOST_DEVICE Matrix<4, 4, T> inverse(
const Matrix<4, 4, T>& mat);
639 template <
size_t nRows,
typename T> CU_HOST_DEVICE Matrix<nRows, nRows, T> inverse(
const Matrix<nRows, nRows, T>& mat);
646 template <
size_t nRows,
size_t nCols,
typename T>
647 CU_HOST_DEVICE Matrix<nCols, nRows, T> transpose(
const Matrix<nRows, nCols, T>& mat);
657 template <
size_t nRows,
size_t nCols,
typename T> CU_HOST_DEVICE T norm(
const Matrix<nRows, nCols, T>& mat);
666 template <
size_t nRows,
size_t nCols,
typename T> CU_HOST_DEVICE T normsq(
const Matrix<nRows, nCols, T>& mat);
673 template <
size_t nRows,
size_t nCols,
typename T>
677 for(
size_t i = 0; i < nRows; ++i) {
680 for(
size_t j = 0; j < nCols; ++j) {
681 rrow[j] = (*fct)(mrow[j]);
692 template <
size_t nRows,
size_t nCols,
typename T>
696 for(
size_t i = 0; i < nRows; ++i) {
699 for(
size_t j = 0; j < nCols; ++j) {
700 rrow[j] = (*fct)(mrow[j]);
711 template <
size_t nRows,
size_t nCols,
typename T>
715 for(
size_t i = 0; i < nRows; ++i) {
718 for(
size_t j = 0; j < nCols; ++j) {
719 rrow[j] = (*fct)(mrow[j]);
730 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
734 for(
size_t i = 0; i < nRows; ++i) {
737 for(
size_t j = 0; j < nCols; ++j) {
738 rrow[j] = (*fct)(mrow[j]);
749 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
753 for(
size_t i = 0; i < nRows; ++i) {
756 for(
size_t j = 0; j < nCols; ++j) {
757 rrow[j] = (*fct)(mrow[j]);
768 template <
size_t nRows,
size_t nCols,
typename T,
typename T1>
772 for(
size_t i = 0; i < nRows; ++i) {
775 for(
size_t j = 0; j < nCols; ++j) {
776 rrow[j] = (*fct)(mrow[j]);
787 template <
size_t nRows,
size_t nCols,
typename T>
792 for(
size_t i = 0; i < nRows; ++i) {
796 for(
size_t j = 0; j < nCols; ++j) {
797 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
808 template <
size_t nRows,
size_t nCols,
typename T>
813 for(
size_t i = 0; i < nRows; ++i) {
817 for(
size_t j = 0; j < nCols; ++j) {
818 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
829 template <
size_t nRows,
size_t nCols,
typename T>
834 for(
size_t i = 0; i < nRows; ++i) {
838 for(
size_t j = 0; j < nCols; ++j) {
839 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
850 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
855 for(
size_t i = 0; i < nRows; ++i) {
859 for(
size_t j = 0; j < nCols; ++j) {
860 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
871 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
876 for(
size_t i = 0; i < nRows; ++i) {
880 for(
size_t j = 0; j < nCols; ++j) {
881 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
892 template <
size_t nRows,
size_t nCols,
typename T,
typename T1,
typename T2>
897 for(
size_t i = 0; i < nRows; ++i) {
901 for(
size_t j = 0; j < nCols; ++j) {
902 rrow[j] = (*fct)(mrow1[j], mrow2[j]);
908 template <
size_t nRows,
size_t nCols,
typename T>
912 for(
size_t i = 0; i < nCols; ++i) {
914 for(
size_t j = 0; j < nRows; ++j)
915 value += mat(j, i) * vec[j];
921 template <
size_t nRows,
size_t intSize,
size_t nCols,
typename T>
926 for(
size_t i = 0; i < nRows; i++)
927 for(
size_t j = 0; j < nCols; j++) {
929 for(
size_t k = 0; k < intSize; k++)
930 acc += mat1(i, k) * mat2(k, j);
942 return mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0);
947 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)
948 - 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);
955 for(
size_t i = 0; i < nRows; i++) {
956 acc += mat(i, 0) * cofactor(mat, i, 0);
961 template <
size_t nRows,
typename T>
965 Matrix<nRows - 1, nRows - 1, T> ans;
966 for(
size_t i1 = 0, i2 = 0; i1 < nRows; i1++, i2++) {
970 for(
size_t j1 = 0, j2 = 0; j1 < nRows; j1++, j2++) {
974 ans(i2, j2) = mat(i1, j1);
988 return inv * matrix_minor(mat, i, j);
994 ans[0][0] = 1 / mat(0, 0);
1005 ans(0, 0) = mat(1, 1) / d;
1006 ans(0, 1) = mat(0, 1) / -d;
1007 ans(1, 0) = mat(1, 0) / -d;
1008 ans(1, 1) = mat(0, 0) / d;
1019 ans(0, 0) = (mat(1, 1) * mat(2, 2) - mat(1, 2) * mat(2, 1)) / d;
1020 ans(1, 1) = (mat(0, 0) * mat(2, 2) - mat(0, 2) * mat(2, 0)) / d;
1021 ans(2, 2) = (mat(1, 1) * mat(0, 0) - mat(1, 0) * mat(0, 1)) / d;
1022 ans(1, 0) = (mat(1, 2) * mat(2, 0) - mat(1, 0) * mat(2, 2)) / d;
1023 ans(0, 1) = (mat(2, 1) * mat(0, 2) - mat(0, 1) * mat(2, 2)) / d;
1024 ans(2, 0) = (mat(1, 0) * mat(2, 1) - mat(1, 1) * mat(2, 0)) / d;
1025 ans(0, 2) = (mat(0, 1) * mat(1, 2) - mat(1, 1) * mat(0, 2)) / d;
1026 ans(1, 2) = (mat(0, 2) * mat(1, 0) - mat(0, 0) * mat(1, 2)) / d;
1027 ans(2, 1) = (mat(2, 0) * mat(0, 1) - mat(0, 0) * mat(2, 1)) / d;
1035 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)
1036 + 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));
1038 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)
1039 - 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));
1041 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)
1042 + 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));
1044 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)
1045 - 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));
1047 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)
1048 - 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));
1050 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)
1051 + 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));
1053 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)
1054 - 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));
1056 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)
1057 + 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));
1059 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)
1060 + 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));
1062 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)
1063 - 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));
1065 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)
1066 + 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));
1068 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)
1069 - 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));
1071 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)
1072 - 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));
1074 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)
1075 + 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));
1077 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)
1078 - 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));
1080 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)
1081 + 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));
1083 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);
1085 T inv_det = 1.0 / det;
1087 return inv_det * inv;
1096 for(
size_t i = 0; i < nRows; ++i)
1097 for(
size_t j = 0; j < nRows; ++j) {
1098 ans(i, j) = cofactor(mat, j, i) / d;
1103 template <
size_t nRows,
size_t nCols,
typename T>
1107 for(
size_t i = 0; i < nRows; i++)
1108 for(
size_t j = 0; j < nCols; j++)
1109 ans(j, i) = mat(i, j);
1116 for(
size_t i = 0; i < nRows; i++)
1117 for(
size_t j = 0; j < nCols; j++) {
1118 const T& v = mat(i, j);
1126 return std::sqrt(normsq(mat));
CU_HOST_DEVICE Matrix & zero(void)
Set the matrix to all zero.
Definition: Matrix.hpp:434
CU_HOST_DEVICE void t(const T &v)
Short access to the fourth element.
Definition: Vector.hpp:678
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:712
CU_HOST_DEVICE Matrix(const T1 *values, MatrixLayout layout=C_STYLE)
Fill in the matrix with the values.
Definition: Matrix.hpp:93
CU_HOST_DEVICE const T * c_data() const
Returns a constant raw pointer on the data.
Definition: Vector.hpp:262
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:872
CU_HOST_DEVICE friend Matrix operator*(const T &scalar, const Matrix &mat)
Matrix-scalar multiplication.
Definition: Matrix.hpp:270
CU_HOST_DEVICE T operator()(size_t i, size_t j) const
Return the value at row i, column j.
Definition: Matrix.hpp:416
CU_HOST_DEVICE Matrix operator-(void) const
Matrix subtraction.
Definition: Matrix.hpp:200
CU_HOST_DEVICE Matrix & operator=(const T &value)
Set the matrix to a diagonal matrix.
Definition: Matrix.hpp:448
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:502
CU_HOST_DEVICE T trace() const
Trace of the matrix.
Definition: Matrix.hpp:521
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:651
CU_HOST_DEVICE const T * c_data() const
Returns a constant raw pointer on the data.
Definition: Matrix.hpp:182
CU_HOST_DEVICE Vector< nCols, T > & operator[](size_t idx)
Returns the nth row.
Definition: Matrix.hpp:390
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:481
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:830
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:769
static CU_HOST_DEVICE size_t nbRows()
Returns the number of rows of the matrix.
Definition: Matrix.hpp:164
CU_HOST_DEVICE Matrix(const Vector< nCols, T1 > *vecs)
Fill the matrix with the array of vectors.
Definition: Matrix.hpp:78
CU_HOST_DEVICE Matrix(const Matrix< nRows, nCols, T1 > &mat)
Copy a matrix.
Definition: Matrix.hpp:66
static CU_HOST_DEVICE Vector< 2, size_t > size()
Returns the size of the matrix.
Definition: Matrix.hpp:156
CU_HOST_DEVICE T * data()
Returns a raw pointer on the data.
Definition: Matrix.hpp:192
static CU_HOST_DEVICE size_t nbColumns()
Returns the number of columns of the matrix.
Definition: Matrix.hpp:172
CU_HOST_DEVICE Matrix(const T &value)
Create a diagonal matrix.
Definition: Matrix.hpp:143
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:750
CU_HOST_DEVICE Matrix(const T *values, MatrixLayout layout=C_STYLE)
Fill in the matrix with the values.
Definition: Matrix.hpp:120
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:788
CU_HOST_DEVICE Matrix operator*(const T &scalar) const
Matrix-scalar multiplication.
Definition: Matrix.hpp:242
CU_HOST_DEVICE Matrix operator+(const Matrix &mat) const
Matrix addition.
Definition: Matrix.hpp:214
CU_HOST_DEVICE T * data()
Returns a raw pointer on the data.
Definition: Vector.hpp:224
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:660
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:731
CU_HOST_DEVICE Vector< nRows, T > diag() const
Return the diagonal vector, if the matrix is square.
Definition: Matrix.hpp:550
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:893
CU_HOST_DEVICE Matrix< nCols, nRows, T > operator~()
Transpose the matrix.
Definition: Matrix.hpp:465
#define STATIC_ASSERT(B)
Assertion that works at compile time.
Definition: StaticAssert.hpp:47
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:674
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:693
static CU_HOST_DEVICE Matrix identity()
Returns an identity matrix.
Definition: Matrix.hpp:424
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:851
Define the STATIC_ASSERT macro.
Class representing a fixed-size matrix.
Definition: Matrix.hpp:34
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:408
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:669
CU_HOST_DEVICE Matrix operator/(const T &scalar) const
Matrix-scalar division.
Definition: Matrix.hpp:256
CU_HOST_DEVICE Matrix(void)
Create a matrix filled with 0s.
Definition: Matrix.hpp:54
CU_HOST_DEVICE Vector< nCols, T > operator[](size_t idx) const
Returns the nth row.
Definition: Matrix.hpp:400
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:809
CU_HOST_DEVICE Vector< nRows, T > operator*(const Vector< nCols, T > &vec) const
Matrix*Column Vector.
Definition: Matrix.hpp:284
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can't...