Coder Social home page Coder Social logo

linalg_lib's Introduction

linalg_lib

Linalg is a linear algebra library designed to run with real-time constraints.

Build from source

The library itself is header only so only tests are needed to be compiled.

Requirements

Requirements to build linalg from source are:

  • C++ compiler clang 13.0.1 or higher (set by default). GCC 12.1.0 has also been tested.
  • C++ linker lld 13.0.1 or higher (any other linker also could be used see below)
  • CMake (tested with 3.23.1)

CMake options

The next CMake options could be customized:

  • CMAKE_CXX_COMPILER - full path to compiler
  • CMAKE_EXE_LINKER_FLAGS - linker flags (e.g. to choose linker use -fuse-ld=<linker_name>)

Build types

The next build types are defined:

  • Debug - no optimization, full debug info
  • Release - maximum optimizations, no assertions
  • Release-lto - like Release but with link time optimization enabled
  • Msan - small optimizations, memory sanitizer, no assertions
  • Msan - small optimizations, address sanitizer, no assertions

Build

To build all tests use commands:

$ cmake -DCMAKE_BUILD_TYPE=<build_type> -B <build_dir>
$ cmake --build <build_dir>

Running tests

There are two tests avaliable:

  • Unit tests checking all classes. To run use:
$ ./build/tests/unit/unit_tests
  • Integration test checking solving a system of linear equations. To run use:
$ ./build/tests/integration/test_from_example/run_test.sh

Usage

To use linalg in your project only include/ directory is needed (There is an issue to make releases #3).

Features

Features of the library are:

  • Operations with matrices and vectors : inversion, transposition, multiplication
  • Optimized inverse() operations calculates inversed matrix only explicitly
  • inverse() returns not initialized matrix if input matrix was singular
  • Compile-time calculations: all operations are constexpr
  • No exceptions (except Debug build type): all operations are marked as noexcept
  • Assertions in Debug build type

Limitations and disadvantages

The library has some limitations:

  • All matrices and vectors data is stored on stack. It may cause stack overflow. Custom allocators could help here (see #13)
  • Matrices and vectors are not initialized by default. An assertion will fail on access to uninitialized field only in Debug build
  • Some algorithms could be optimized to use CPU cache more effectively
  • operator,() in objects initialization ignores redundant so it's easy to make a mistake

Example of usage

Integration test is a good example of how to use the library.

CI

CI has some automated checks using Github workflows:

  • Clang-tidy checks
  • Build and run all tests for all awaliable build types

Notifications about failed workflows are sent to my Telegram.

Credits

Thanks to Timur Doumler for the really helpful talk about using C++ for real-time applications.

linalg_lib's People

Contributors

kuznetsss avatar

Watchers

 avatar  avatar

linalg_lib's Issues

Use dynamic memory

Instead of using stack to store matrix data some custom allocator could be used. It's possible to allocate some dynamic at an application start and use it as a memory pool in runtime having allocations with constant time cost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.