array_api #
vtl.array_api
vtl.array_api is the explicit namespace for VTL's incrementally implemented Python Array API surface. It currently exposes creation, reshape, broadcasting, and transpose operations plus broadcast-aware where selection, matmul, and scalar clip, global sum, prod, min, max, all, any_, and mean, with a small capability matrix so consumers can select the namespace without mistaking VTL-specific functions for standard operations.
The supported specification target is 2024.12. The matrix is intentionally conservative: an operation is listed only after its semantics have focused regression coverage. Unsupported operations are not re-exported from this namespace.
Numeric reductions (sum, prod, min, max, and mean) accept VTL's vtl.Real constraint, so unsupported element types are rejected at compile time.
import vtl
import vtl.array_api as xp
x := xp.arange[f32](0.0, 6.0, 1.0)!
x = xp.reshape(x, [2, 3])!
assert xp.supports('reshape')
expanded := xp.broadcast_to(x, [4, 2, 3])!
transposed := xp.transpose(expanded, 0, 2, 1)!
condition := vtl.from_2d[bool]([[true], [false]])!
positive := xp.ones[f32]([2, 3])
negative := xp.zeros[f32]([2, 3])
selected := xp.where(condition, positive, negative)!
weights := xp.ones[f32]([3, 2])
scores := xp.matmul(weights, weights.t()!)!
bounded := xp.clip(scores, 0.0, 1.0)!
total := xp.sum(bounded)
average := xp.mean(bounded)
close_mask := xp.isclose(bounded, bounded, 1e-5, 1e-8, false)!
finite_mask := xp.isfinite(bounded)
This is not yet a complete conformance implementation. Consumers should check xp.capability_matrix() before selecting operations dynamically.
Constants #
const standard_version = '2024.12'
standard_version identifies the Array API specification targeted by this namespace. It is intentionally separate from VTL's package version.
fn all #
fn all[T](array &vtl.Tensor[T]) bool
all reports whether every element is truthy.
fn allclose #
fn allclose[T](a &vtl.Tensor[T], b &vtl.Tensor[T], rtol f64, atol f64, equal_nan bool) !bool
allclose reports whether all broadcasted values satisfy the tolerances.
fn any_ #
fn any_[T](array &vtl.Tensor[T]) bool
any_ reports whether at least one element is truthy. The suffix is required because any is a reserved V type name.
fn arange #
fn arange[T](start f64, stop f64, step f64) !&vtl.Tensor[T]
arange creates values in the half-open interval [start, stop).
fn broadcast_to #
fn broadcast_to[T](array &vtl.Tensor[T], shape []int) !&vtl.Tensor[T]
broadcast_to expands an array to a compatible shape.
fn capability_matrix #
fn capability_matrix() []Capability
capability_matrix returns the current, deliberately small conformance surface. Consumers can use this instead of guessing from VTL's broader API.
fn clip #
fn clip[T](array &vtl.Tensor[T], min_value T, max_value T) !&vtl.Tensor[T]
clip limits every array value to the inclusive scalar interval.
fn empty #
fn empty[T](shape []int) &vtl.Tensor[T]
empty creates an array with the requested shape and element type.
fn full #
fn full[T](shape []int, value T) &vtl.Tensor[T]
full creates an array filled with value.
fn isclose #
fn isclose[T](a &vtl.Tensor[T], b &vtl.Tensor[T], rtol f64, atol f64, equal_nan bool) !&vtl.Tensor[bool]
isclose compares broadcasted values using relative and absolute tolerances.
fn isfinite #
fn isfinite[T](array &vtl.Tensor[T]) &vtl.Tensor[bool]
isfinite returns true for values that are neither infinite nor NaN.
fn isinf #
fn isinf[T](array &vtl.Tensor[T]) &vtl.Tensor[bool]
isinf returns true for positive or negative infinite values.
fn isnan #
fn isnan[T](array &vtl.Tensor[T]) &vtl.Tensor[bool]
isnan returns true for NaN values.
fn matmul #
fn matmul[T](a &vtl.Tensor[T], b &vtl.Tensor[T]) !&vtl.Tensor[T]
matmul computes matrix multiplication with Array API vector and batch rules.
fn max #
fn max[T vtl.Real](array &vtl.Tensor[T]) T
max reduces all elements to their maximum in the input dtype.
fn mean #
fn mean[T vtl.Real](array &vtl.Tensor[T]) f64
mean reduces real numeric elements to an f64 scalar.
fn median #
fn median[T](array &vtl.Tensor[T]) f64
median computes the median of all elements.
fn median_axis #
fn median_axis[T](array &vtl.Tensor[T], axis int, keepdims bool) !&vtl.Tensor[f64]
median_axis reduces median along one axis.
fn min #
fn min[T vtl.Real](array &vtl.Tensor[T]) T
min reduces all elements to their minimum in the input dtype.
fn ones #
fn ones[T](shape []int) &vtl.Tensor[T]
ones creates an array filled with one.
fn prod #
fn prod[T vtl.Real](array &vtl.Tensor[T]) T
prod reduces all elements to a product in the input dtype.
fn quantile #
fn quantile[T](array &vtl.Tensor[T], q f64) !f64
quantile computes a linear-interpolated quantile of all elements.
fn quantile_axis #
fn quantile_axis[T](array &vtl.Tensor[T], q f64, axis int, keepdims bool) !&vtl.Tensor[f64]
quantile_axis reduces a linear-interpolated quantile along one axis.
fn reshape #
fn reshape[T](array &vtl.Tensor[T], shape []int) !&vtl.Tensor[T]
reshape returns an array with the requested shape, preserving its values.
fn std #
fn std[T vtl.Real](array &vtl.Tensor[T], ddof int) !f64
std computes the population standard deviation of all elements.
fn std_axis #
fn std_axis[T vtl.Real](array &vtl.Tensor[T], axis int, ddof int, keepdims bool) !&vtl.Tensor[f64]
std_axis reduces standard deviation along one axis.
fn sum #
fn sum[T vtl.Real](array &vtl.Tensor[T]) T
sum reduces all elements to a scalar in the input dtype.
fn supports #
fn supports(operation string) bool
supports reports whether an operation is implemented in this namespace.
fn transpose #
fn transpose[T](array &vtl.Tensor[T], axes ...int) !&vtl.Tensor[T]
transpose permutes axes, reversing them when no explicit order is supplied.
fn var #
fn var[T vtl.Real](array &vtl.Tensor[T], ddof int) !f64
var computes the variance of all elements.
fn var_axis #
fn var_axis[T vtl.Real](array &vtl.Tensor[T], axis int, ddof int, keepdims bool) !&vtl.Tensor[f64]
var_axis reduces variance along one axis.
fn where #
fn where[T](condition &vtl.Tensor[bool], x &vtl.Tensor[T], y &vtl.Tensor[T]) !&vtl.Tensor[T]
where selects values from x or y according to a broadcastable condition.
fn zeros #
fn zeros[T](shape []int) &vtl.Tensor[T]
zeros creates an array filled with zero.
struct Capability #
struct Capability {
pub:
operation string
supported bool
}
Capability describes one operation exposed by this namespace.
- README
- Constants
- fn all
- fn allclose
- fn any_
- fn arange
- fn broadcast_to
- fn capability_matrix
- fn clip
- fn empty
- fn full
- fn isclose
- fn isfinite
- fn isinf
- fn isnan
- fn matmul
- fn max
- fn mean
- fn median
- fn median_axis
- fn min
- fn ones
- fn prod
- fn quantile
- fn quantile_axis
- fn reshape
- fn std
- fn std_axis
- fn sum
- fn supports
- fn transpose
- fn var
- fn var_axis
- fn where
- fn zeros
- struct Capability