~/bend-docscommunity

io.bend relies on unsafe/foreign

raw source on the hub · import bend-kit-f32array@0.2.5.0/io.bend as Io

Native byte conversions and file reads, kept outside the pure proof imports.

4 imports
import Base
import ./f32array.bend as A
import bend-kit-bytes@0.3.3.3/bytes.bend as Bytes
import bend-kit-files@0.4.0.3/files.bend as Files

Types

type Read source · line 50 · raw

Type

A file read in progress: more bytes to read, or the final result.

type Tensor source · line 128 · raw

Type

type AtRead source · line 152 · raw

Type

Definitions

def from_bytes.if source · line 15 · raw

@ok:Bool -> @+len:U32 -> @buf:Array<U32> -> @+big:U32 -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)

def from_bytes.with source · line 25 · raw

@b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @+big:U32 -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)

def from_bytes.le source · line 30 · raw

@b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)

Native little-endian conversions transfer the packed buffer when its size fits.

def from_bytes.be source · line 33 · raw

@b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)

def to_bytes.with source · line 36 · raw

@a:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @+big:U32 -> IO(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes)

def to_bytes.le source · line 43 · raw

@a:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> IO(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes)

len must be below 2^30, as for the pure encoder.

def to_bytes.be source · line 46 · raw

@a:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> IO(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes)

def read.next source · line 54 · raw

@more:Bool -> @file:File -> @acc:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @+left:U32 -> Read

def read.step source · line 62 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes>) -> @acc:0x3f4d48cfd4df31741ee4b528a4e7773e/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 72 · raw

@n:Nat -> @st:Read -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes>))

Each pass reads at least one byte or stops, so left + 1 passes are enough.

def read.sized source · line 89 · raw

@sz:Pair(File, Result<&1, &1, Pair(U32, String), U32>) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes>))

def read.decode source · line 97 · raw

@m:Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array> -> Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>

def read.le source · line 121 · raw

@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/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 125 · raw

@file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/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 131 · raw

@full:Bool -> @array:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @+bits:U32 -> @+used:U32 -> @+index:U32 -> @+width:U32 -> Tensor

def tensor.take source · line 138 · raw

@state:Tensor -> @+width:U32 -> @byte:U32 -> Tensor

def tensor.bytes source · line 144 · raw

@n:Nat -> @pair:Pair(Array<U32>, U32) -> @+at:U32 -> @state:Tensor -> @+width:U32 -> Tensor

def read.at.stop source · line 156 · raw

@file:File -> @state:Tensor -> @result:Result<&1, &1, Pair(U32, String), Unit> -> AtRead

def read.at.next source · line 160 · raw

@done:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @left:U32 -> @state:Tensor -> AtRead

def read.at.bytes source · line 167 · 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 177 · 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 185 · raw

@n:Nat -> @state:AtRead -> @+width:U32 -> IO(Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))

def read.at.valid source · line 202 · raw

@+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> Bool

def read.at.into.start source · line 208 · raw

@valid:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @+n:U32 -> @+width:U32 -> @array:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))

def read.at.into.with source · line 217 · raw

@file:File -> @+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> @array:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @+start:U32 -> IO(Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))

def read.le.at.into source · line 224 · raw

@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> @array:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/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 227 · raw

@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> @array:0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array -> @start:U32 -> IO(Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)))

def read.at.result source · line 230 · raw

@pair:Pair(File, Pair(0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array, Result<&1, &1, Pair(U32, String), Unit>)) -> Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)

def read.at.start source · line 238 · raw

@valid:Bool -> @file:File -> @hi:U32 -> @lo:U32 -> @+n:U32 -> @width:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

def read.at.with source · line 247 · raw

@file:File -> @+hi:U32 -> @+lo:U32 -> @+n:U32 -> @+width:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

def read.le.at source · line 251 · raw

@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

Exactly n elements at hi * 2^32 + lo bytes; the file position does not move.

def read.bf16.at source · line 255 · raw

@file:File -> @hi:U32 -> @lo:U32 -> @n:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

Little-endian BF16 bits become the top 16 bits of each F32, without arithmetic.

Templates

template read.fin source · line 104 · raw

@-f:(@_:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)) -> @got:Pair(File, Result<&1, &1, Pair(U32, String), 0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes>) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

template read.with source · line 114 · raw

@-f:(@_:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> IO(Maybe<&1, 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>)) -> @file:File -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.F32Array>))

Effects (foreign code)

effect from_bytes.raw source · line 7 · raw

@+n:U32 -> @a:Array<U32> -> @+big:U32 -> IO(Array<0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.Cell>)

foreign: effs/convert.c, effs/convert.js

effect to_bytes.raw source · line 11 · raw

@+n:U32 -> @a:Array<0xd71fe1e23d9ecc4809f1df933130c2a1/f32array.Cell> -> @+big:U32 -> IO(Array<U32>)

foreign: effs/convert.c, effs/convert.js