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:

How to fix it

The repair at a glance

src/demo.unadiff
  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.unauna
ita demo
  version 0.1.0
  edition 0.5
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub zeros(shape: List[Int]) -> Tensor[F64] = tensor_filled(shape: shape, value: 0.0)

Fixed example

ita.unauna
ita demo
  version 0.1.0
  edition 0.5
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub zeros(n: Int) -> Tensor[F64]
  requires n >= 0
=
  tensor_filled(shape: [n, n], value: 0.0)