def attach_decided_length
bendtorch-core@0.1.0.0 · src/tensor/allocation_PROOF.bend:56
import bendtorch-core@0.1.0.0/src/tensor/allocation_PROOF.bend as AllocationPROOF
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/shape/nat_proofs.bend as Nats
import bendtorch-core@0.1.0.0/src/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/lifecycle.bend as Lifecycle
import bendtorch-core@0.1.0.0/src/tensor/allocation_spec.bend as Allocation
56def attach_decided_length(+shape: Shape.Shape, +length: Nat, decision: Shape.BoolCase<Nat.is_eq(length, Shape.elements(shape))>,
57 storage: Storage.Storage, exact: {Lifecycle.logical_length(storage) == length : Nat}, accepted: {True{} == Nat.is_eq(length, Shape.elements(shape)) : Bool}) ->
58 {Allocation.tensor_length(shape, Core.attach_decided(shape, storage, length, exact, decision)) == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>}:
59 match decision:
60 case Shape.BFalse{equal}:
61 Empty.absurd({None{} == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>}, Nats.contradiction(Nat.is_eq(length, Shape.elements(shape)), accepted, equal))
62 case Shape.BTrue{equal}:
63 Equal.cong(Nat, Maybe<&2, Nat>, n => Some{n}, Lifecycle.logical_length(storage), Shape.logical_numel(Shape.dimensions(shape)),
64 Equal.trans(Nat, Lifecycle.logical_length(storage), length, Shape.logical_numel(Shape.dimensions(shape)), exact,
65 Equal.trans(Nat, length, Shape.elements(shape), Shape.logical_numel(Shape.dimensions(shape)), Lifecycle.natural_equal(length, Shape.elements(shape), equal), Shape.elements_exact(shape))))