Lynx is a lightweight and efficient easy to use C++ library for linear algebra operations, providing support for both N-dimensional and 2D matrices. It is designed for high performance while maintaining ease of use with generic programing.
-
2D Matrices (
lynx2d)- Efficient operations on strictly 2-dimensional matrices.
- Determinant and inverse calculation.
- Matrix multiplication, addition, subtraction (in-place and not in-place).
- Scalar multiplication/division (in-place and not in-place).
- Transpose of matrices.
- Input/output stream support.
- Equality and inequality checks.
-
N-Dimensional Matrices (
lynx)- Supports general N-dimensional arrays (core library).
- Flexible for high-dimensional linear algebraic computations.
-
Safe Access
- Element access with bounds checking via
operator().
- Element access with bounds checking via
-
Convenient Utilities
- Identity matrix generation.
- Shape querying (
shape()method). - Stream operators for file I/O and console output.
Clone the repository and include the headers in your project:
https://github.com/bhos-sec/Lynx.gitInclude in your code:
#include "lynx/matrix.hpp" // For N-dimensional matrices
#include "lynx/matrix2d.hpp" // For optimised 2D matrices#include <iostream>
#include <lynx/matrix2d.hpp>
int main() {
using namespace lynx2d;
// Create a 3x3 matrix
matrix<double> A(3, 3);
A(0,0) = 1; A(0,1) = 2; A(0,2) = 3;
A(1,0) = 0; A(1,1) = 1; A(1,2) = 4;
A(2,0) = 5; A(2,1) = 6; A(2,2) = 0;
// Print the matrix
std::cout << "Matrix A:\n" << A << "\n";
// Identity matrix
auto I = identity<double>(3);
std::cout << "Identity matrix:\n" << I << "\n";
// Determinant
std::cout << "Determinant of A: " << det(A) << "\n";
// Inverse
auto A_inv = inverse(A);
std::cout << "Inverse of A:\n" << A_inv << "\n";
// Multiplication (should return identity)
std::cout << "A * A_inv:\n" << A * A_inv << "\n";
return 0;
}Lynx library gives you the access to you use any input/output stream for your matrix operations.
#include <fstream>
matrix<int> K(3,3);
std::ifstream in("matrix0.txt");
in >> K;
std::ofstream out("matrix0.txt");
out << K * 10;Compile your example using:
g++ -std=c++23 -Wall -Wextra -O2 example.cpp -I./lynx -o example.outRun:
./example.outThis project is licensed under the BSD-3-Clause License. See the LICENSE file for details.
Vugar Ahadli Email: vuqarahadli17@gmail.com | vugar.ahadli.std@bhos.edu.az