Fixed matrix test using fast math with Clang
This commit is contained in:
parent
3a560f3fd5
commit
1cead1904a
@ -2,6 +2,7 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/ulp.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
@ -15,55 +16,73 @@ int test_matrixCompMult()
|
||||
{
|
||||
mat2 m(0, 1, 2, 3);
|
||||
mat2 n = matrixCompMult(m, m);
|
||||
Error += n == mat2(0, 1, 4, 9) ? 0 : 1;
|
||||
mat2 expected = mat2(0, 1, 4, 9);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x3 m(0, 1, 2, 3, 4, 5);
|
||||
mat2x3 n = matrixCompMult(m, m);
|
||||
Error += n == mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1;
|
||||
mat2x3 expected = mat2x3(0, 1, 4, 9, 16, 25);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat2x4 n = matrixCompMult(m, m);
|
||||
Error += n == mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
|
||||
mat2x4 expected = mat2x4(0, 1, 4, 9, 16, 25, 36, 49);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
mat3 n = matrixCompMult(m, m);
|
||||
Error += n == mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1;
|
||||
mat3 expected = mat3(0, 1, 4, 9, 16, 25, 36, 49, 64);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x2 m(0, 1, 2, 3, 4, 5);
|
||||
mat3x2 n = matrixCompMult(m, m);
|
||||
Error += n == mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1;
|
||||
mat3x2 expected = mat3x2(0, 1, 4, 9, 16, 25);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat3x4 n = matrixCompMult(m, m);
|
||||
Error += n == mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
|
||||
mat3x4 expected = mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
mat4 n = matrixCompMult(m, m);
|
||||
Error += n == mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1;
|
||||
mat4 expected = mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat4x2 n = matrixCompMult(m, m);
|
||||
Error += n == mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
|
||||
mat4x2 expected = mat4x2(0, 1, 4, 9, 16, 25, 36, 49);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat4x3 n = matrixCompMult(m, m);
|
||||
Error += n == mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
|
||||
mat4x3 expected = mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
@ -92,57 +111,75 @@ int test_transpose()
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
mat2 m(0, 1, 2, 3);
|
||||
mat2 t = transpose(m);
|
||||
Error += t == mat2(0, 2, 1, 3) ? 0 : 1;
|
||||
mat2 const m(0, 1, 2, 3);
|
||||
mat2 const t = transpose(m);
|
||||
mat2 const expected = mat2(0, 2, 1, 3);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x3 m(0, 1, 2, 3, 4, 5);
|
||||
mat3x2 t = transpose(m);
|
||||
Error += t == mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
|
||||
mat3x2 const expected = mat3x2(0, 3, 1, 4, 2, 5);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat4x2 t = transpose(m);
|
||||
Error += t == mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
|
||||
mat4x2 const expected = mat4x2(0, 4, 1, 5, 2, 6, 3, 7);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
mat3 t = transpose(m);
|
||||
Error += t == mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
|
||||
mat3 const expected = mat3(0, 3, 6, 1, 4, 7, 2, 5, 8);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x2 m(0, 1, 2, 3, 4, 5);
|
||||
mat2x3 t = transpose(m);
|
||||
Error += t == mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
|
||||
mat2x3 const expected = mat2x3(0, 2, 4, 1, 3, 5);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat4x3 t = transpose(m);
|
||||
Error += t == mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
|
||||
mat4x3 const expected = mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
mat4 t = transpose(m);
|
||||
Error += t == mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
|
||||
mat4 const expected = mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat2x4 t = transpose(m);
|
||||
Error += t == mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
|
||||
mat2x4 const expected = mat2x4(0, 2, 4, 6, 1, 3, 5, 7);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat3x4 t = transpose(m);
|
||||
Error += t == mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
|
||||
mat3x4 const expected = mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
@ -157,33 +194,45 @@ int test_determinant()
|
||||
|
||||
int test_inverse()
|
||||
{
|
||||
int Failed(0);
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4x4 A4x4(
|
||||
glm::vec4(1, 0, 1, 0),
|
||||
glm::vec4(0, 1, 0, 0),
|
||||
glm::vec4(0, 0, 1, 0),
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
glm::mat4x4 B4x4 = inverse(A4x4);
|
||||
glm::mat4x4 I4x4 = A4x4 * B4x4;
|
||||
Failed += I4x4 == glm::mat4x4(1) ? 0 : 1;
|
||||
{
|
||||
glm::mat4x4 A4x4(
|
||||
glm::vec4(1, 0, 1, 0),
|
||||
glm::vec4(0, 1, 0, 0),
|
||||
glm::vec4(0, 0, 1, 0),
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
glm::mat4x4 B4x4 = inverse(A4x4);
|
||||
glm::mat4x4 I4x4 = A4x4 * B4x4;
|
||||
glm::mat4x4 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I4x4[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
glm::mat3x3 A3x3(
|
||||
glm::vec3(1, 0, 1),
|
||||
glm::vec3(0, 1, 0),
|
||||
glm::vec3(0, 0, 1));
|
||||
glm::mat3x3 B3x3 = glm::inverse(A3x3);
|
||||
glm::mat3x3 I3x3 = A3x3 * B3x3;
|
||||
Failed += I3x3 == glm::mat3x3(1) ? 0 : 1;
|
||||
{
|
||||
glm::mat3x3 A3x3(
|
||||
glm::vec3(1, 0, 1),
|
||||
glm::vec3(0, 1, 0),
|
||||
glm::vec3(0, 0, 1));
|
||||
glm::mat3x3 B3x3 = glm::inverse(A3x3);
|
||||
glm::mat3x3 I3x3 = A3x3 * B3x3;
|
||||
glm::mat3x3 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I3x3[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
glm::mat2x2 A2x2(
|
||||
glm::vec2(1, 1),
|
||||
glm::vec2(0, 1));
|
||||
glm::mat2x2 B2x2 = glm::inverse(A2x2);
|
||||
glm::mat2x2 I2x2 = A2x2 * B2x2;
|
||||
Failed += I2x2 == glm::mat2x2(1) ? 0 : 1;
|
||||
{
|
||||
glm::mat2x2 A2x2(
|
||||
glm::vec2(1, 1),
|
||||
glm::vec2(0, 1));
|
||||
glm::mat2x2 B2x2 = glm::inverse(A2x2);
|
||||
glm::mat2x2 I2x2 = A2x2 * B2x2;
|
||||
glm::mat2x2 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I2x2[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Failed;
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_inverse_simd()
|
||||
@ -255,7 +304,7 @@ int test_inverse_perf(std::size_t Count, std::size_t Instance, char const * Mess
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
int Error = 0;
|
||||
Error += test_matrixCompMult();
|
||||
Error += test_outerProduct();
|
||||
Error += test_transpose();
|
||||
|
Loading…
Reference in New Issue
Block a user