def new_result_length
bendtorch-core@0.1.0.0 · src/tensor/allocation_PROOF.bend:75
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/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/storage/arith.bend as Arith
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
75def new_result_length(+shape: Shape.Shape, result: Result<&2, &1, Storage.Error, Storage.Storage>,
76 exact: {Allocation.storage_length(result) == Some{Shape.elements(shape)} : Maybe<&2, Nat>}) ->
77 {Allocation.tensor_length(shape, Core.new_result(shape, result)) == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>}:
78 match result:
79 case Fail{error}:
80 Empty.absurd({None{} == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>},
81 Arith.clash(Equal.cong(Maybe<&2, Nat>, Bool, value => Maybe.is_some(&2, Nat, value), None{}, Some{Shape.elements(shape)}, exact)))
82 case Done{storage}:
83 attach_length(shape, storage,
84 Equal.cong(Maybe<&2, Nat>, Nat, value => Maybe.default(&2, Nat, value, 0n), Some{Lifecycle.logical_length(storage)}, Some{Shape.elements(shape)}, exact))