argamak 🐎

Hex Package Hex Docs License Build

A Gleam library for tensor maths.

“I admire the elegance of your method of computation; it must be nice to ride through these fields upon the horse of true mathematics while the like of us have to make our way laboriously on foot.”

—Albert Einstein, to Tullio Levi-Civita, circa 1915–1917

Argamak: A shiny steed.

Installation

As a dependency of your Gleam project

• Add argamak to gleam.toml from the command line

$ gleam add argamak

As a dependency of your Mix project

• Add argamak to mix.exs

defp deps do
  [
    {:argamak, "~> 0.2"},
  ]
end

As a dependency of your Rebar3 project

• Add argamak to rebar.config

{deps, [
  {argamak, "0.2.0"}
]}.

JavaScript

The @tensorflow/tfjs package is a runtime requirement for argamak, and its import path in the argamak_ffi.mjs module might need adjustment, depending on your use case.

Usage

// derby.gleam
import argamak/space
import argamak/tensor

pub type Axis {
  Horse
  Trial
}

pub fn print_times(from list: List(Float)) {
  assert Ok(space) = space.d2(#(Horse, 3), #(Trial, -1))
  try tensor = tensor.from_floats(of: list, into: space)

  tensor
  |> tensor.print(wrap_at: -1, meta: True)
  |> Ok
}

Example

> derby.print_times(from: [1.2, 1.3, 1.3, 1., 1.5, 0.9])
// Tensor
// format: Float32
// space: D2 #(Horse, 3), #(Trial, 2)
// data:
// [[1.2, 1.3],
//  [1.3, 1.0],
//  [1.5, 0.9]]
Ok(Nil)
Search Document