All Projects → Octachron → tensority

Octachron / tensority

Licence: GPL-3.0 license
Strongly typed multidimensional array library for OCaml

Programming Languages

ocaml
1615 projects

Projects that are alternatives of or similar to tensority

Arraymancer
A fast, ergonomic and portable tensor library in Nim with a deep learning focus for CPU, GPU and embedded devices via OpenMP, Cuda and OpenCL backends
Stars: ✭ 793 (+1702.27%)
Mutual labels:  tensor, multidimensional-arrays
Hptt
High-Performance Tensor Transpose library
Stars: ✭ 141 (+220.45%)
Mutual labels:  tensor, multidimensional-arrays
Tensor
package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Stars: ✭ 222 (+404.55%)
Mutual labels:  tensor, multidimensional-arrays
bs-getenv
ReasonML/BuckleScript PPX for embedding env variables
Stars: ✭ 25 (-43.18%)
Mutual labels:  ppx
gmap
heterogenous Map over a GADT
Stars: ✭ 40 (-9.09%)
Mutual labels:  gadt
Tensors.jl
Efficient computations with symmetric and non-symmetric tensors with support for automatic differentiation.
Stars: ✭ 142 (+222.73%)
Mutual labels:  tensor
ostd
Online Stochastic Tensor Decomposition for Background Subtraction in Multispectral Video Sequences
Stars: ✭ 21 (-52.27%)
Mutual labels:  tensor
rescript-logger
Logging implementation for ReScript
Stars: ✭ 103 (+134.09%)
Mutual labels:  ppx
jsoo-react
js_of_ocaml bindings for ReactJS. Based on ReasonReact.
Stars: ✭ 126 (+186.36%)
Mutual labels:  ppx
OLSTEC
OnLine Low-rank Subspace tracking by TEnsor CP Decomposition in Matlab: Version 1.0.1
Stars: ✭ 30 (-31.82%)
Mutual labels:  tensor
tentris
Tentris is a tensor-based RDF triple store with SPARQL support.
Stars: ✭ 34 (-22.73%)
Mutual labels:  tensor
leibniz
Leibniz equivalence and Liskov substitutability library for Scala.
Stars: ✭ 35 (-20.45%)
Mutual labels:  gadt
pytorch-examples-cn
用例子学习PyTorch1.0(Learning PyTorch with Examples 中文翻译与学习)
Stars: ✭ 54 (+22.73%)
Mutual labels:  tensor
ke
Fast implementation of queue in OCaml
Stars: ✭ 42 (-4.55%)
Mutual labels:  gadt
proxifier-rules
Rules for proxifiers programs: Proxifier
Stars: ✭ 51 (+15.91%)
Mutual labels:  ppx
awesome-ppx-reasonml
curated list of reasonml PPX rewriter
Stars: ✭ 28 (-36.36%)
Mutual labels:  ppx
Xtensor.jl
Julia package for xtensor-julia
Stars: ✭ 38 (-13.64%)
Mutual labels:  tensor
zarray
Dynamically typed N-D expression system based on xtensor
Stars: ✭ 23 (-47.73%)
Mutual labels:  multidimensional-arrays
Gisola
Gisola: A High Performance Computing application for real-time Moment Tensor inversion
Stars: ✭ 35 (-20.45%)
Mutual labels:  tensor
BTAS
Basic Tensor Algebra Subroutines
Stars: ✭ 35 (-20.45%)
Mutual labels:  tensor

Beware: This is a work in progress on a highly experimental prototype. Do not expect backward compatibility, performance nor correctness.

Tensority is an experience in designing a library for strongly-typed multidimensional arrays and tensors manipulation. Tensority aims to cover three levels of compile-time safety:

  • tensor order level:

    • the type of multidimensional arrays should distinguish between arrays of different dimensions
    • the type of tensor should moreover distinguish between an vector and 1-form, i.e between (1 + 0) tensor and (0 + 1) tensors
  • dimension level:

    • adding two vectors of different dimensions should be a type error
  • index level

    • trying to access the k+1th elements of an array of size k should be an error

Each level of safety restricts the number of functions implementable using tensority safe interface. However, non-trivial functions can still be implemented using this safe interface.

Examples

With the included ppx extension, tensority looks like:

open Tensority
open Multidim_array
open Shape

(* Multidimensional array literals *)
let array4 = [%array 4
      [
        [1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12];
        [1, 2; 8, 9], [9, 1; 2, 3], [19, 12; 14, 17]
      ]
];;

(* Definition using function *)
let array = init_sh [502103s] (function [k] -> Nat.to_int k)

(* accessing an element *)
let one = array4.( 1i, 0i, 0i, 0i ) ;;

(* accessing an element with an out-of-bound type error *)
let one = array4.( 1i, 5i, 0i, 1i ) ;;

(* element assignment *)
array4.(0i,0i,0i,0i) <- 0;;

(* slicing *)
let matrix = array4.!( All, All, 1j, 1j );;
(* matrix is [9, 1; 2, 3] *)

(* slice assignment *)
let row = [%array (2,3) ];;
matrix.!(All, 0j) <- row;;
(* matrix is now [2, 3; 2, 3] *)

(* range slice *)
let array' = array.!([%range 25 50 ~by:5])
(* or *)
let array' = array.!( 25 #-># 50 ## 5 )

Examples without ppx

Note that most of the ppx transformations are local, without rewriter the previous example would become

open Tensority
open Multidim_array
open Shape
open Nat_defs

(* Multidimensional array literals *)
let array4 = Unsafe.create [ _2; _2; _3; _2 ]
[| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12;
   1; 2; 8; 9; 9; 1; 2; 3; 19; 12; 14; 17
|]

(* Definition using function *)
let array = init_sh Size.[nat _5 @ _0 @ _2 @ _1 @ _0 @ _3n]
  (function [k] -> Nat.to_int k)

(* accessing an element *)
let one = array4.%( [ _1i; _0i; _0i; _0i] ) ;;

(* accessing an element with an out-of-bound type error *)
let one = array4.%([ _1i; _5i; _0i; _1i ] ) ;;

(* element assignment *)
array4.%([ _0i; _0i; _0i; _0i ]) <- 0;;

(* slicing *)
let matrix = array4.%[[ All; All; Elt _1i;  Elt _1i ]];;
(* matrix is [9, 1; 2, 3] *)

(* slice assignment *)
let row = Unsafe.create [_2] [| 2; 3 |];;
matrix.%[[ All; Elt _0i]] <- row
(* matrix is now [2, 3; 2, 3] *)

(* range slice *)
let r= Range.create ~by: 5 ~start:Indices.(nat _2 @ 5n)
  ~stop:Indices.(nat _5 @ 0n) ~len:_10

let array' = array.%[[Range r]]
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].