All Projects → tanguyl → numerl

tanguyl / numerl

Licence: Apache-2.0 License
Small matrix library for Erlang.

Programming Languages

c
50402 projects - #5 most used programming language
erlang
1774 projects

Projects that are alternatives of or similar to numerl

hlml
vectorized high-level math library
Stars: ✭ 42 (+90.91%)
Mutual labels:  matrix
Scylla
An Elm-based front-end for Matrix.
Stars: ✭ 24 (+9.09%)
Mutual labels:  matrix
matrix-puppet-facebook
a puppetted facebook bridge
Stars: ✭ 90 (+309.09%)
Mutual labels:  matrix
matrix-tag-manager
A web interface for supporting power users and their Matrix room tags.
Stars: ✭ 22 (+0%)
Mutual labels:  matrix
DashGL-Library
Basic Matrix Manipulation Library For OpenGL Written in C
Stars: ✭ 20 (-9.09%)
Mutual labels:  matrix
monolish
monolish: MONOlithic LInear equation Solvers for Highly-parallel architecture
Stars: ✭ 166 (+654.55%)
Mutual labels:  matrix
TP Arduino DigitalRain Anim
A library that represents Digital Rain Animation on color displays that support TFT_eSPI
Stars: ✭ 80 (+263.64%)
Mutual labels:  matrix
python-twelve-tone
🎶 12-tone matrix to generate dodecaphonic melodies 🎶
Stars: ✭ 68 (+209.09%)
Mutual labels:  matrix
EventBus
💢 Nepxion EventBus is a generic event dispatching component based on Google Guava with Spring framework AOP, support synchronous and asynchronous mode 基于Google Guava通用事件派发机制的事件总线组件,注解式发布订阅
Stars: ✭ 65 (+195.45%)
Mutual labels:  matrix
canvas-cast
Cast any <canvas> element to an LED Matrix over WebSockets with an Arduino/ESP8266.
Stars: ✭ 39 (+77.27%)
Mutual labels:  matrix
addon-matrix
Matrix - Home Assistant Community Add-ons
Stars: ✭ 39 (+77.27%)
Mutual labels:  matrix
mtxclient
Client API library for Matrix, built on top of Boost.Asio
Stars: ✭ 21 (-4.55%)
Mutual labels:  matrix
Alchemy
CV DL
Stars: ✭ 59 (+168.18%)
Mutual labels:  matrix
zombi-addons
No description or website provided.
Stars: ✭ 15 (-31.82%)
Mutual labels:  matrix
chop
Round matrix elements to lower precision in MATLAB
Stars: ✭ 21 (-4.55%)
Mutual labels:  matrix
botdarr
Slack/Discord/Telegram/Matrix bot for accessing radarr, sonarr, and lidarr
Stars: ✭ 76 (+245.45%)
Mutual labels:  matrix
mxpp
Bot for bridging Matrix and XMPP
Stars: ✭ 23 (+4.55%)
Mutual labels:  matrix
Matswift
Matrix computation library in Swift
Stars: ✭ 17 (-22.73%)
Mutual labels:  matrix
glsl-rotate
GLSL rotation functions with matrices: 2D and 3D (with X/Y/Z convenience functions).
Stars: ✭ 54 (+145.45%)
Mutual labels:  matrix
alvito
Alvito - An Algorithm Visualization Tool for Python
Stars: ✭ 52 (+136.36%)
Mutual labels:  matrix

NUMERL

NUMeric ERLang is an API for matrix operations in Erlang. All functions (except [eval/1, rnd_matrix/1]) are implemented in NIFs; some make use of BLAS and LAPACKE [inv/1, nrm2/1, vec_dot/2, dot/2] for even better performances.

1ms rule

This library does not yet take into account the 1ms rule of NIFs; DO NOT USE BIG MATRICES yet.
Work is in progress to make numerl's functions execute on chunks of matrices in parallel, solving this issue and improving performances.
This will be solved by the end of 2022's Q1.

Usage

This library is a rebar3 dependency (https://github.com/erlang/rebar3):

    {deps, [{numerl, {git, "https://github.com/tanguyl/numerl.git", {branch, "master"}}}]}.

A numerl example can be found at https://github.com/tanguyl/raytracer.

Installation

Openblas and lapacke are mandatory to use this library.

Ubuntu-like os'es:

    sudo apt-get install libopenblas-dev liblapacke-dev

macOS:
lapacke is included through the accelerate framework; only openblas is required.

    brew install openblas

Windows:
Tested on WSL :)

MAN

API

The following functions are available:

Constructors     = [matrix/1, rnd_matrix/1, eye/1, zeros/2].
Comparator       = [equals/2].
Accessors         = [mtfli/1, mtfl/1, get/3, at/2, row/2, col/2].
Element_wise_ops = [add/2, sub/2 ,mult/2, divide/2].
Ops              = [inv/1, nrm2/1, vec_dot/2, dot/2, transpose/1].

Matrices

Matrices are defined as follows:

-record(matrix,{n_rows, n_cols, bin}).

The bin field is a Binary, containing the represented matrices values stored as doubles.

Constructors

The following functions can be used to create matrices:

Constructors = [matrix/1, rnd_matrix/1, eye/1, zeros/2].

They can be used as follows:

% FCT                              INPUT(S)   OUTPUT    
numerl:matrix([[1, 2.0],[3, 4.0]]).% L    
numerl:rnd_matrix(2).              % N,     random   matrix of size NxN.
numerl:eye(2).                     % N,     identity matrix of size NxN.
numerl:zeros(2, 2).                % N,M    empty    matrix of size NxM.

The matrix/1 takes as input a list of rows.

Comparator

Matrices are stored as arrays of doubles, the granularity of which makes the ==/2 operator unadviced. Instead, numerl provides its own comparison operator:

Comparator = [equals/2].

It should be used as follows:

E = numerl:eye(2),                 %
Z = numerl:zeros(2,2),             %
%FCT                               INPUTS
Boolean = numerl:equals(E,Z).      % M1,M2: compared matrices.

Accessors

Matrices content can be extracted with the following functions:

Accessors = [mtfli/1, mtfl/1, row/2, col/2, get/3, at/2].

They are used as such:

M = numerl:matrix([[1,2,3]]),
P = numerl:matrix([[1]]),   
N = 1,                             
O = 1,                             
%Output         Fct                 Input
[1,2,3]       = numerl:mtfli(M),   % matrix M
[1.0,2.0,3.0] = numerl:mtfl(M),    % Matrix M
M             = numerl:row(M,N),   % N  in [1, M.n_rows], M
P             = numerl:col(M,N),   % N  in [1, M.n_cols], M
1.0           = numerl:get(M,N,O), % N in
1.0           = numerl:at(M,N).    % The N'th element of the matrix.

Element-wise operations

The following operations can be done element-wise on matrices:

Element_wise_ops = [add/2, sub/2 ,mult/2, divide/2].

They have the following usage:

%FCT                               INPUTS
op(Lval, Rval).                    % Lval: a matrix, Rval: a matrix || a number

For divide/2 op used with Rval either null or containing a null value, a badarg is thrown.

These ops can be combined with the eval/1 function:

M = numerl:rnd_matrix(2),
%FCT                               INPUTS
numerl:eval([M, add, 1,            % L: a list of V1,Op1,V2,OP2...
             divide, 2,
              mult, M]).

More functions

Ops = [inv/1, nrm2/1, vec_dot/2, dot/2, transpose/1].

Inv

Returns the inverse of input function.

M = numerl:rnd_matrix(2),
P = numerl:inv(M).

A badarg is thrown for input non-square matrix; and error "nif_inv: could not invert singular matrix." is thrown in case of input singular matrix.

Implementation is based upon a LAPACKE LU's decomposition/inversion.

nrm2

Returns the root square of the sum of the squared elements of input matrix.

P   = numerl:matrix([[-3]]),
3.0 = numerl:nrm2(P).

vec_dot

Returns the sum of element-wise multiplication of input matrices.

Q    = numerl:matrix([[1,2]]),
R    = numerl:matrix([[3,4]]),
11.0 = numerl:vec_dot(Q,R).

Input matrices need to contain the same number of elements; but their dimensions do not need to match.

dot

Returns the product of input matrices.

I    = numerl:eye(2),
I2   = numerl:mult(I,2),
M    = numerl:matrix([[1,2], [3,4]]),
R    = numerl:dot(M,I2).

transpose

Returns the transpose of input matrix.

I = numerl:eye(2),
It = numerl:transpose(I),
true = numerl:equals(I,It).
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].