Skip to content

4J-company/mr-math

Repository files navigation

mr. Math

Lightweight and high-performance linear algebra library optimized for 3d graphics workflow

Features

  • Cross-platform library with support for GCC, Cland and MSVC.
  • Modern C++23
  • Competitive performance (see library comparisons).
  • Linear algebra types: vectors, matrices, quaternions, and normals.
  • 3D graphics suitable types: bound boxes, projection matrices, camera, color.
  • Type safety: correct unit conversions, transformation matrices, and normalization.
  • Safe by default with explicit faster options.
  • Debug visualizers for all types (MSVC (ready) and GDB (coming soon)).
  • Printing types using std::ostream or std::format.
  • Useful utilities.

Dependencies

  • Vc for simd wrappers
  • Google Test for tests only
  • Google Benchmark for benchmarks only

Usage

For functionality and usage examples see usage.

Installation

Using CPM.cmake:

CPMAddPackage("gh:4J-company/mr-math#master")
target_link_libraries(<your-project>
            PUBLIC/INTERFACE/PRIVATE
            mr-math-lib)

Using Conan

Add special 4j remote to your machine:

git clone https://github.com/4J-company/conan-center-index.git cci-4j
conan remote add 4J-company ./cci-4j --type local-recipes-index

Add "mr-math/1.1.0" to your conanfile.

Building

Build with Conan:

conan build . -b missing -o target=all

target option controls which CMake targets are built. Possile values are library (default), tests, benchmark, or all. For other options, see conanfile.py.

Once you installed all dependencies with Conan, you can build with CMake:

cmake --preset <preset-name>
cmake --build --preset <preset-name>

CMake presets are generated by Conan depending on your configuration. To see available presets, run:

cmake --list-presets

Benchmarking

With Bash & Python:

bash run-bench-viz.sh

This generates a plot with the benchmarking results NOTE: requires python, pandas, matplotlib, numpy

With Conan:

conan build . -b missing -o '&:target=bench'

With CMake:

cmake -DMR_MATH_ENABLE_BENCHMARK=ON -DMAKE_BUILD_TYPE=Release
cmake --build build/benchmark
./build/benchmark/mr-math-bench

More advanced benchmark configuration

If you are interested in specific results, you can disable particular benchmarks with the following options:

  • MR_MATH_ENABLE_VEC_BENCH
  • MR_MATH_ENABLE_MATR_BENCH
  • MR_MATH_ENABLE_QUAT_BENCH
  • MR_MATH_ENABLE_AABB_BENCH
  • MR_MATH_ENABLE_CAM_BENCH
  • MR_MATH_ENABLE_COLOR_BENCH

To enable extra optimizations use:

  • MR_MATH_EXTRA_OPTIMIZED
    Adds -ffast-math, this hurts accuracy a little but increases perf a lot
  • MR_MATH_ENABLE_PROFILING
    Makes changes suggested by profiling tools used by me
    Adds -lprofiler -ltcmalloc
    DOES NOT include any optimization

Comparison with other libraries

Library Matrix Multiplication (ns) Vector normalization (ns) Scalar triple products (ns)
mr. Math 4 2 6.5
DirectXMath 4.8 4.3 2.3
glm 5.7 3.3 1.6
cglm 6.2 14.6 2.2
lin 5.7 3.3 2.3

About

Linear algebra library for computer graphics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •