Skip to content
Jiayao' Math ToolBox: Linear Algebra Library
C++ Other
  1. C++ 99.1%
  2. Other 0.9%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.travis.yml
CMakeLists.txt
LICENSE
Makefile
README.md
appveyor.yml
cmatrix.hpp
complex.hpp
dmatrix.hpp
matrix.hpp

README.md

jmt-matrix

license Travis_status Appveyor status Chat on Gitter

Johnson's Math ToolBox: Linear Algebra Library

Introduction

JMT Linear Algebra Library is a light weighted fast library for scientific computing with C++. Though the author does not claim the library can outperform the celebrated LAPCK library, it is nonetheless very easy to use and performs pretty well with matrices sized less than 100.

This library supports common operations for real and complex matrices including:

  • Singular Value Decomposition

Single-sided Jacobi's rotation is used. This operation is similar to a compact SVD for thin matrices.

  • QR/LQ Decomposition

Householder's Reflection is used for numerical robustness.

  • Cholesky Decomposition

This directly leads to the ability for matrix inversion.

Installation

First, clone this repo using git:

git clone https://github.com/zjiayao/jmt-matrix

Then cd to the repo and build and run the example:

cd jmt-matrix && make example && ./example

For Windows users, a CMakeList is prepared, and thus one may build using cmake:

cd jmt-matrix
cmake -H. -Bbuild
cmake --build build
./build/example

Usage

To use JMT Linear Algebra Library for operating on real numbers, include dmatrix.hpp in the header; analogously, include cmatrix.hpp for complex support.

A sample program for calling common APIs is given in the examples folder.

Features

  • Zero Dependency, Platform Dependent

The whole library is self-contained, shipped with a dedicated complex library used for comlex manipulations.

  • Template Programming

This library is written in template classes, that is, there is no need to compile or link before use. Directly include the desired headers (see previous section) and compile, voila!

This also makes the library very easy to extend to other data types, for examples, 16bit floats, etc.

  • Intuitive API

Doing a SVD and print the result is as simple as if in MatLAB or Python:

// a normal 5 * 3 real random matrix
jmt::dmat mat = jmt::dmat::getNRand(5, 3), u, s, v;
mat.SVD(u, s, v);
u.print();
  • Portability

This library provides a handful of formats for printing, hence it is easy to feed the results to, for example, Python.

// print to file
jmt::cmat cmat = jmt::cmat::getNRand(6, 3), q, r;
cmat.QR(q, r);

q.print(fout); // fout is a FILE pointer

r.print(stdout, jmt::NUMPY);

this gives:

 [[ 0.671    -    0.741i  ,0.000                 ,0.000                    ],
  [ 0.000                 ,0.975    +    0.223i  ,0.000                    ],
  [ 0.000                 ,0.000                 ,-0.625   -    0.781i     ],
  [ 0.000                 ,0.000                 ,0.000                    ],
  [ 0.000                 ,0.000                 ,0.000                    ],
  [ 0.000                 ,0.000                 ,0.000                    ]]

Of course, directly std::cout and std::cin (yes!) are supported.

Claimer

It is recommended NOT to use this library in production environment, rather, use well-crafted libraries such as LAPACK in lieu.

You can’t perform that action at this time.