35static const float EPSILON = std::numeric_limits<float>::epsilon();
60static float*
invertMatrix(
float msrc[],
float mres[],
float temp[]) {
63 for (i = 0; i < 4; i++) {
65 for (j = 0; j < 4; j++) {
66 temp[i4+j] = msrc[i4+j];
71 for (i = 0; i < 4; i++) {
78 for (j = i + 1; j < 4; j++) {
85 const int swap4 =
swap*4;
89 for (k = 0; k < 4; k++) {
91 temp[i4+k] = temp[swap4+k];
95 mres[i4+k] = mres[swap4+k];
100 if (temp[i4+i] == 0) {
109 for (k = 0; k < 4; k++) {
113 for (j = 0; j < 4; j++) {
117 for (k = 0; k < 4; k++) {
118 temp[j4+k] -= temp[i4+k] * t;
119 mres[j4+k] -= mres[i4+k]*t;
144 Mat4f matrix_m(matrix);
145 Mat4f inv1_4a(matrix_m);
146 REQUIRE(
true == inv1_4a.
invert() );
147 Mat4f inv2_4a(inv1_4a);
148 REQUIRE(
true == inv2_4a.
invert() );
151 Mat4f a(inv1_0), b( inv1_4a.
get(temp) );
152 std::cout <<
"A: " << a << std::endl;
153 std::cout <<
"B: " << b << std::endl;
160 REQUIRE(
true == inv1_4b.
invert(matrix_m) );
162 REQUIRE(
true == inv2_4b.
invert(inv1_4b) );
171TEST_CASE(
"Test 02",
"[mat4f][linear_algebra][math]" ) {
172 float p[] = { 2.3464675f, 0, 0, 0,
179TEST_CASE(
"Test 03",
"[mat4f][linear_algebra][math]" ) {
180 float mv[] = { 1, 0, 0, 0,
187TEST_CASE(
"Test 04",
"[mat4f][linear_algebra][math]" ) {
188 float p[] = { 2.3464675f, 0, 0, 0,
196TEST_CASE(
"Test 05 Perf01",
"[mat4f][linear_algebra][math]" ) {
197 float p1[] = { 2.3464675f, 0, 0, 0,
203 float p2[] = { 26, 59, 143, 71,
205 143, 730, 9770, 5370,
206 71, 386, 5370, 2954 };
211 const size_t warmups = 1000_u64;
212 const size_t loops = 10_u64*1000000_u64;
224 for(
size_t i=0; i<warmups; i++) {
231 for(
size_t i=0; i<
loops; i++) {
241 for(
size_t i=0; i<warmups; i++) {
249 for(
size_t i=0; i<
loops; i++) {
258 printf(
"Checkmark %f\n", dr);
259 printf(
"Summary loops %6zu: I4a %6s ms total (%s us), %f ns/inv, I4a / I4b %f%%\n",
loops,
262 printf(
"Summary loops %6zu: I4b %6s ms total (%s us), %f ns/inv, I4b / I4a %f%%\n",
loops,
#define REQUIRE_MSG(MSG,...)
#define COMPARE_NARRAYS_EPS(lhs, rhs, len, eps)
constexpr double to_double() const noexcept
Returns the converted fraction to lossy double.
constexpr int_type to_ms() const noexcept
Convenient shortcut to to_num_of(1_ms)
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)
Basic 4x4 value_type matrix implementation using fields for intensive use-cases (host operations).
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
std::string toString(const std::string &rowPrefix, const std::string &f) const noexcept
Returns a formatted string representation of this matrix.
constexpr Matrix4 & load(const_iterator src) noexcept
Load the values of the given matrix src to this matrix w/o boundary check.
void swap(cow_darray< Value_type, Size_type, Alloc_type > &rhs, cow_darray< Value_type, Size_type, Alloc_type > &lhs) noexcept
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr 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.
bool to_fraction_i64(fraction_i64 &result, const std::string &value, const fraction_i64 &min_allowed, const fraction_i64 &max_allowed) noexcept
Stores the fraction_i64 value of the given string value in format <num>/<denom>, which may contain wh...
fraction_timespec getMonotonicTime() noexcept
Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01.
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
std::string to_decstring(const value_type &v, const char separator=',', const nsize_t width=0) noexcept
Produce a decimal string representation of an integral integer value.
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 const float EPSILON
static float * invertMatrix(float msrc[], float mres[], float temp[])
int printf(const char *format,...)
Operating Systems predefined macros.