28#include <jau/test/catch2_ext.hpp>
58static float*
invertMatrix(
float msrc[],
float mres[],
float temp[]) {
61 for (i = 0; i < 4; i++) {
63 for (j = 0; j < 4; j++) {
64 temp[i4+j] = msrc[i4+j];
69 for (i = 0; i < 4; i++) {
76 for (j = i + 1; j < 4; j++) {
77 if (std::abs(temp[j*4+i]) > std::abs(temp[i4+i])) {
83 const int swap4 =
swap*4;
87 for (k = 0; k < 4; k++) {
89 temp[i4+k] = temp[swap4+k];
93 mres[i4+k] = mres[swap4+k];
98 if (temp[i4+i] == 0) {
107 for (k = 0; k < 4; k++) {
111 for (j = 0; j < 4; j++) {
115 for (k = 0; k < 4; k++) {
116 temp[j4+k] -= temp[i4+k] * t;
117 mres[j4+k] -= mres[i4+k]*t;
142 Mat4f matrix_m(matrix);
143 Mat4f inv1_4a(matrix_m);
144 REQUIRE(
true == inv1_4a.
invert() );
145 Mat4f inv2_4a(inv1_4a);
146 REQUIRE(
true == inv2_4a.
invert() );
149 Mat4f a(inv1_0), b( inv1_4a.
get(temp) );
150 std::cout <<
"A: " << a << std::endl;
151 std::cout <<
"B: " << b << std::endl;
158 REQUIRE(
true == inv1_4b.
invert(matrix_m) );
160 REQUIRE(
true == inv2_4b.
invert(inv1_4b) );
169TEST_CASE(
"Test 02",
"[mat4f][linear_algebra][math]" ) {
170 float p[] = { 2.3464675f, 0, 0, 0,
177TEST_CASE(
"Test 03",
"[mat4f][linear_algebra][math]" ) {
178 float mv[] = { 1, 0, 0, 0,
185TEST_CASE(
"Test 04",
"[mat4f][linear_algebra][math]" ) {
186 float p[] = { 2.3464675f, 0, 0, 0,
194TEST_CASE(
"Test 05 Perf01",
"[mat4f][linear_algebra][math]" ) {
195 float p1[] = { 2.3464675f, 0, 0, 0,
201 float p2[] = { 26, 59, 143, 71,
203 143, 730, 9770, 5370,
204 71, 386, 5370, 2954 };
209 const size_t warmups = 1000_u64;
210 const size_t loops = 10_u64*1000000_u64;
222 for(
size_t i=0; i<warmups; i++) {
229 for(
size_t i=0; i<
loops; i++) {
239 for(
size_t i=0; i<warmups; i++) {
247 for(
size_t i=0; i<
loops; i++) {
256 printf(
"Checkmark %f\n", dr);
257 printf(
"Summary loops %6zu: I4a %6s ms total (%s us), %f ns/inv, I4a / I4b %f%%\n",
loops,
260 printf(
"Summary loops %6zu: I4b %6s ms total (%s us), %f ns/inv, I4b / I4a %f%%\n",
loops,
constexpr double to_double() const noexcept
Returns the converted fraction to lossy double.
constexpr int_type to_us() const noexcept
Convenient shortcut to to_num_of(1_us)
constexpr int_type to_ns() const noexcept
Convenient shortcut to to_num_of(1_ns)
constexpr int_type to_ms() const noexcept
Convenient shortcut to to_num_of(1_ms)
static constexpr const value_type inv_deviation
constexpr value_type get(const jau::nsize_t i) const noexcept
Returns the ith component of the given column-major order matrix, 0 <= i < 16, w/o boundary check.
bool invert() noexcept
Invert this matrix.
value_type determinant() const noexcept
Returns the determinant of this matrix.
constexpr bool equals(const Matrix4 &o, const value_type epsilon=std::numeric_limits< value_type >::epsilon()) const noexcept
constexpr Matrix4 & load(const_iterator src) noexcept
Load the values of the given matrix src to this matrix w/o boundary check.
std::string toString(const std::string &rowPrefix, const std::string_view f) const noexcept
Returns a formatted string representation of this matrix.
void swap(cow_darray< Value_type, Size_type, Alloc_type > &rhs, cow_darray< Value_type, Size_type, Alloc_type > &lhs) noexcept
constexpr T EPSILON
Alias for epsilon constant, i.e. std::numeric_limits<T>::epsilon()
constexpr bool is_zero(const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if the given value is less than epsilon, w/ epsilon > 0.
FracI64SizeBoolTuple to_fraction_i64(std::string_view str, const fraction_i64 &min_allowed, const fraction_i64 &max_allowed) noexcept
Returns the fraction_i64 of the given character in format <num>/<denom>, which may contain whitespace...
fraction_timespec getMonotonicTime() noexcept
Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01.
fraction< int64_t > fraction_i64
fraction using int64_t as integral type
std::string to_decstring(const value_type &v, const char separator='\'', const nsize_t min_width=0) noexcept
Produces a decimal integer string representation of an integral integer value with given radix.
constexpr const jau::fraction_i64 zero(0l, 1lu)
zero is 0/1
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
static void testImpl(float matrix[])
static float * makeIdentity(float m[])
TEST_CASE("Test 02", "[mat4f][linear_algebra][math]")
static float * invertMatrix(float msrc[], float mres[], float temp[])
int printf(const char *format,...)
Operating Systems predefined macros.