io.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-f32array@0.2.3.0/io.bend as Io
File reads for packed F32 arrays, kept outside the pure proof imports.
4 imports
import Base import ./f32array.bend as A import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes import bend-kit-files@0.4.0.1/files.bend as Files
Types
type Read source · line 8 · raw
Type
A file read in progress: more bytes to read, or the final result.
More@file:File -> @acc:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @left:U32 -> Read
Stop@file:File -> @result:Result<&1, &1, Pair(U32, String), 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> Read
type Tensor source · line 84 · raw
Type
Tensor@array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @bits:U32 -> @used:U32 -> @index:U32 -> Tensor
type AtRead source · line 108 · raw
Type
AtMore@file:File -> @hi:U32 -> @lo:U32 -> @left:U32 -> @state:Tensor -> AtRead
AtStop@file:File -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @result:Result<&1, &1, Pair(U32, String), Unit> -> AtRead
Definitions
def read.next source · line 12 · raw
@more:Bool -> @file:File -> @acc:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+left:U32 -> Read
def read.step source · line 20 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>) -> @acc:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+left:U32 -> Read
A read of no bytes ends the loop early, so a file that shrank stops there.
def read.loop source · line 30 · raw
@n:Nat -> @st:Read -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>))
Each pass reads at least one byte or stops, so left + 1 passes are enough.
def read.sized source · line 47 · raw
@sz:Pair(File, Result<&1, &1, Pair(U32, String), U32>) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>))
def read.decode source · line 55 · raw
@m:Maybe<&1, 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array> -> Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>
def read.le source · line 77 · raw
@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
The rest of an open file, four little-endian bytes per element. Fails EINVAL when its size is not a multiple of 4.
def read.be source · line 81 · raw
@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
The rest of an open file, four big-endian bytes per element. Fails EINVAL when its size is not a multiple of 4.
def tensor.byte source · line 87 · raw
@full:Bool -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @+bits:U32 -> @+used:U32 -> @+index:U32 -> @+width:U32 -> Tensor
def tensor.take source · line 94 · raw
@state:Tensor -> @+width:U32 -> @byte:U32 -> Tensor
def tensor.bytes source · line 100 · raw
@n:Nat -> @pair:Pair(Array<U32>, U32) -> @+at:U32 -> @state:Tensor -> @+width:U32 -> Tensor
def read.at.stop source · line 112 · raw
@file:File -> @state:Tensor -> @result:Result<&1, &1, Pair(U32, String), Unit> -> AtRead
def read.at.next source · line 116 · raw
@done:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @left:U32 -> @state:Tensor -> AtRead
def read.at.bytes source · line 123 · raw
@empty:Bool -> @file:File -> @+hi:U32 -> @+lo:U32 -> @+left:U32 -> @state:Tensor -> @+got:U32 -> @words:Array<U32> -> @+width:U32 -> AtRead
def read.at.step source · line 133 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @hi:U32 -> @lo:U32 -> @left:U32 -> @state:Tensor -> @+width:U32 -> AtRead
def read.at.loop source · line 141 · raw
@n:Nat -> @state:AtRead -> @+width:U32 -> IO(Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))
def read.at.valid source · line 158 · raw
@+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> Bool
def read.at.into.start source · line 164 · raw
@valid:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @+n:U32 -> @+width:U32 -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))
def read.at.into.with source · line 173 · raw
@file:File -> @+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @+start:U32 -> IO(Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))
def read.le.at.into source · line 180 · raw
@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))
Both handles return on error; complete elements read before an IO error stay written.
def read.bf16.at.into source · line 183 · raw
@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> @array:0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))
def read.at.result source · line 186 · raw
@pair:Pair(File, Pair(0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)) -> Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>)
def read.at.start source · line 194 · raw
@valid:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @+n:U32 -> @width:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
def read.at.with source · line 203 · raw
@file:File -> @+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
def read.le.at source · line 207 · raw
@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
Exactly n elements at hi * 2^32 + lo bytes; the file position does not move.
def read.bf16.at source · line 211 · raw
@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))
Little-endian BF16 bits become the top 16 bits of each F32, without arithmetic.
Templates
template read.fin source · line 62 · raw
@-f:(@_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&1, 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>) -> @got:Pair(File, Result<&1, &1, Pair(U32, String), 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>) -> Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>)
template read.with source · line 70 · raw
@-f:(@_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&1, 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>) -> @file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x67c3b862888f326f31733da2a0aafb4d/f32array.F32Array>))