def attached

bendtorch-core@0.1.0.0 · src/tensor/read_contract.bend:49

import bendtorch-core@0.1.0.0/src/tensor/read_contract.bend as ReadContract
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_PROOF.bend as AllocationProof

49def attached(+shape: Shape.Shape, -storage: Storage.Storage, +n: Nat, -exact: {Lifecycle.logical_length(storage) == n : Nat},
50  decision: Shape.BoolCase<Nat.is_eq(n, Shape.elements(shape))>, counted: {n == Shape.elements(shape) : Nat},
51  -P: Result<&2, &1, Core.Error, Core.Tensor<shape>> -> Type,
52  h: @-valid: {Lifecycle.logical_length(storage) == Shape.logical_numel(Shape.dimensions(shape)) : Nat} -> P(Done{Core.TTensor{storage, valid}})) ->
53  P(Core.attach_decided(shape, storage, n, exact, decision)):
54  match decision:
55    case Shape.BFalse{no}:
56      Empty.absurd(P(Core.attach_decided(shape, storage, n, exact, Shape.BFalse{no})),
57        Nats.contradiction(Nat.is_eq(n, Shape.elements(shape)), AllocationProof.natural_equal_true(n, Shape.elements(shape), counted), no))
58    case Shape.BTrue{yes}:
59      h(Equal.trans(Nat, Lifecycle.logical_length(storage), n, Shape.logical_numel(Shape.dimensions(shape)), exact,
60        Equal.trans(Nat, n, Shape.elements(shape), Shape.logical_numel(Shape.dimensions(shape)), Lifecycle.natural_equal(n, Shape.elements(shape), yes), Shape.elements_exact(shape))))

Uses (19)

Used by (1)