diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp index 3c66776e..9acc7f3a 100644 --- a/glm/gtx/matrix_factorisation.hpp +++ b/glm/gtx/matrix_factorisation.hpp @@ -13,7 +13,6 @@ #pragma once // Dependency: -#include #include "../glm.hpp" #ifndef GLM_ENABLE_EXPERIMENTAL @@ -49,7 +48,7 @@ namespace glm{ /// Given an n-by-m input matrix, q has dimensions min(n,m)-by-m, and r has dimensions n-by-min(n,m). /// From GLM_GTX_matrix_factorisation extension. template class matType> - GLM_FUNC_DECL void qr_decompose(matType& q, matType& r, const matType& in); + GLM_FUNC_DECL void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in); /// Performs RQ factorisation of a matrix. /// Returns 2 matrices, r and q, such that r is an upper triangular matrix, the rows of q are orthonormal and span the same subspace than those of the input matrix, and r*q=in. @@ -57,7 +56,7 @@ namespace glm{ /// Given an n-by-m input matrix, r has dimensions min(n,m)-by-m, and q has dimensions n-by-min(n,m). /// From GLM_GTX_matrix_factorisation extension. template class matType> - GLM_FUNC_DECL void rq_decompose(matType& r, matType& q, const matType& in); + GLM_FUNC_DECL void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in); /// @} } diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index f53d8280..52f0d56c 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -24,14 +24,14 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER void qr_decompose(matType& q, matType& r, const matType& in) { + GLM_FUNC_QUALIFIER void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in) { // Uses modified Gram-Schmidt method // Source: https://en.wikipedia.org/wiki/Gram–Schmidt_process // And https://en.wikipedia.org/wiki/QR_decomposition //For all the linearly independs columns of the input... // (there can be no more linearly independents columns than there are rows.) - for (length_t i = 0; i < std::min(R, C); i++) { + for (length_t i = 0; i < (C < R ? C : R); i++) { //Copy in Q the input's i-th column. q[i] = in[i]; @@ -55,7 +55,7 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER void rq_decompose(matType& r, matType& q, const matType& in) { + GLM_FUNC_QUALIFIER void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in) { // From https://en.wikipedia.org/wiki/QR_decomposition: // The RQ decomposition transforms a matrix A into the product of an upper triangular matrix R (also known as right-triangular) and an orthogonal matrix Q. The only difference from QR decomposition is the order of these matrices. // QR decomposition is Gram–Schmidt orthogonalization of columns of A, started from the first column. @@ -64,8 +64,8 @@ namespace glm { matType tin = transpose(in); tin = fliplr(tin); - matType tr; - matType tq; + matType tr; + matType<(C < R ? C : R), C, T, P> tq; qr_decompose(tq, tr, tin); tr = fliplr(tr); diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp index d45c352e..573f3d0a 100644 --- a/test/gtx/gtx_matrix_factorisation.cpp +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -5,8 +5,8 @@ const double epsilon = 1e-10f; template class matType> int test_qr(matType m) { - matType q(-999); - matType r(-999); + matType<(C < R ? C : R), R, T, P> q(-999); + matType r(-999); glm::qr_decompose(q, r, m); @@ -21,7 +21,7 @@ int test_qr(matType m) { } //Test if the columns of q are orthonormal - for (glm::length_t i = 0; i < std::min(C, R); i++) { + for (glm::length_t i = 0; i < (C < R ? C : R); i++) { if ((length(q[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j m) { //Test if the matrix r is upper triangular for (glm::length_t i = 0; i < C; i++) { - for (glm::length_t j = i + 1; j < std::min(C, R); j++) { + for (glm::length_t j = i + 1; j < (C < R ? C : R); j++) { if (r[i][j] != 0) return 4; } } @@ -41,8 +41,8 @@ int test_qr(matType m) { template class matType> int test_rq(matType m) { - matType q(-999); - matType r(-999); + matType q(-999); + matType<(C < R ? C : R), R, T, P> r(-999); glm::rq_decompose(r, q, m); @@ -58,9 +58,9 @@ int test_rq(matType m) { //Test if the rows of q are orthonormal - matType tq = transpose(q); + matType<(C < R ? C : R), C, T, P> tq = transpose(q); - for (glm::length_t i = 0; i < std::min(C, R); i++) { + for (glm::length_t i = 0; i < (C < R ? C : R); i++) { if ((length(tq[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j m) { } //Test if the matrix r is upper triangular - for (glm::length_t i = 0; i < std::min(C, R); i++) { - for (glm::length_t j = R - std::min(C, R) + i + 1; j < R; j++) { + for (glm::length_t i = 0; i < (C < R ? C : R); i++) { + for (glm::length_t j = R - (C < R ? C : R) + i + 1; j < R; j++) { if (r[i][j] != 0) return 4; } }