def counted_lift
bendtorch-core@0.1.0.0 · src/tensor/from_values_contract.bend:297
import bendtorch-core@0.1.0.0/src/tensor/from_values_contract.bend as FromValuesContract
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/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/allocation_PROOF.bend as AllocationProof
import bendtorch-core@0.1.0.0/src/tensor/read_contract.bend as Reads
297def counted_lift(+shape: Shape.Shape, +values: List<&2, F32>,
298 decision: Shape.BoolCase<Nat.is_eq(List.length(&2, F32, values), Shape.elements(shape))>,
299 +counted: {List.length(&2, F32, values) == Shape.logical_numel(Shape.dimensions(shape)) : Nat},
300 -P: Result<&2, &1, Core.Error, Core.Tensor<shape>> -> Type, h: Filled(shape, values, 0n, Nil{}, P)) ->
301 P(Core.from_values_counted(shape, values, decision)):
302 match decision:
303 case Shape.BFalse{equal}:
304 Empty.absurd(P(Fail{Core.ValueCountMismatch{}}),
305 Nats.contradiction(Nat.is_eq(List.length(&2, F32, values), Shape.elements(shape)),
306 AllocationProof.natural_equal_true(List.length(&2, F32, values), Shape.elements(shape),
307 Equal.trans(Nat, List.length(&2, F32, values), Shape.logical_numel(Shape.dimensions(shape)), Shape.elements(shape), counted,
308 Equal.sym(Nat, Shape.elements(shape), Shape.logical_numel(Shape.dimensions(shape)), Shape.elements_exact(shape)))),
309 equal))
310 case Shape.BTrue{equal}:
311 Reads.new_lift(shape, 0.0, result => P(Core.from_values_new(shape, values, result)),
312 fill_lift(values, shape, 0n, Nil{}, start_room(shape, values, counted), P, h))