def position_digits

bendtorch-core@0.1.0.0 · src/tensor/matrix_index_proof.bend:115

import bendtorch-core@0.1.0.0/src/tensor/matrix_index_proof.bend as MatrixIndexProof
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/shape/coordinate_proofs.bend as Coordinates
import bendtorch-core@0.1.0.0/src/tensor/matmul.bend as Matrix

115def position_digits(+output: Shape.Shape, +rows: Nat, +columns: Nat,
116  extents: {Shape.extents(output) == [rows, columns] : List<&2, Nat>}, +position: Nat,
117  +fits: {True{} == Nat.is_lt(position, Shape.numel(Shape.extents(output))) : Bool}) ->
118  {Shape.indices(Shape.extents(output), Shape.unflatten(Shape.extents(output),
119    Coordinates.fin_from(Shape.numel(Shape.extents(output)), position, fits))) ==
120    [Matrix.row_of(columns, position), Matrix.column_of(columns, position)] : List<&2, Nat>}:
121  +bound = Shape.numel(Shape.extents(output))
122  +index = Coordinates.fin_from(bound, position, fits)
123  Equal.trans(List<&2, Nat>, Shape.indices(Shape.extents(output), Shape.unflatten(Shape.extents(output), index)),
124    Shape.digits(Shape.extents(output), Shape.Fin.value(bound, index)), [Matrix.row_of(columns, position), Matrix.column_of(columns, position)],
125    Coordinates.digits_unflatten(Shape.extents(output), index),
126    Equal.trans(List<&2, Nat>, Shape.digits(Shape.extents(output), Shape.Fin.value(bound, index)),
127      Shape.digits(Shape.extents(output), position), [Matrix.row_of(columns, position), Matrix.column_of(columns, position)],
128      Equal.cong(Nat, List<&2, Nat>, value => Shape.digits(Shape.extents(output), value), Shape.Fin.value(bound, index), position,
129        Coordinates.fin_from_value(bound, position, fits)),
130      Equal.cong(List<&2, Nat>, List<&2, Nat>, dims => Shape.digits(dims, position), Shape.extents(output), [rows, columns], extents)))

Uses (18)

Used by (2)