ExZarr.Gallery.Pack (ExZarr v1.1.0)

View Source

Small helpers for Livebook tutorials: pack/unpack Elixir numbers into the row-major binaries expected by ExZarr.Array.get_slice/2 and set_slice/3.

This module is intentionally tiny and dependency-free.

Summary

Functions

Packs a flat list of numbers into a binary for the given dtype.

Unpacks a binary into a flat list of numbers for the given dtype.

Types

dtype()

@type dtype() ::
  :int8
  | :uint8
  | :int16
  | :uint16
  | :int32
  | :uint32
  | :int64
  | :uint64
  | :float32
  | :float64

Functions

itemsize(atom)

@spec itemsize(
  :float32
  | :float64
  | :int16
  | :int32
  | :int64
  | :int8
  | :uint16
  | :uint32
  | :uint64
  | :uint8
) :: 1 | 2 | 4 | 8

pack(list, dtype)

@spec pack([number()], dtype()) :: binary()

Packs a flat list of numbers into a binary for the given dtype.

Notes:

  • ExZarr uses little-endian primitives.
  • For signed ints we use signed-little.
  • For floats we use IEEE 754 float-little.

unpack(bin, dtype)

@spec unpack(binary(), dtype()) :: [number()]

Unpacks a binary into a flat list of numbers for the given dtype.