Home / Docs / Diagnostics
U2038: A tensor shape, index, permutation or axis out of place
Release v0.4.0
In edition 0.5 (preview), a tensor shape, index, permutation or axis is out of place.
Why Una rejects it
A Tensor[T] has a rank from 1 to 8 and a length along each axis (spec/29 §17, ADR 0120). The checker reads a tensor's shapes, indices, permutations and axes from the source, so that each call gets the contract of its rank and the verifier proves its shapes with linear facts. So each is written as a literal:
- the
shape:oftensorandtensor_filled, theat:ofget,atandset, and theshape:ofreshape, are list literals of 1 to 8 elements, whose elements may be anyIntexpressions:shape: [rows, 3]; - the
axes:ofpermuteis a list literal of integer literals that is a permutation of 0 to r - 1, where r is its length:axes: [1, 0]; - the
axis:ofdimandsum, and theaxis:andother:ofcontract, are integer literals from 0 to 7; tensorandtensor_filledare not function values, since a function value's shape would be a run-time list; a lambda that calls one with a list literal is.
How to fix it
- Write the literal.
- Or, for a computed shape, write a list literal of computed lengths:
tensor_filled(shape: [n, n], value: 0.0).
The repair at a glance
src/demo.una
module demo
- pub zeros(shape: List[Int]) -> Tensor[F64] = tensor_filled(shape: shape, value: 0.0)
+ pub zeros(n: Int) -> Tensor[F64]
+ requires n >= 0
+ =
+ tensor_filled(shape: [n, n], value: 0.0)Failing example
ita.una
ita demo
version 0.1.0
edition 0.5ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub zeros(shape: List[Int]) -> Tensor[F64] = tensor_filled(shape: shape, value: 0.0)Fixed example
ita.una
ita demo
version 0.1.0
edition 0.5ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub zeros(n: Int) -> Tensor[F64]
requires n >= 0
=
tensor_filled(shape: [n, n], value: 0.0)