Make C++98 compliant

This commit is contained in:
Vincent Aymong 2017-07-06 17:45:40 -04:00
parent edde2bcf60
commit f9962054d9
3 changed files with 17 additions and 18 deletions

View File

@ -13,7 +13,6 @@
#pragma once
// Dependency:
#include <algorithm>
#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 <length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_DECL void qr_decompose(matType<std::min(C, R), R, T, P>& q, matType<C, std::min(C, R), T, P>& r, const matType<C, R, T, P>& in);
GLM_FUNC_DECL void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType<C, (C < R ? C : R), T, P>& r, const matType<C, R, T, P>& 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 <length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_DECL void rq_decompose(matType<std::min(C, R), R, T, P>& r, matType<C, std::min(C, R), T, P>& q, const matType<C, R, T, P>& in);
GLM_FUNC_DECL void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType<C, (C < R ? C : R), T, P>& q, const matType<C, R, T, P>& in);
/// @}
}

View File

@ -24,14 +24,14 @@ namespace glm {
}
template <length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_QUALIFIER void qr_decompose(matType<std::min(C, R), R, T, P>& q, matType<C, std::min(C, R), T, P>& r, const matType<C, R, T, P>& in) {
GLM_FUNC_QUALIFIER void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType<C, (C < R ? C : R), T, P>& r, const matType<C, R, T, P>& in) {
// Uses modified Gram-Schmidt method
// Source: https://en.wikipedia.org/wiki/GramSchmidt_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 <length_t C, length_t R, typename T, precision P, template<length_t, length_t, typename, precision> class matType>
GLM_FUNC_QUALIFIER void rq_decompose(matType<std::min(C, R), R, T, P>& r, matType<C, std::min(C, R), T, P>& q, const matType<C, R, T, P>& in) {
GLM_FUNC_QUALIFIER void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType<C, (C < R ? C : R), T, P>& q, const matType<C, R, T, P>& 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 GramSchmidt orthogonalization of columns of A, started from the first column.
@ -64,8 +64,8 @@ namespace glm {
matType<R, C, T, P> tin = transpose(in);
tin = fliplr(tin);
matType<R, std::min(C, R), T, P> tr;
matType<std::min(C, R), C, T, P> tq;
matType<R, (C < R ? C : R), T, P> tr;
matType<(C < R ? C : R), C, T, P> tq;
qr_decompose(tq, tr, tin);
tr = fliplr(tr);

View File

@ -5,8 +5,8 @@ const double epsilon = 1e-10f;
template <glm::length_t C, glm::length_t R, typename T, glm::precision P, template<glm::length_t, glm::length_t, typename, glm::precision> class matType>
int test_qr(matType<C, R, T, P> m) {
matType<std::min(C, R), R, T, P> q(-999);
matType<C, std::min(C, R), T, P> r(-999);
matType<(C < R ? C : R), R, T, P> q(-999);
matType<C, (C < R ? C : R), T, P> r(-999);
glm::qr_decompose(q, r, m);
@ -21,7 +21,7 @@ int test_qr(matType<C, R, T, P> 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<i; j++) {
@ -31,7 +31,7 @@ int test_qr(matType<C, R, T, P> 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<C, R, T, P> m) {
template <glm::length_t C, glm::length_t R, typename T, glm::precision P, template<glm::length_t, glm::length_t, typename, glm::precision> class matType>
int test_rq(matType<C, R, T, P> m) {
matType<C, std::min(C, R), T, P> q(-999);
matType<std::min(C, R), R, T, P> r(-999);
matType<C, (C < R ? C : R), T, P> 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<C, R, T, P> m) {
//Test if the rows of q are orthonormal
matType<std::min(C, R), C, T, P> 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<i; j++) {
@ -69,8 +69,8 @@ int test_rq(matType<C, R, T, P> 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;
}
}