def result_length

bendtorch-core@0.1.0.0 · src/tensor/construction_contract_PROOF.bend:277

import bendtorch-core@0.1.0.0/src/tensor/construction_contract_PROOF.bend as ConstructionContractPROOF
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/LAWS.bend as StorageLaws
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
import bendtorch-core@0.1.0.0/src/tensor/observation.bend as Observation

277def result_length(+shape: Shape.Shape, +index: U32, result: Result<&2, &1, Storage.Error, Storage.Storage>,
278  counted: {Allocation.storage_length(result) == Some{Shape.elements(shape)} : Maybe<&2, Nat>},
279  kept: {Lifecycle.retained_read(Storage.get(StorageLaws.created.of(result), index)) == Shape.logical_numel(Shape.dimensions(shape)) : Nat}) ->
280  {Observation.after_length(shape, index, Core.new_result(shape, result)) == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>}:
281  match result:
282    case Fail{error}:
283      Empty.absurd({None{} == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>}, Arith.clash(Equal.cong(Maybe<&2, Nat>, Bool,
284        value => Maybe.is_some(&2, Nat, value), None{}, Some{Shape.elements(shape)}, counted)))
285    case Done{storage}:
286      attach_length(shape, index, storage,
287        Equal.cong(Maybe<&2, Nat>, Nat, value => Maybe.default(&2, Nat, value, 0n),
288          Some{Lifecycle.logical_length(storage)}, Some{Shape.elements(shape)}, counted), kept)

Uses (24)

Used by (1)