package caisar

  1. Overview
  2. Docs

Immutable tensor module

Tensors are multidimensional arrays used to represent numerical such as a neural network paramters.

This library relies on Bigarray.Genarray to instanciante tensors.

get t idx returns the value in tensor t stored at coordinates idx. Throw an error if the coordinate is invalid.

set_idx t idx v sets value v for tensor t at idx. Throw an error if the coordinate is invalid.

type ('a, 'b) t
val of_tensor : ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Genarray.t -> ('a, 'b) t
val to_tensor : ('a, 'b) t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Genarray.t
val create_1_float : float -> (float, Stdlib.Bigarray.float64_elt) t

create_1_float f returns an unidimentional tensor with one floating point value f.

val create_1_int64 : int64 -> (int64, Stdlib.Bigarray.int64_elt) t

create_1_int64 i returns an unidimentional tensor with one int64 value i.

val shape : ('a, 'b) t -> Shape.t
val flatten : ('a, 'b) t -> 'a list

flatten t returns all values stored in t as a flat list.

val of_array1 : Shape.t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> ('a, 'b) t
val reshape : Shape.t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Genarray.t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Genarray.t
val get : ('a, 'b) t -> int array -> 'a

get t sh returns the value stored at coordinates sh in t.

  • raises Invalid_argument

    if sh does not exactly match the shape of t, or if sh is out-of-bounds.

OCaml

Innovation. Community. Security.