public void Invert() { var maxDelta = 0.001m; var deltas = new List <decimal>(); // Scalability and edge cases foreach (var m in testCases) { Matrix3x3 testCase = m; FloatMatrix3x3 floatMatrix = MathConverter.Convert(testCase); FloatMatrix3x3 expected; FloatMatrix3x3.Invert(ref floatMatrix, out expected); Matrix3x3 actual; if (float.IsInfinity(expected.M11) || float.IsNaN(expected.M11)) { expected = new FloatMatrix3x3(); } Matrix3x3.Invert(ref testCase, out actual); bool success = true; foreach (decimal delta in GetDeltas(expected, actual)) { deltas.Add(delta); success &= delta <= maxDelta; } Assert.True(success, string.Format("Precision: Matrix3x3Invert({0}): Expected {1} Actual {2}", testCase, expected, actual)); } output.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision); output.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision); }
public void BenchmarkInvert() { var swf = new Stopwatch(); var swd = new Stopwatch(); var deltas = new List <decimal>(); foreach (var m in testCases) { Matrix3x3 testCase = m; for (int i = 0; i < 10000; i++) { FloatMatrix3x3 floatMatrix = MathConverter.Convert(testCase); FloatMatrix3x3 expected; swf.Start(); FloatMatrix3x3.Invert(ref floatMatrix, out expected); swf.Stop(); Matrix3x3 actual; swd.Start(); Matrix3x3.Invert(ref testCase, out actual); swd.Stop(); if (float.IsInfinity(expected.M11) || float.IsNaN(expected.M11)) { expected = new FloatMatrix3x3(); } foreach (decimal delta in GetDeltas(expected, actual)) { deltas.Add(delta); } } } output.WriteLine("Max error: {0} ({1} times precision)", deltas.Max(), deltas.Max() / Fix64.Precision); output.WriteLine("Average precision: {0} ({1} times precision)", deltas.Average(), deltas.Average() / Fix64.Precision); output.WriteLine("Fix64.Invert time = {0}ms, float.Invert time = {1}ms", swf.ElapsedMilliseconds, swd.ElapsedMilliseconds); }