mxm icon indicating copy to clipboard operation
mxm copied to clipboard

Header-only/compiled C++ numerical compute library.

mxm

A header-only/compiled C++ numerical compute library.

$$\Huge A_{m \times m}$$

Features

1. Dense Matrix Operation

  • N-Dimensional Matrix/Vector Operation [mxm/linalg_mat.h]
    • Real
    • Complex [mxm/linalg_complex.h]
    • Quaternion [mxm/linalg_complex.h]
    • Dual Number [mxm/linalg_dual_number.h]
  • QR Decomposition/solver (Real, Complex) [mxm/linalg_solve.h]
  • Eigenvalue Decomposition (Real, by shifted QR Iteration).
  • Singular Value Decomposition (Real).

2. Geometry

  • 2-D, 3-D, N-D Rotation
    • Logarithmic/Exponential Map for $SO(n)$ and $\mathfrak{so}(n)$ [mxm/lie_special_orthogonal.h]
    • Conversion between Axis/Plane-Angle, Rotation Matrix, Quaternion [mxm/full_dimensional_rotation.h]
    • Spherical Linear Interpolation
  • N-D Ray [mxm/geometry_ray.h]
  • N-D Pinhole Camera (3D Radial Tangential Distortion) [mxm/model_camera.h]
  • N-D Simplex(line segment, triangle, tetrahedron ...) [mxm/geometry_primitive.h]
  • N-D Rigidbody Transform [mxm/rigid_transform.h]
  • N-D Affine Transform [mxm/transform_affine.h]
  • N-D BVH Tree [mxm/spatial_bvh.h]
    • Ray Closest-Hit/Any-Hit/Multi-Hit
    • Radius Search
    • Nearest Neighbor Search
  • N-D Metric Tree (for any metric space) [mxm/spatial_metric_tree.h]

3. None-linear Optimization

  • Gauss-Newton Method [mxm/optimize.h]
  • Auto Derivative(based on Dual Number) :star2: :star2:
  • Sparse Jacobian Acceleration for SfM [mxm/optimize_sfm_gn.h]

4. Graph

  • Directed/Undirected Weighted/Unweighted Graph [mxm/graph_base.h]
  • Shortest Path [mxm/graph_dijkstra.h]
    • Dijkstra
    • Bellman Ford
  • Flow Network [mxm/graph_flow.h]
    • Fulkerson Ford Max Flow

5. Toy Demos

  • Optical Flow [mxm/cv_optical_flow.h]
  • Pinhole Camera Calibration [mxm/cv_calibration.h]

Code Sample

  • QR decomposition and linear equation
#include "mxm/linalg.h"
using namespace mxm;

Matrix<float> mat_a = random::uniform({5,5});
Vector<float> vec_b = random::uniform({5,1});
auto qr = qr::decomposeByRotation(mat_a);
auto vec_x = qr::solve(mat_a, vec_b);
  • 4D Rotation
#include "mxm/rotation.h"
using namespace mxm;

// Rotation::fromPlaneAngle() is available for any dimensional rotation.
Rotation<double> r1 = Rotation::fromPlaneAngle({1,0,0,0}, {0,1,0,0}, 0.5);
auto v1 = r1.apply({1,2,3,4});
  • Pinhole Camera Intrinsic Calibration
#include "mxm/cv_calibration.h"
#include "mxm/optimize_sfm_gn.h"

using namespace mxm;

Camera<DType, 3> cam_guess(cam);
cam_guess.setFocalLength(Vector<DType>{500, 500});
cam_guess.setPrincipalOffset(Vector<DType>{250, 0.5 * 752});
cam_guess.setDistortion(Distortion<DType>::radialTangential({0,0,0,0}));

PinholeCameraIntrinsicEstimator<DType> problem(pts3d, pts2d);
problem.initialGuess(pose_guess, cam_guess);
problem.solve(5, 0);

For more code samples, see tests/test_main.cpp.

Installation

Linux/MacOS

git clone https://github.com/XiaoxingChen/mxm
cd mxm
./build.py --test

Windows

git clone https://github.com/XiaoxingChen/mxm
cd mxm
python build.py --test

Dependents

  • c++17
  • STL

Related Blogs and Links

  1. A 4D CPU Ray Tracing Renderer based on mxm: ray_tracing_4d
  2. Blog: Dual Number and Auto Derivative of Special Orthogonal Group
  3. Blog: Geometries for N-Dimensional Ray Tracing
  4. Zhihu: How to implement Auto Differentiation in C++?(Chinese)