tensor_file.bend checks
raw source on the hub · import stelliferous@0.0.4.0/tensor_file.bend as Tensor_file
Raw files of FP32 or U8 values and NumPy .npy files through the official File effects, and the reader that other formats share: a byte range of an open file, decoded element by element, written straight into a tensor's storage.
6 imports
import Base import ./storage_bytes.bend as Bytes import ./storage_element_format.bend as Formats import ./math_fp32.bend as Fp32 import ./storage_buffer.bend as Buffers import ./tensor.bend as Tensors
Types
type Partial source · line 36 · raw
Data
An element in progress: its first four bytes, the bytes above them, the weight of the next byte within its word, and how many bytes arrived.
Partial@low:U32 -> @high:U32 -> @weight:U32 -> @filled:U32 -> Partial
type Words source · line 39 · raw
Data
Words@values:List<&2, F32> -> @count:U32 -> @partial:Partial -> Words
type Target source · line 43 · raw
Type
The buffer of the tensor, the values found so far, and an element in progress.
Target@buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32> -> @found:U32 -> @partial:Partial -> Target
type Reading source · line 46 · raw
Type
More@file:File -> @position:U32 -> @remaining:U32 -> @target:Target -> Reading
End@file:File -> @target:Target -> @complete:Bool -> Reading
type Outcome source · line 50 · raw
Type
Outcome@file:File -> @target:Target -> @complete:Bool -> Outcome
type Header source · line 289 · raw
Data
The shape and the position of the first value.
Header@shape:List<&2, U32> -> @data:U32 -> Header
type Writing source · line 395 · raw
Type
Pending@file:File -> @storage:Array<F32> -> @offset:U32 -> @remaining:Nat -> Writing
Finished@file:File -> @complete:Bool -> Writing
Definitions
def Tensor source · line 11 · raw
Type
def Read source · line 14 · raw
Type
def Written source · line 17 · raw
Type
def Sized source · line 20 · raw
Type
def chunk source · line 24 · raw
U32
FP32 values per File effect; a read takes four times as many bytes.
def chunk_bytes source · line 27 · raw
U32
def fresh_partial source · line 53 · raw
Partial
def gathered source · line 56 · raw
@lower:Bool -> @done:Bool -> @wrap:Bool -> @+byte:U32 -> @format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @values:List<&2, F32> -> @+count:U32 -> @+low:U32 -> @+high:U32 -> @+weight:U32 -> @+filled:U32 -> Words
def push source · line 64 · raw
@+byte:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @words:Words -> Words
def trickle source · line 69 · raw
@bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @words:Words -> Words
def singles source · line 75 · raw
@bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @values:List<&2, F32> -> @+count:U32 -> Words
Whole elements at a time while the bytes allow; the values are newest first.
def pairs source · line 80 · raw
@bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @values:List<&2, F32> -> @+count:U32 -> Words
def quads source · line 86 · raw
@bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @values:List<&2, F32> -> @+count:U32 -> Words
def octets source · line 92 · raw
@bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @values:List<&2, F32> -> @+count:U32 -> Words
def by_width source · line 99 · raw
@+width:U32 -> @bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> Words
def words source · line 107 · raw
@whole:Bool -> @bytes:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @partial:Partial -> Words
def within source · line 113 · raw
@fits:Bool -> @+room:U32 -> @values:List<&2, F32> -> List<&2, F32>
Values beyond the count of the shape are counted and not written.
def placed source · line 118 · raw
@read:Words -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32> -> @+found:U32 -> @+count:U32 -> Target
def fill source · line 124 · raw
@bytes:List<&2, U32> -> @target:Target -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> Target
def ranged source · line 129 · raw
@exhausted:Bool -> @file:File -> @+position:U32 -> @+remaining:U32 -> @target:Target -> Reading
def advanced source · line 135 · raw
@target:Target -> @file:File -> @+position:U32 -> @+remaining:U32 -> @+width:U32 -> @+found:U32 -> @+held:U32 -> Reading
The bytes of a read are the elements it added and the change of the element in progress.
def absorbed source · line 142 · raw
@bytes:List<&2, U32> -> @file:File -> @+position:U32 -> @+remaining:U32 -> @target:Target -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> Reading
A read that ends early leaves the count short, which the count check reports.
def received source · line 150 · raw
@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @file:File -> @+position:U32 -> @+remaining:U32 -> @target:Target -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> Reading
def taken source · line 155 · raw
@read:Read -> @+position:U32 -> @+remaining:U32 -> @target:Target -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> Reading
def read_all source · line 159 · raw
@fuel:Nat -> @reading:Reading -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> IO(Outcome)
def fresh source · line 169 · raw
@+count:U32 -> Target
def fuel source · line 172 · raw
@+length:U32 -> Nat
def read_range source · line 177 · raw
@file:File -> @+position:U32 -> @+length:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> IO(Outcome)
The elements stored from the position on, as many bytes as the count of the format takes; the file stays open.
def fault source · line 180 · raw
@operation:String -> @path:String -> @detail:String -> @shape:List<&2, U32> -> Tensor
def sized source · line 183 · raw
@matches:Bool -> @operation:String -> @path:String -> @+shape:List<&2, U32> -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32> -> Tensor
def whole source · line 188 · raw
@aligned:Bool -> @operation:String -> @path:String -> @+shape:List<&2, U32> -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32> -> @+found:U32 -> @+count:U32 -> Tensor
def aligned source · line 193 · raw
@operation:String -> @path:String -> @+shape:List<&2, U32> -> @target:Target -> @+count:U32 -> Tensor
def checked source · line 198 · raw
@complete:Bool -> @operation:String -> @path:String -> @+shape:List<&2, U32> -> @target:Target -> @+count:U32 -> Tensor
def decoded source · line 203 · raw
@operation:String -> @path:String -> @+shape:List<&2, U32> -> @outcome:Outcome -> @+count:U32 -> Pair(File, Tensor)
def ranged_count source · line 207 · raw
@fits:Bool -> @file:File -> @operation:String -> @path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+length:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> @+count:U32 -> IO(Pair(File, Tensor))
def ranged_shape source · line 215 · raw
@count:Maybe<&2, U32> -> @file:File -> @operation:String -> @path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def load_range source · line 224 · raw
@file:File -> @operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
The tensor of the shape whose elements of the format start at the position of an open file, which stays open.
def closed source · line 227 · raw
@pair:Pair(File, Tensor) -> IO(Tensor)
def refused source · line 233 · raw
@file:File -> @tensor:Tensor -> IO(Tensor)
def measured source · line 240 · raw
@aligned:Bool -> @matches:Bool -> @file:File -> @operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
A raw file holds exactly the bytes of its shape: a size that is not a whole number of values, or another number of them, is refused before reading.
def with_size source · line 249 · raw
@result:Result<&1, &1, Pair(U32, String), U32> -> @file:File -> @operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+count:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
def sized_file source · line 255 · raw
@sized:Sized -> @operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+count:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
def stored_values source · line 259 · raw
@file:File -> @operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+position:U32 -> @+count:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
def opened source · line 264 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @+operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+count:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
def counted source · line 269 · raw
@count:Maybe<&2, U32> -> @+operation:String -> @+path:String -> @+shape:List<&2, U32> -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Tensor)
def load source · line 278 · raw
@+path:String -> @+shape:List<&2, U32> -> IO(Tensor)
The file holds the values of the shape in row-major order and nothing else.
def load_u8 source · line 282 · raw
@+path:String -> @+shape:List<&2, U32> -> IO(Tensor)
The same for one byte per value, each an FP32 from 0 to 255.
def magic source · line 292 · raw
List<&2, U32>
def contains source · line 295 · raw
@text:List<&2, U32> -> @+pattern:List<&2, U32> -> Bool
def after source · line 301 · raw
@text:List<&2, U32> -> @+pattern:List<&2, U32> -> Maybe<&2, List<&2, U32>>
The text after the first occurrence of the pattern.
def pushed source · line 307 · raw
@digits:Bool -> @current:U32 -> @shape:List<&2, U32> -> List<&2, U32>
def closed_shape source · line 312 · raw
@valid:Bool -> @shape:List<&2, U32> -> Maybe<&2, List<&2, U32>>
def extents source · line 318 · raw
@text:List<&2, U32> -> @+current:U32 -> @digits:Bool -> @valid:Bool -> @shape:List<&2, U32> -> Maybe<&2, List<&2, U32>>
Extents up to the closing parenthesis: digits, commas and spaces.
def shaped source · line 328 · raw
@shape:Maybe<&2, List<&2, U32>> -> @+data:U32 -> Maybe<&2, Header>
def typed source · line 333 · raw
@supported:Bool -> @text:Maybe<&2, List<&2, U32>> -> @+data:U32 -> Maybe<&2, Header>
def described source · line 339 · raw
@+text:List<&2, U32> -> @+length:Nat -> @+data:U32 -> Maybe<&2, Header>
def region source · line 343 · raw
@+bytes:List<&2, U32> -> @+prefix:U32 -> @+length:U32 -> Maybe<&2, Header>
def versioned source · line 347 · raw
@major:U32 -> @+bytes:List<&2, U32> -> Maybe<&2, Header>
Version 1 has a two-byte header length; later versions have four bytes.
def marked source · line 352 · raw
@valid:Bool -> @+bytes:List<&2, U32> -> Maybe<&2, Header>
def header source · line 357 · raw
@+bytes:List<&2, U32> -> Maybe<&2, Header>
def npy_counted source · line 360 · raw
@count:Maybe<&2, U32> -> @+shape:List<&2, U32> -> @+data:U32 -> @file:File -> @+path:String -> IO(Tensor)
def npy_parsed source · line 365 · raw
@parsed:Maybe<&2, Header> -> @file:File -> @+path:String -> IO(Tensor)
def npy_received source · line 370 · raw
@result:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @file:File -> @+path:String -> IO(Tensor)
def npy_headed source · line 375 · raw
@read:Read -> @+path:String -> IO(Tensor)
def npy_opened source · line 379 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @+path:String -> IO(Tensor)
def load_npy source · line 388 · raw
@+path:String -> IO(Tensor)
An FP32 array saved by NumPy, with its shape.
def bytes source · line 399 · raw
@+word:U32 -> @rest:List<&2, U32> -> List<&2, U32>
def encode source · line 402 · raw
@count:Nat -> @values:List<&2, F32> -> List<&2, U32>
def read_chunk source · line 409 · raw
@count:Nat -> @+offset:U32 -> @storage:Array<F32> -> @values:List<&2, F32> -> Pair(Array<F32>, List<&2, F32>)
The cursor retains the array; only the current chunk becomes a list.
def pending source · line 416 · raw
@remaining:Nat -> @file:File -> @storage:Array<F32> -> @offset:U32 -> Writing
def continued source · line 421 · raw
@result:Result<&1, &1, Pair(U32, String), Unit> -> @file:File -> @storage:Array<F32> -> @remaining:Nat -> @offset:U32 -> Writing
def after_write source · line 426 · raw
@written:Written -> @storage:Array<F32> -> @remaining:Nat -> @offset:U32 -> Writing
def write_chunk source · line 430 · raw
@file:File -> @read:Pair(Array<F32>, List<&2, F32>) -> @+count:Nat -> @remaining:Nat -> @offset:U32 -> IO(Writing)
def finished source · line 436 · raw
@file:File -> @complete:Bool -> IO(Bool)
def write_all source · line 441 · raw
@fuel:Nat -> @writing:Writing -> IO(Bool)
def unsaved source · line 452 · raw
@pair:Pair(Tensor, List<&2, U32>) -> @operation:String -> @path:String -> @detail:String -> Tensor
def written source · line 456 · raw
@complete:Bool -> @operation:String -> @path:String -> @tensor:Tensor -> Tensor
def created source · line 462 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @operation:String -> @+path:String -> @tensor:Tensor -> @prefix:List<&2, U32> -> @storage:Array<F32> -> @+length:Nat -> IO(Tensor)
The prefix is written first; a raw file has none.
def saving source · line 471 · raw
@operation:String -> @+path:String -> @tensor:Tensor -> @prefix:List<&2, U32> -> @buffer:Result<&2, &1, 0xa2af805348d03b11eb853850859654f6/tensor.Problem, 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32>> -> IO(Tensor)
def save source · line 481 · raw
@+path:String -> @tensor:Tensor -> IO(Tensor)
Writes the values in row-major order and returns the tensor. A failed tensor writes nothing and keeps its problem.
def joined source · line 484 · raw
@shape:List<&2, U32> -> String
def tuple source · line 491 · raw
@shape:List<&2, U32> -> String
NumPy writes (), (3,) and (2, 3).
def spaces source · line 497 · raw
@count:Nat -> List<&2, U32>
def framed source · line 503 · raw
@+text:List<&2, U32> -> @+length:U32 -> List<&2, U32>
Version 1: the header ends in a newline and the data starts at a multiple of 64 bytes.
def npy_header source · line 508 · raw
@shape:List<&2, U32> -> List<&2, U32>
def npy_saving source · line 512 · raw
@+path:String -> @pair:Pair(Tensor, Tensor) -> @+shape:List<&2, U32> -> IO(Tensor)
def save_npy source · line 517 · raw
@+path:String -> @tensor:Tensor -> IO(Tensor)
Writes a .npy file that NumPy loads with the tensor's shape.