29package com.jogamp.opengl.test.junit.math;
31import org.junit.Assert;
33import org.junit.FixMethodOrder;
34import org.junit.runners.MethodSorters;
36import com.jogamp.common.os.Platform;
37import com.jogamp.junit.util.JunitTracer;
38import com.jogamp.math.FloatUtil;
39import com.jogamp.math.Matrix4f;
41@FixMethodOrder(MethodSorters.NAME_ASCENDING)
44 final float[] m1_0 =
new float[]{ 1, 3, 4, 0,
52 final float[] m2_0 =
new float[]{ 1, 6, 98, 54,
59 final float[] m2xm1_0 =
60 new float[]{ 26, 59, 143, 71,
63 71, 386, 5370, 2954 };
67 final float[] m1xm2_0 =
68 new float[]{12557, 893, 748, 1182,
71 1182, 113, 104, 131 };
78 final float[] r_0 =
new float[16];
80 Assert.assertArrayEquals(m1xm2_0, r_0, 0f);
82 Assert.assertEquals(m1xm2,
new Matrix4f(m1).mul(m2));
83 Assert.assertEquals(m1xm2,
new Matrix4f().mul(m1, m2));
85 Assert.assertEquals(n1xn2,
new Matrix4fb(n1).mul(n2));
86 Assert.assertEquals(n1xn2,
new Matrix4fb().mul(n1, n2));
89 final float[] r_0 =
new float[16];
91 Assert.assertArrayEquals(m2xm1_0, r_0, 0f);
93 Assert.assertEquals(m2xm1,
new Matrix4f(m2).mul(m1));
94 Assert.assertEquals(m2xm1,
new Matrix4f().mul(m2, m1));
96 Assert.assertEquals(n2xn1,
new Matrix4fb(n2).mul(n1));
97 Assert.assertEquals(n2xn1,
new Matrix4fb().mul(n2, n1));
103 final float[] res =
new float[16];
108 final int warmups = 1000;
109 final int loops = 25*1000*1000;
118 for(
int i=0; i<warmups; i++) {
122 long t_0 = Platform.currentTimeMillis();
123 for(
int i=0; i<loops; i++) {
127 tI1 = Platform.currentTimeMillis() - t_0;
130 for(
int i=0; i<warmups; i++) {
134 t_0 = Platform.currentTimeMillis();
135 for(
int i=0; i<loops; i++) {
139 tI2 = Platform.currentTimeMillis() - t_0;
149 for(
int i=0; i<warmups; i++) {
155 t_0 = Platform.currentTimeMillis();
156 for(
int i=0; i<loops; i++) {
162 tI4a = Platform.currentTimeMillis() - t_0;
165 for(
int i=0; i<warmups; i++) {
173 t_0 = Platform.currentTimeMillis();
174 for(
int i=0; i<loops; i++) {
182 tI4b = Platform.currentTimeMillis() - t_0;
189 for(
int i=0; i<warmups; i++) {
195 t_0 = Platform.currentTimeMillis();
196 for(
int i=0; i<loops; i++) {
202 tI5a = Platform.currentTimeMillis() - t_0;
203 Assert.assertTrue( dr > 0 );
206 for(
int i=0; i<warmups; i++) {
214 t_0 = Platform.currentTimeMillis();
215 for(
int i=0; i<loops; i++) {
223 tI5b = Platform.currentTimeMillis() - t_0;
224 Assert.assertTrue( dr > 0 );
226 System.err.printf(
"Checkmark %f%n", dr);
227 System.err.printf(
"Summary loops %6d: I1 %6d ms total, %f us/mul%n", loops, tI1, tI1*1e3/loops);
228 System.err.printf(
"Summary loops %6d: I2 %6d ms total, %f us/mul, I2 / I1 %f%%%n", loops, tI2, tI2*1e3/2.0/loops, (
double)tI2/(
double)tI1*100.0);
229 System.err.printf(
"Summary loops %6d: I4a %6d ms total, %f us/mul, I4a / I2 %f%%, I4a / I4b %f%%%n", loops, tI4a, tI4a*1e3/2.0/loops, (
double)tI4a/(
double)tI2*100.0, (
double)tI4a/(
double)tI4b*100.0);
230 System.err.printf(
"Summary loops %6d: I4b %6d ms total, %f us/mul, I4b / I2 %f%%, I4b / I4a %f%%%n", loops, tI4b, tI4b*1e3/2.0/loops, (
double)tI4b/(
double)tI2*100.0, (
double)tI4b/(
double)tI4a*100.0);
231 System.err.printf(
"Summary loops %6d: I5a %6d ms total, %f us/mul, I5a / I2 %f%%, I5a / I5b %f%%%n", loops, tI5a, tI5a*1e3/2.0/loops, (
double)tI5a/(
double)tI2*100.0, (
double)tI5a/(
double)tI5b*100.0);
232 System.err.printf(
"Summary loops %6d: I5b %6d ms total, %f us/mul, I5b / I2 %f%%, I5b / I5a %f%%%n", loops, tI5b, tI5b*1e3/2.0/loops, (
double)tI5b/(
double)tI2*100.0, (
double)tI5b/(
double)tI5a*100.0);
235 public static void main(
final String args[]) {
Basic Float math utility functions.
static void multMatrix(final float[] a, final int a_off, final float[] b, final int b_off, final float[] d, final int d_off)
Multiply matrix: [d] = [a] x [b].
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
final Matrix4f mul(final Matrix4f b)
Multiply matrix: [this] = [this] x [b].
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
float determinant()
Returns the determinant of this matrix.
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
float determinant()
Returns the determinant of this matrix.
Matrix4fb load(final Matrix4fb src)
Load the values of the given matrix b to this matrix.
final Matrix4fb mul(final Matrix4fb b)
Multiply matrix: [this] = [this] x [b].
static void main(final String args[])