View Source CEM.MapMatrix (cem v0.1.1)

A matrix data structure based on nested maps with a very limited set of operations.

For certain problems, it's more performant to use MapMatrix operations than the equivalent opertations on Nx tensors.

Summary

Functions

Given a list of lists of values, return a MapMatrix.

Collect values at the given index pairs [{i, j},...] into a list.

Get the value at the given index pair {i, j}.

Set the value at the given index pair {i, j}.

Return the shape {n_row, n_col} of the MapMatrix.

Convert the MapMatrix to a list of lists of values.

Create a MapMatrix with the shape {n_row, n_col} and all values set to zero.

Types

@type index() :: non_neg_integer()
@type shape() :: {pos_integer(), pos_integer()}
@type t() :: %CEM.MapMatrix{
  matrix: %{required(index()) => %{required(index()) => number()}},
  shape: shape()
}

Functions

Link to this function

from_list(list_of_lists)

View Source
@spec from_list([[number()]]) :: t()

Given a list of lists of values, return a MapMatrix.

This is useful when converting an Nx tensor to a MapMatrix.

@spec gather(t(), [{index(), index()}]) :: [number()]

Collect values at the given index pairs [{i, j},...] into a list.

This is similar to Nx.gather/2.

@spec get(
  t(),
  {index(), index()}
) :: number()

Get the value at the given index pair {i, j}.

@spec put(t(), {index(), index()}, number()) :: t()

Set the value at the given index pair {i, j}.

@spec shape(t()) :: shape()

Return the shape {n_row, n_col} of the MapMatrix.

@spec to_list(t()) :: [[number()]]

Convert the MapMatrix to a list of lists of values.

The result can be passed directly to Nx.tensor/1 to get the tensor representation of the matrix.

@spec zero(shape()) :: t()

Create a MapMatrix with the shape {n_row, n_col} and all values set to zero.