Skip to content
Konjure / spatial intelligence

Tensor

← Builtin reference

An immutable packed Tensor[T] with shared storage and checked shape/stride views.

Signature

A tensor stores one numeric dtype and a runtime shape. Comma-separated indices select scalar elements; slices preserve tensors and share their allocation. Arithmetic broadcasts trailing dimensions; @ multiplies matrices and batches. Arithmetic and indexing return Res; get returns Opt for a scalar lookup. Dtypes must match, with contextual typing reserved for literal operands.

Methods

len

len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

get

get(List[f64]) -> Opt[T]

Returns Some(value) for a valid index and None otherwise.

shape

shape() -> List[f64]

Returns one nonnegative extent for each tensor axis.

reshape

reshape(List[f64]) -> Res[Tensor[T], DataError]

Returns a reshaped tensor or DataError when dimensions do not fit.

transpose

transpose() -> Res[Tensor[T], DataError]
transpose(List[f64]) -> Res[Tensor[T], DataError]

Returns a reordered tensor or DataError for an invalid axis permutation.

sum

sum() -> Res[T, DataError]

Returns the tensor sum or DataError when the operation cannot be represented.

matmul

matmul(Tensor[T]) -> Res[Tensor[T], DataError]

Returns a matrix product or DataError when tensor shapes are incompatible.

convert

convert[U]() -> Res[Tensor[U], DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Slice a matrix

A slice is an immutable view; indexing with one integer per axis returns a typed scalar.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
[2, 2]
Some(5)

Rust definition

Value::Tensor(konjure_sdk::data::Tensor); a numeric dtype, shape, strides and shared packed storage.

See also