def attach_lift
bendtorch-core@0.1.0.0 · src/tensor/read_contract.bend:62
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/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
62def attach_lift(+shape: Shape.Shape, storage: Storage.Storage, counted: {Lifecycle.logical_length(storage) == Shape.elements(shape) : Nat},
63 -P: Result<&2, &1, Core.Error, Core.Tensor<shape>> -> Type,
64 h: @-valid: {Lifecycle.logical_length(storage) == Shape.logical_numel(Shape.dimensions(shape)) : Nat} -> P(Done{Core.TTensor{storage, valid}})) ->
65 P(Core.attach(shape, storage)):
66 match storage:
67 case Storage.Empty{}:
68 attached(shape, Storage.Empty{}, 0n, {==}, Shape.bool_case(Nat.is_eq(0n, Shape.elements(shape))), counted, P, h)
69 case Storage.Owned{+depth, +length, array, balanced, valid}:
70 attached(shape, Storage.Owned{depth, length, array, balanced, valid}, length, {==},
71 Shape.bool_case(Nat.is_eq(length, Shape.elements(shape))), counted, P, h)