jlt lib is a C++ and Matlab library of various utility functions that I found useful over the years, and which are used in many of my other projects.
jlt lib provides efficient implementations of common numerical operations including:
- Mathematical vectors and matrices with BLAS/LAPACK integration
- Sparse matrix support via CSparse
- Polynomial operations and finite difference methods
- I/O utilities (Matlab format, STL containers, version control info)
- Timing utilities with detailed performance metrics
#include "jlt/mathvector.hpp"
#include "jlt/mathmatrix.hpp"
jlt::mathvector<double, double> v(3);
v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
jlt::mathmatrix<double, double> A(3, 3);
// ... perform linear algebra operationsHeader-only library - just add the parent directory to your include path:
g++ -std=c++11 -O3 -I/path/to/jlt/parent myprog.cpp -o myprogFor LAPACK functionality, add -lblas -llapack. See AGENTS.md for
detailed build instructions.
Comprehensive test suite with 1687 assertions across 23 test suites using Catch2:
cd tests && mkdir -p build && cd build
cmake .. && make
ctest # Run all tests
ctest -E lapack # Skip LAPACK tests (if not installed)
ctest -R lapack # Run only LAPACK testsTest coverage includes:
- Core library (1313 assertions): vector, matrix, mathvector, mathmatrix, polynomial, etc.
- LAPACK integration (174 assertions): LAPACK wrappers (45), eigensystems (32), SVD decomposition for real and complex matrices (97)
- Optional libraries: Matlab MAT-file I/O (61 assertions), CSparse (65 assertions), Boost timer (44 assertions)
See tests/README.md for detailed testing documentation.
- Derived from
std::vectorwith additional features - Optional compile-time bounds checking (
-DJLT_VECTOR_CHECK_BOUNDS) - Matlab and Mathematica output formats
- Example:
examples/vector_test.cpp
- Efficient row-major storage using
std::vector(RAII) - Move semantics (C++11)
- Optional bounds checking (
-DJLT_MATRIX_CHECK_BOUNDS) - Multiple output formats (Matlab, Mathematica)
- Example:
examples/matrix_test.cpp
- Full arithmetic operations (+, -, *, /, dot product, cross product)
- Integration with LAPACK for advanced operations
- Specialized support for eigenvalues/eigenvectors (
jlt/eigensystem.hpp) - LU and QR decomposition (
jlt/matrixutil.hpp) - Singular Value Decomposition for real and complex matrices (
jlt/svdecomp.hpp) - Requires:
-lblas -llapackfor linear algebra operations - Examples:
examples/mathvector_test.cpp,examples/eigensystem_test.cpp
- Wrappers for Timothy A. Davis's CSparse library
- Conversion to/from
jlt::mathmatrix - Type-safe
cs_unique_ptrwith automatic memory management - CSparse v3.1.1 included in
extern/CSparse/ - Requires:
-lcsparseor use included version - Example:
examples/csparse_test.cpp
- Arithmetic operations, evaluation, derivatives
- Root finding and polynomial division
- Example:
examples/polynomial_test.cpp
- Specialized class for polynomials satisfying P(x) = x^n * P(1/x)
- Efficient storage (only n/2 + 1 coefficients needed)
- Applications in dynamical systems and number theory
- 1st through 4th order accurate schemes
- Forward, backward, and central differences
- Equal and unequal spacing support
- Error estimation for 2nd and 4th order methods
- Export to Matlab MAT-file format (binary) or text format
- Works with scalars, vectors, matrices, and strings
- Binary mode requires: Matlab libraries (
-lmat -lmx -leng) andJLT_MATLAB_LIB_SUPPORTdefined - Text mode: No external dependencies
- Example:
examples/matlab_test.cpp
- Simple iostream operators for STL containers
- Supports: vector, list, set, map, valarray, array, deque, tuple, optional
- Customizable formatting (field width, separators)
- Complex number support
- MATLAB-style
tic()/toc()interface - Reports wall-clock, user CPU, and system CPU times
- Output format:
0.5w 0.5u 0s (1.2w 1.2u 0s)(elapsed and cumulative) - Programmatic API via
get_timing()for accessing timing data - Requires: Boost timer (
-lboost_timer -lboost_chrono) - Example:
examples/tictoc_test.cpp
- Extract commit information from Git, Mercurial, or Subversion
- Detects uncommitted changes (appends '+' to revision)
- Useful for reproducible research and embedding build info
- Example:
examples/vcs_test.cpp
- RAII-based task progress display with log levels
- Automatic timing and status reporting
- Mutable mode for quiet operation
- Specialized exceptions:
stepsize_too_small,failed_to_converge,too_many_steps JLT_THROWmacro for conditional exception compilation- Used throughout library for robust error handling
jlt/prompt.hpp: Terminal prompts for interactive programsjlt/command.hpp: Execute Unix commands and capture outputjlt/math.hpp: Mathematical utilities (Mod, Sign functions)jlt/lapack.h: C++ wrappers for LAPACK Fortran functions
The matlab/ directory contains complementary Matlab functions, including:
fourdif.m: Fourier differentiation matrix (by S. C. Reddy and J. A. C. Weideman)
See AGENTS.md for:
- Detailed build instructions and compiler flags
- Code style guidelines and conventions
- Test suite documentation
- Example compilation commands
- 2004: Initial development
- 2014: Migration from Subversion to Mercurial
- 2018: Migration to Git
- 2020s: Modernization (C++11, RAII, comprehensive test suite)
- 2026: 1607 test assertions, complex matrix SVD, bounds checking, improved error handling
See CHANGELOG.md for detailed version history.
- C++11 or later
- Optional dependencies:
- BLAS/LAPACK: For linear algebra operations
- Boost timer: For
jlt::tictoctiming utilities - Matlab libraries: For binary MAT-file I/O
- CSparse: For sparse matrix operations (v3.1.1 included)
jlt lib was written and is maintained by Jean-Luc Thiffeault.
Released under the MIT License.
Special acknowledgments:
fourdif.mby S. C. Reddy and J. A. C. Weideman- CSparse by Timothy A. Davis (included under GNU LGPL)
This library is actively maintained and used in multiple research projects. While originally developed for personal use, it is stable and well-tested. Contributions and bug reports are welcome.