def attach_decided
bendtorch-core@0.1.0.0 · src/tensor/core.bend:57
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
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/tensor/lifecycle.bend as Lifecycle
57def attach_decided(+shape: Shape.Shape, storage: Storage.Storage, +n: Nat,
58 -exact: {Lifecycle.logical_length(storage) == n : Nat},
59 decision: Shape.BoolCase<Nat.is_eq(n, Shape.elements(shape))>) ->
60 Result<&2, &1, Error, Tensor<shape>>:
61 match decision:
62 case Shape.BFalse{equal}:
63 Fail{StorageLengthMismatch{}}
64 case Shape.BTrue{equal}:
65 Done{TTensor{storage, Equal.trans(Nat, Lifecycle.logical_length(storage), n,
66 Shape.logical_numel(Shape.dimensions(shape)), exact,
67 Equal.trans(Nat, n, Shape.elements(shape), Shape.logical_numel(Shape.dimensions(shape)),
68 Lifecycle.natural_equal(n, Shape.elements(shape), equal), Shape.elements_exact(shape)))}}