All Projects → calebzulawski → Cotila

calebzulawski / Cotila

Licence: other
A compile-time linear algebra system for C++

Projects that are alternatives of or similar to Cotila

lubeck
High level linear algebra library for Dlang
Stars: ✭ 57 (-26.92%)
Mutual labels:  linear-algebra, blas
optimath
A #[no_std] LinAlg library
Stars: ✭ 47 (-39.74%)
Mutual labels:  linear-algebra, blas
mfi
Modern Fortran Interfaces to BLAS and LAPACK
Stars: ✭ 31 (-60.26%)
Mutual labels:  linear-algebra, blas
Cython Blis
💥 Fast matrix-multiplication as a self-contained Python library – no system dependencies!
Stars: ✭ 165 (+111.54%)
Mutual labels:  linear-algebra, blas
Armadillo Code
Armadillo: fast C++ library for linear algebra & scientific computing - http://arma.sourceforge.net
Stars: ✭ 388 (+397.44%)
Mutual labels:  linear-algebra, blas
Blasjs
Pure Javascript manually written 👌 implementation of BLAS, Many numerical software applications use BLAS computations, including Armadillo, LAPACK, LINPACK, GNU Octave, Mathematica, MATLAB, NumPy, R, and Julia.
Stars: ✭ 241 (+208.97%)
Mutual labels:  linear-algebra, blas
sblas
Scala Native BLAS (Basic Linear Algebra Subprograms) supporting Linux and macOS
Stars: ✭ 25 (-67.95%)
Mutual labels:  linear-algebra, blas
Xtensor Blas
BLAS extension to xtensor
Stars: ✭ 102 (+30.77%)
Mutual labels:  linear-algebra, blas
MatlabJuliaMatrixOperationsBenchmark
Benchmark MATLAB & Julia for Matrix Operations
Stars: ✭ 21 (-73.08%)
Mutual labels:  linear-algebra, blas
monolish
monolish: MONOlithic LInear equation Solvers for Highly-parallel architecture
Stars: ✭ 166 (+112.82%)
Mutual labels:  linear-algebra, blas
Eigen Git Mirror
THIS MIRROR IS DEPRECATED -- New url: https://gitlab.com/libeigen/eigen
Stars: ✭ 1,659 (+2026.92%)
Mutual labels:  linear-algebra, blas
Fmatvec
A fast vector/matrix library
Stars: ✭ 5 (-93.59%)
Mutual labels:  linear-algebra, blas
Blasfeo
Basic linear algebra subroutines for embedded optimization
Stars: ✭ 120 (+53.85%)
Mutual labels:  linear-algebra, blas
linnea
Linnea is an experimental tool for the automatic generation of optimized code for linear algebra problems.
Stars: ✭ 60 (-23.08%)
Mutual labels:  linear-algebra, blas
Kokkos Kernels
Kokkos C++ Performance Portability Programming EcoSystem: Math Kernels - Provides BLAS, Sparse BLAS and Graph Kernels
Stars: ✭ 113 (+44.87%)
Mutual labels:  linear-algebra, blas
fml
Fused Matrix Library
Stars: ✭ 24 (-69.23%)
Mutual labels:  linear-algebra, blas
Lacaml
OCaml bindings for BLAS/LAPACK (high-performance linear algebra Fortran libraries)
Stars: ✭ 101 (+29.49%)
Mutual labels:  linear-algebra, blas
dbcsr
DBCSR: Distributed Block Compressed Sparse Row matrix library
Stars: ✭ 65 (-16.67%)
Mutual labels:  linear-algebra, blas
Vectorious
Linear algebra in TypeScript.
Stars: ✭ 616 (+689.74%)
Mutual labels:  linear-algebra, blas
Blis
BLAS-like Library Instantiation Software Framework
Stars: ✭ 859 (+1001.28%)
Mutual labels:  linear-algebra, blas

Build Status License GitHub release

Overview

Cotila (compile-time linear algebra) is a header-only library that provides a set of linear algebra functions in C++ intended for use during compile time. All functions available in Cotila are constexpr, meaning they can be used at compile-time to generate constants and lookup tables in a type-safe, readable, and maintainable manner.

Installation

Cotila is a header-only library. Simply point your compiler to include the include/ directory.

If you are using CMake, you can also import the cotila::cotila library.

Code must be compiled with at least C++17 support to use Cotila.

Documentation

The current documentaiton is available online.

The documentation can also be built with CMake and Doxygen:

cmake -D BUILD_DOCS=ON -B build .
cmake --build build --target doc

Quickstart Guide

To use Cotila, all you need to do is #include <cotila/cotila.h>. This header will include all of the headers provided by Cotila.

The Cotila interface is designed around operations commonly found in BLAS or MATLAB and should be simple and predictable.

Types

Cotila provides support for three types: scalars, vectors, and matrices.

Scalars are represented by fundamental types, such as float or double, as well as std::complex. Cotila provides a variety of operations that manipulate scalar types. In some cases, such as square roots, a standard library implementation already exists but it is not constexpr. A simple example below:

constexpr double s = cotila::sqrt(4.);
static_assert(s == 2.); // this evaluates and passes at compile time

Vectors are represented by the cotila::vector class. The vector class is a container for scalar types. Additionally, vector is an aggregate class containing a single array and is constructed via aggregate initialization. If you are confused, some notes on aggregate initialization can be found in the next section. A simple vector example:

constexpr cotila::vector<double, 3> v1 {{1., -2., 3.}}; // very explicit declaration
constexpr cotila::vector v2 {1., 2., 3.}; // deduces the type, omits the extra braces via uniform initialization
static_assert(v2 == cotila::abs(v1));

Matrices are represented by the cotila::matrix class. Like the vector class, matrix is an aggregate class containing a single 2-dimensional array. A matrix is initialized like a normal 2-dimensional array in C++ (i.e. row-major order). A simple matrix example:

/*  m1 contains:        m2 contains:
 *  1 2 3               1 4
 *  4 5 6               2 5
 *                      3 6
 */
constexpr cotila::matrix<double, 2, 3> m1 {{{1., 2., 3.}, {4., 5., 6.}}}; // very explicit declaration
constexpr cotila::matrix m2 {{{1., 4.}, {2., 5.}, {3., 6.}}}; // deduces the type, but the extra braces are required
static_assert(m2 == cotila::transpose(m1));

Complex values are not handled any differently, other than initialization:

/*  m1 contains:        m2 contains:
 *  1 + 0i   2 + 1i     1 + 0i   3 + 1i
 *  3 - 1i   4 + 2i     2 - 1i   4 - 2i
 *
 */
constexpr cotila::matrix<std::complex<double>, 2, 2> m1 {{{{1., 0.}, {2., 1.}}, {{3., -1.}, {4., 2.}}}};
constexpr cotila::matrix m2 {{{{1., 0.}, {3., 1.}}, {{2., -1.}, {4., -2.}}}}; // complex types can be deduced, too!
static_assert(m2 = cotila::hermitian(m1));

Aggregate Initialization

Aggregate objects can be initialized similarly to C structs by simply providing an initializer list with the values to initialize each member. In C++, arrays can be initialized like so:

double arr[3] = {1., 2., 3.};

or

double arr[3] {1., 2., 3.};

The cotila::vector class contains a single array:

template<typename T, std::size_t N>
struct vector {
    T arr[N];
};

To initialize a vector, you must initialize the array member, which results in an extra set of braces:

vector<double, 3> v = {{1., 2., 3.}};

or

vector<double, 3> v {{1., 2., 3.}};

Uniform initialization

Aggregate objects with a single member can be initialized with uniform initialization, which allows you to omit the extra braces:

vector<double, 3> v {1., 2., 3.};

You may omit the extra braces on cotila::matrix, however this can get confusing. You may not use nested initializer lists for uniform initialization, so the elements must be listed in row-major order:

matrix<double, 2, 2> m {1., 2., 3., 4.}; // first row contains [1, 2], second row contains [3, 4]

Class template argument deduction

Cotila's vectors and matrices support class template argument deduction. This allows you to omit the template arguments entirely:

vector v1 {1., 2., 3.};   // uniform initialization
vector v2 {{1., 2., 3.}}; // normal aggregate initialization

Matrices do not support template argument deduction for uniform initialization, since it is impossible to deduce the shape of the matrix. In this case, an extra set of braces is always required:

matrix m {{{1., 2.}, {3., 4.}}};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].