Skip to content

jopadan/mlr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlr

mlr - single-header-only C++23 linear algebra math library

About

mlr implements aligned array arr : std::array<T,N> based vector vec::type<T,N,A> type for N-dimensional linear algebra math and Quake C++ vec_t type interface.

Dependencies

Building

cmake . --install-prefix=/usr
make install

Optimization

Change CMakeLists.txt compile flags to fit your needs:

add_compile_options(-march=native -mfpmath=[your SIMD instruction set] -O3)

Usage

#include <mlr/vector.hpp>
#include <mlr/color.hpp>

using namespace math;

int main(int argc, char** argv)
{
    vec::f32<3> A = { vec::f32<3>::identity(0),
                      vec::f32<3>::identity(1),
                      vec::f32<3>::identity(2) };

    A[2] = vec::f32<3>::cross3(A[0],A[1]);

    A[2].print_header(3, "cross3");
    A[2].print(3);

    col::u8 <{R,G,B            }> RGB888       = {1,2,3  }; // array    type
    col::u8 <{R,G,B,A          }> RGBA8888     = {1,2,3,4}; // array    type
    col::u8 <{B,G,R,A          }> BGRA8888     = {1,2,3,4}; // array    type
    col::u8 <{A,R,G,B          }> ARGB8888     = {1,2,3,4}; // array    type
    col::u8 <{A,B,G,R          }> ABGR8888     = {1,2,3,4}; // array    type

    col::f32<{R,G,B            }> RGBF32       = {1,2,3  }; // array    type
    col::f32<{R,G,B,A          }> RGBAF32      = {1,2,3,4}; // array    type
    col::f32<{A,R,G,B          }> ARGBF32      = {1,2,3,4}; // array    type
    col::f32<{A,B,G,R          }> ABGRF32      = {1,2,3,4}; // array    type
    col::f32<{B,G,R,A          }> BGRAF32      = {1,2,3,4}; // array    type

    col::u16<{R,G,B  },{5,6,5  }> RGB565       = {1,2,3  }; // bitfield type
    col::u16<{R,G,B,A},{5,5,5,1}> RGBA5551     = {1,2,3,4}; // bitfield type
    col::u16<{R,G,B,A},{4,4,4,4}> RGBA4444     = {1,2,3,4}; // bitfield type

    col::u8 <{R,G,B  },{2,4,2  }> RGB242       = {1,2,3  }; // bitfield type
    col::u8 <{R,G,B,A},{2,2,2,2}> RGBA2222     = {1,2,3,0}; // bitfield type

    col::u16<{R,G,B            }> RGB161616    = {1,2,3  }; // array    type
    col::u16<{R,G,B,A          }> RGBA16161616 = {1,2,3,4}; // array    type

    exit(EXIT_SUCCESS);
}
|vector                                 | typ|alg|vec|alg|mode           |cnt
|+1.00e+00 +0.00e+00 +0.00e+00 +0.00e+00|   4|  4| 16| 16|adaptive/vector|4
|+0.00e+00 +1.00e+00 +0.00e+00 +0.00e+00|   4|  4| 16| 16|adaptive/vector|4
|cross3                                 | typ|alg|vec|alg|mode           |cnt
|+0.00e+00 +0.00e+00 +1.00e+00 +0.00e+00|   4|  4| 16| 16|adaptive/vector|4
|cross4                                 | typ|alg|vec|alg|mode           |cnt
|-0.00e+00 +0.00e+00 -0.00e+00 +1.00e+00|   4|  4| 16| 16|adaptive/vector|4
|cross2 MLR_CCW/MLR_CW                  | typ|alg|vec|alg|mode           |cnt
|-0.00e+00 +1.00e+00 +0.00e+00 -1.00e+00|   4|  4| 16| 16|adaptive/vector|4
|dot4                                   | typ|alg|vec|alg|mode           |cnt
|+0.00e+00 +0.00e+00 +0.00e+00 +0.00e+00|   4|  4| 16| 16|adaptive/vector|4
|sum                                    | typ|alg|vec|alg|mode           |cnt
|+1.00e+00 +1.00e+00 +1.00e+00 +1.00e+00|   4|  4| 16| 16|adaptive/vector|4

|vector                       | typ|alg|vec|alg|mode           |cnt
|+1.00e+00 +0.00e+00 +0.00e+00|   4|  4| 12|  4|adaptive/scalar|3
|+0.00e+00 +1.00e+00 +0.00e+00|   4|  4| 12|  4|         scalar|3
|+0.00e+00 +0.00e+00 +1.00e+00|   4|  4| 16| 16|         vector|3
|un/aligned add               | typ|alg|vec|alg|mode           |cnt
|+0.00e+00 +1.00e+00 +1.00e+00|   4|  4| 12|  4|adaptive/scalar|3
|+1.00e+00 +0.00e+00 +1.00e+00|   4|  4| 12|  4|         scalar|3
|+1.00e+00 +1.00e+00 +0.00e+00|   4|  4| 16| 16|         vector|3

|color RGBA8888                         | typ|alg|vec|alg|mode           |cnt
|+23       +123      +53       +222     |   1|  1|  4|  4|adaptive/vector|4
|color RGB888                 | typ|alg|vec|alg|mode           |cnt
|+23       +123      +53      |   1|  1|  3|  1|adaptive/scalar|3

Links

Other C++ Math Libraries

Other OpenCL/SYCL/CUDA linear algebra vector type implementations

Quake C++ Math Libraries

War for the Overworld C++ Math Library

Math code/tutorials