Skip to content

Tensors and interchange: API index

Find an operation by its purpose. Entries link to the complete signature and contract.

HMath.Interchange

API Purpose
array Construct a bounded view.
Array Opaque validated bytes and descriptive UTF-8 metadata (key/value strings).
Endian Explicit byte order.
LittleEndian Declaration and type contract below.
BigEndian Declaration and type contract below.
DType Numeric wire types; no platform-dependent Int, object or record dtype.
Bool8 Declaration and type contract below.
I8 Declaration and type contract below.
U8 Declaration and type contract below.
I16 Declaration and type contract below.
U16 Declaration and type contract below.
I32 Declaration and type contract below.
U32 Declaration and type contract below.
I64 Declaration and type contract below.
U64 Declaration and type contract below.
F32 Declaration and type contract below.
F64 Declaration and type contract below.
C64 Declaration and type contract below.
C128 Declaration and type contract below.
Limits Caller-configurable finite resource budgets, checked before allocations.
Limits Declaration and type contract below.
maxBytes Maximum aggregate encodedinputbacking bytes, including relevant format overhead.
maxElements Maximum logical scalar element count.
maxRank Maximum array dimension count (implementation cap 255).
maxMetadata Maximum descriptive metadata/header byte budget.
maxArchiveEntries Maximum archive member count; aggregate uncompressed bytes are also bounded.
defaultLimits 128 MiB of bytes, 8 million samples, rank 16, 64 KiB metadata, 256 members.
Order Physical order of a packed output; logical values are always row major.
COrder Declaration and type contract below.
FOrder Declaration and type contract below.
InterchangeError Decoders never throw on malformed bytes; IO failures have their own case.
InvalidData Declaration and type contract below.
Unsupported Declaration and type contract below.
LimitExceeded Declaration and type contract below.
InterchangeIOError Declaration and type contract below.
Element Fixed-width element encoding.
elementType Given a Haskell Element type proxy, return its exact fixed-width wire DType.
putElement Given a Haskell Element type proxy, return its exact fixed-width wire DType.
getElement Given a Haskell Element type proxy, return its exact fixed-width wire DType.
contiguousArray Given limits,dtype,endian,physical order,shape,then exact packed bytes, construct a canonical byte-strided array.
validateShape Given limits then dimensions, validate rank, nonnegative axes and element product, returning Int element count.
arrayDType Return the fixed-width wire dtype of an Array; this is independent of Haskell host Int/Double defaults.
arrayEndian Return explicit payload byte order; single-byte dtypes are endian-independent.
arrayShape Return logical dimensions in axis order; [] is scalar and zero axes are valid.
arrayStrides Return signed byte strides for each axis.
arrayOffset Return byte offset of logical origin within arrayBytes backing storage.
arrayBytes Return immutable backing bytes, which may include padding or data not reached by the logical strided view.
arrayMetadata Return descriptive UTF-8-compatible key/value metadata strings in stored order; metadata is not executable.
withMetadata Metadata is UTF-8 in binary files; keys must be unique and nonempty.
elementBytes Return fixed byte width of a DType, including complex pairs (C64=8,C128=16) and Bool8=1.
elementCount Return logical shape product; scalar arrays have one element and empty axes have zero.
denseStrides Dense strides use Integer arithmetic before conversion.
fromValues Given limits,endian,shape,then typed Element list, encode to a contiguous array with that Element dtype.
toValues Decode logical row-major values as the requested Element type, requiring an exact dtype match.
fromTensor Given limits,endian,then typed Haskell Tensor, encode logical row-major values and preserve shape.
toTensor Decode an Array of matching Element dtype to a contiguous Haskell Tensor, preserving logical shape/order.
fromMatrix Given limits,endian,then typed Matrix, encode its row-major values as a rank-two Array.
toMatrix Decode a matching typed rank-two Array to Matrix.
repack Pack arbitrary views, preserving dtype and exact component bits.
rawEncode Given limits,destination endian,physical order,then Array, repack its logical payload and return raw bytes without shapeheader metadata.
rawDecode Given limits,dtype,endian,order,shape,then bytes, construct a packed Array.
encodeBinary Given limits then Array, encode HMath wire-format v1 including shapestridesoffsetmetadatabacking storage and CRC-32.
decodeBinary Given limits then bytes, validate HMath v1 magicheaderflags/CRC and exact framing, returning an Array.
crc32 Standard CRC-32, compatible with ZIP and zlib, with a fixed 256-entry table.

HMath.Interchange.Array

API Purpose
Array Opaque validated bytes and descriptive UTF-8 metadata (key/value strings).
DType Numeric wire types; no platform-dependent Int, object or record dtype.
Bool8 Declaration and type contract below.
I8 Declaration and type contract below.
U8 Declaration and type contract below.
I16 Declaration and type contract below.
U16 Declaration and type contract below.
I32 Declaration and type contract below.
U32 Declaration and type contract below.
I64 Declaration and type contract below.
U64 Declaration and type contract below.
F32 Declaration and type contract below.
F64 Declaration and type contract below.
C64 Declaration and type contract below.
C128 Declaration and type contract below.
Endian Explicit byte order.
LittleEndian Declaration and type contract below.
BigEndian Declaration and type contract below.
Order Physical order of a packed output; logical values are always row major.
COrder Declaration and type contract below.
FOrder Declaration and type contract below.
Limits Caller-configurable finite resource budgets, checked before allocations.
Limits Declaration and type contract below.
maxBytes Maximum aggregate encodedinputbacking bytes, including relevant format overhead.
maxElements Maximum logical scalar element count.
maxRank Maximum array dimension count (implementation cap 255).
maxMetadata Maximum descriptive metadata/header byte budget.
maxArchiveEntries Maximum archive member count; aggregate uncompressed bytes are also bounded.
defaultLimits 128 MiB of bytes, 8 million samples, rank 16, 64 KiB metadata, 256 members.
InterchangeError Decoders never throw on malformed bytes; IO failures have their own case.
InvalidData Declaration and type contract below.
Unsupported Declaration and type contract below.
LimitExceeded Declaration and type contract below.
InterchangeIOError Declaration and type contract below.
Element Fixed-width element encoding.
elementType Given a Haskell Element type proxy, return its exact fixed-width wire DType.
putElement Given a Haskell Element type proxy, return its exact fixed-width wire DType.
getElement Given a Haskell Element type proxy, return its exact fixed-width wire DType.
array Construct a bounded view.
contiguousArray Given limits,dtype,endian,physical order,shape,then exact packed bytes, construct a canonical byte-strided array.
validateShape Given limits then dimensions, validate rank, nonnegative axes and element product, returning Int element count.
arrayDType Return the fixed-width wire dtype of an Array; this is independent of Haskell host Int/Double defaults.
arrayEndian Return explicit payload byte order; single-byte dtypes are endian-independent.
arrayShape Return logical dimensions in axis order; [] is scalar and zero axes are valid.
arrayStrides Return signed byte strides for each axis.
arrayOffset Return byte offset of logical origin within arrayBytes backing storage.
arrayBytes Return immutable backing bytes, which may include padding or data not reached by the logical strided view.
arrayMetadata Return descriptive UTF-8-compatible key/value metadata strings in stored order; metadata is not executable.
withMetadata Metadata is UTF-8 in binary files; keys must be unique and nonempty.
elementBytes Return fixed byte width of a DType, including complex pairs (C64=8,C128=16) and Bool8=1.
elementCount Return logical shape product; scalar arrays have one element and empty axes have zero.
denseStrides Dense strides use Integer arithmetic before conversion.
fromValues Given limits,endian,shape,then typed Element list, encode to a contiguous array with that Element dtype.
toValues Decode logical row-major values as the requested Element type, requiring an exact dtype match.
fromTensor Given limits,endian,then typed Haskell Tensor, encode logical row-major values and preserve shape.
toTensor Decode an Array of matching Element dtype to a contiguous Haskell Tensor, preserving logical shape/order.
fromMatrix Given limits,endian,then typed Matrix, encode its row-major values as a rank-two Array.
toMatrix Decode a matching typed rank-two Array to Matrix.
repack Pack arbitrary views, preserving dtype and exact component bits.
rawEncode Given limits,destination endian,physical order,then Array, repack its logical payload and return raw bytes without shapeheader metadata.
rawDecode Given limits,dtype,endian,order,shape,then bytes, construct a packed Array.
byteOffsets Return backing byte offsets for each logical element in row-major coordinate order, honoring signed strides and offset.
guardI Given condition then InterchangeError, return Right () when True and Left that error otherwise.
checkLimits Validate nonnegative finite resource caps, rank<=255 and Int-safe byteelementmetadata/archive budgets.
boundedInt Given diagnostic name,nonnegative upper bound,then Integer value, convert only if value lies in [0,upper] and fits Int.

HMath.Interchange.Binary

API Purpose
encodeBinary Given limits then Array, encode HMath wire-format v1 including shapestridesoffsetmetadatabacking storage and CRC-32.
decodeBinary Given limits then bytes, validate HMath v1 magicheaderflags/CRC and exact framing, returning an Array.
crc32 Standard CRC-32, compatible with ZIP and zlib, with a fixed 256-entry table.
runDecoder Strict, exact decoder: trailing bytes are an error rather than ignored.

HMath.Interchange.Compression

API Purpose
Compression Wire wrappers around the same DEFLATE coding.
RawDeflate Declaration and type contract below.
Zlib Declaration and type contract below.
Gzip Declaration and type contract below.
compressionAvailable Probe whether the optional native zlib adapter is available, returning IO Bool.
compress Given limits,RawDeflateZlibGzip wrapper,then bytes, compress within a bounded output allocation.
decompress The output length may be smaller than the budget.

HMath.Interchange.IO

API Purpose
readArrayFile File reading checks the declared size before allocating, then caps the actual read too, handling concurrent growth.
writeArrayFile Writes to the supplied path after encoding succeeds.
RawSpec Raw physical storage: fixed dtypeendianorder and shape, no header.
RawSpec Declaration and type contract below.
readRawChunks Read physical-order chunks (one-dimensional arrays); the caller retains the original RawSpec for reconstructing dimensions.
writeRawChunks Write fixed-size raw chunks.
MappedArray Scope-bound mapping; no pointer or borrowed ByteString is exposed.
withMappedArray Given limits,RawSpec,path,then rank-2 callback, map read-only raw data for that callback's lifetime and unmap on exit.
mappedValue Read one typed scalar using checked multidimensional indexing.
mappedShape Return dimensions of a callback-scoped read-only mapped array.
mappedReadBytes Copy a bounded byte range.

HMath.Interchange.Numpy

API Purpose
encodeNpy Given limits,physical C/F order,then Array, repack and write a NumPy NPY v1 payload with explicit dtypeendianshape.
decodeNpy Given limits then NPY bytes, decode supported v1v2v3 fixed-width scalar dtype arrays.
encodeNpz Deterministic archives, DOS epoch timestamps and no ZIP comments.
decodeNpz Checks directory/local consistency, CRC, exact deflate length, duplicate names, overlapping member ranges and aggregate expanded bytes.

HMath.Interchange.Text

API Purpose
encodeText Given limits then Array, encode self-describing HMath text with dtype/shape and scalar tokens.
decodeText Given limits then HMath text bytes, parse dtypeshapetokens and return a checked Array.
encodeDelimited Given limits,comma or tab separator,then rank-two noncomplex Array, encode CSV/TSV numeric cells.
decodeDelimited Given limits,commatab separator,target DType,then CSVTSV bytes, parse rectangular real numeric cells to a rank-two Array.
encodeMatrixMarket Dense general Matrix Market; exact Int64, Float64, or Complex128.
decodeMatrixMarket Array and coordinate input, realintegercomplex/pattern fields and generalsymmetricskew-symmetric/Hermitian storage.

HMath.Tensor

API Purpose
Tensor Immutable boxed CPU tensor with signed element strides and shared view storage.
Layout Tensor storage classification: canonical row major,column major,or general strided view.
RowMajor Declaration and type contract below.
ColumnMajor Declaration and type contract below.
Strided Declaration and type contract below.
Device Tensor execution/storage device; this release supports CPU.
CPU Declaration and type contract below.
tensor Given shape then flat row-major values, construct an immutable CPU tensor.
tensorColumnMajor Given shape then values in column-major storage order, construct a column-major CPU tensor.
tensorValues Return logical values in row-major coordinate order, honoring strides/offsets rather than exposing raw backing storage.
tensorShape Return dimensions in axis order.
tensorStrides Return signed element strides for each axis.
tensorOffset Return backing-array offset in elements of the logical coordinate origin.
tensorDType Return the Typeable element type name as a String.
tensorDevice Return CPU, the supported device for this Haskell tensor implementation.
tensorLayout Classify canonical row-major strides first, then column-major, otherwise Strided.
isContiguous Test whether stored strides exactly match canonical row-major strides for this shape.
contiguous Copy logical values into a new canonical row-major tensor of the same shape.
numel Return logical element count (product of shape), including one for scalars and zero for any empty axis.
shapeSize Validate nonnegative dimensions and return their product as Int.
inferBroadcast Given two shapes, align trailing dimensions; equal sizes or a size-one dimension are compatible.
tensorZeros Construct a row-major tensor of zeros with the supplied shape.
tensorOnes Construct a row-major tensor of ones with the supplied shape.
tensorFull Given shape then fill value, construct an immutable row-major tensor with every element equal to that value.
tensorArange Given finite start, exclusive stop, and nonzero finite step, construct a rank-one arithmetic progression.
tensorLinspace Given start, stop, then nonnegative count, return a rank-one evenly spaced sequence including both endpoints when count>=2.
tensorLogspace Given base, starting exponent, ending exponent, then count, return base raised to tensorLinspace exponents.
tensorRandom Explicit deterministic LCG seed.
indexTensor Given tensor then complete zero-based coordinate list, return the element.
sliceTensor Given axis,start,count,nonzero step,then tensor, return a zero-copy strided view.
fancyIndex Given axis then index list then tensor, copy selected positions along that axis in index-list order, retaining duplicates.
booleanIndex Given an identically shaped Bool mask then tensor, return a rank-one tensor of values whose mask is True, in logical row-major order.
gather Alias of fancyIndex: given axis, zero-based index list, then tensor, copy those axis positions.
scatter Given axis,index list,update tensor,then target, return a new target-shaped tensor with updates written to selected positions.
scatterAdd Given axis,indices,updates,target, return a new target with updates added at selected coordinates.
reshapeTensor Given new dimensions then tensor, preserve logical element order with unchanged count.
flattenTensor Reshape to rank one with numel entries in logical row-major order.
squeeze Remove every length-one axis as a shared view, preserving storage and logical values.
unsqueeze Given insertion axis in [0,rank] then tensor, insert a length-one dimension as a shared view.
expand Alias of broadcastTo: expand singleton dimensions to a requested compatible target shape without copying values.
permute Given a permutation of all zero-based axes then tensor, return a zero-copy view with shape/strides reordered.
transposeTensor Reverse every axis of a tensor as a shared view.
moveAxis Given source axis,destination axis,then tensor, move one axis while preserving the order of others.
swapAxes Given two existing axes then tensor, exchange their dimensions/strides in a shared view.
broadcastTo Given target shape then tensor, return a shared zero-stride view where existing/trailing size-one axes can expand.
repeatTensor Given axis,repetition count,then tensor, repeat each individual axis position consecutively.
tile Given one nonnegative repetition count per existing axis then tensor, tile whole axis contents into repeated blocks.
concatenate Given existing axis then nonempty tensor list, copy tensors end-to-end along that axis.
stack Given insertion axis then nonempty list of equally shaped tensors, insert that axis and concatenate along it.
splitTensor Given axis,nonnegative segment sizes,then tensor, return shared slices partitioning that axis exactly.
chunkTensor Given axis,positive chunk count,then tensor, split into exactly that many near-equal shared slices; earlier chunks get the remainder.
padTensor Given (before,after) nonnegative padding for every axis,fill value,then tensor, copy into a padded output.
roll Given axis,signed shift,then tensor, cyclically shift elements along the axis, preserving shape.
flipTensor Given axis then tensor, reverse that axis using a negative-stride shared slice.
rotate Given two distinct axes,integer quarter-turn count,then tensor, repeatedly swap axes and flip the first.
sortTensor Flatten logical values and return a rank-one tensor sorted ascending under Ord.
argsort Flatten logical values and return a rank-one tensor of stable zero-based ascending-sort indices.
topk Given k in [0,numel] then tensor, return rank-one (values,flat indices) for k largest values in descending order.
unique Return sorted distinct logical values as a rank-one tensor.
nonzero Return a count-by-rank tensor of zero-based coordinates of nonzero elements in row-major traversal order.
whereTensor Given Bool mask,yes tensor,no tensor, broadcast all three shapes and select yes/no values elementwise.
maskedFill Given broadcastable mask,fill value,then tensor, return a copied result with True positions replaced.
maskedSelect Given mask then identically shaped tensor, return a rank-one copy of True-selected values in row-major order.
mapTensor Apply scalar arithmetic, comparisons, logic, or elementary functions such as sin, exp, and log to each logical element.
zipTensor Given binary element function then two tensors, broadcast compatible shapes and return a new contiguous result.
tensorAdd Given two tensors, broadcast compatible shapes and add corresponding values, returning a new contiguous tensor.
tensorSubtract Given two tensors, broadcast compatible shapes and subtract right values from left, returning a new contiguous tensor.
tensorMultiply Given two tensors, broadcast compatible shapes and multiply corresponding values, returning a new contiguous tensor.
tensorDivide Given two tensors, broadcast compatible shapes and divide left values by right, returning a new contiguous tensor.
tensorEqual Given two tensors, broadcast compatible shapes and compare corresponding values for equality, returning a new contiguous tensor.
tensorLess Given two tensors, broadcast compatible shapes and compare corresponding values with (<), returning a new contiguous tensor.
tensorAnd Given two tensors, broadcast compatible shapes and combine Bool values with logical AND, returning a new contiguous tensor.
tensorOr Given two tensors, broadcast compatible shapes and combine Bool values with logical OR, returning a new contiguous tensor.
tensorNot Negate each Bool element, returning a new contiguous tensor of the same shape.
promoteTensor Explicitly convert each Real element through exact Rational to the destination Fractional type, preserving shape.
sumAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by sum.
meanAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by arithmetic mean.
productAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by product.
minAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by minimum.
maxAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by maximum.
argmin Return first zero-based flat row-major index of a minimum logical element.
argmax Return first zero-based flat row-major index of a maximum logical element.
varianceAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by population variance (dividing by group size).
normAxes Given unique zero-based axis list,keep-dimensions Bool,then tensor, reduce those axes by scaled Euclidean norm.
cumulativeSum Given existing axis then tensor, return inclusive running sums along that axis, preserving shape.
cumulativeProduct Given existing axis then tensor, return inclusive running products along that axis, preserving shape.
tensordot Given contraction axes for the first tensor,axes for the second,then both tensors, sum products over matched axis pairs.
einsum Explicit Einstein notation; each operand has one label per axis.
batchedMatmul Multiply tensors on their final two dimensions and broadcast leading batch dimensions.
tensorKronecker Return multidimensional Kronecker product, left-padding the lower-rank shape with ones and multiplying corresponding axis sizes.
serializeTensor Serialize (shape,logical row-major values) using Haskell Show.
deserializeTensor Read a complete Haskell (shape,values) encoding, permitting only trailing whitespace, and validate shapecount.
TensorGraph Lazy expression trees defer computation.
inputGraph Wrap an immutable tensor as a lazy TensorGraph leaf, retaining its backing storage without evaluating a new output array.
mapGraph Given element function then graph, compose a lazy element transform, preserving shape.
zipGraph Given binary function then two graphs, validate broadcast shapes and return a fused lazy graph.
evaluateGraph Evaluate a lazy graph into one contiguous row-major tensor.

HMath.Tensor.Mutable

API Purpose
MutableTensor Pinned CPU tensor with shared mutable views and garbage-collected ForeignPtr ownership.
newMutable Given checked dimensions then fill value, allocate pinned row-major storage filled with that value.
thawTensor Copy logical immutable tensor values to new contiguous pinned mutable storage.
freezeTensor Copy current logical view values into a new immutable tensor in row-major order.
mutableShape Return current mutable-view dimensions in axis order.
readMutable Given a mutable view then full zero-based coordinate list, read one element through the view strides.
writeMutable Given a mutable view, full coordinate list, then value, update that storage element.
modifyMutable Given view, coordinates, then transformation, read and replace an element.
sliceMutable Given axis, start, count, nonzero step, then view, return a zero-copy mutable slice retaining shared ForeignPtr ownership.
transposeMutable Reverse the order of all shape axes and strides, returning a zero-copy mutable view.
withMutableBuffer The pointer is valid only during the callback.
mutableAlignment Given a type Proxy, return the Storable ABI alignment in bytes.