---
title: "U2038: A tensor shape, index, permutation or axis out of place"
url: https://una-lang.org/en/docs/errors/U2038/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U2038.md
---

# U2038: A tensor shape, index, permutation or axis out of place

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:` of `tensor` and `tensor_filled`, the `at:` of `get`, `at` and `set`, and the `shape:` of `reshape`, are list literals of 1 to 8 elements, whose elements may be any `Int` expressions: `shape: [rows, 3]`;
- the `axes:` of `permute` is 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:` of `dim` and `sum`, and the `axis:` and `other:` of `contract`, are integer literals from 0 to 7;
- `tensor` and `tensor_filled` are 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`

```diff
  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`

```una
ita demo
  version 0.1.0
  edition 0.5
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

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

## Fixed example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.5
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

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