Skip to content

bhos-sec/Lynx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Lynx Linear Algebra Library

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.


Features

  • 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().
  • Convenient Utilities

    • Identity matrix generation.
    • Shape querying (shape() method).
    • Stream operators for file I/O and console output.

Installation

Clone the repository and include the headers in your project:

https://github.com/bhos-sec/Lynx.git

Include in your code:

#include "lynx/matrix.hpp"    // For N-dimensional matrices
#include "lynx/matrix2d.hpp"  // For optimised 2D matrices

Usage Examples

2D Matrix Example

#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;
}

File I/O

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;

Compilation

Compile your example using:

g++ -std=c++23 -Wall -Wextra -O2 example.cpp -I./lynx -o example.out

Run:

./example.out

License

This project is licensed under the BSD-3-Clause License. See the LICENSE file for details.


Contact

Vugar Ahadli Email: vuqarahadli17@gmail.com | vugar.ahadli.std@bhos.edu.az

About

A lightweight and beginner-friendly linear algebra library written in C++

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages