def fill_lift

bendtorch-core@0.1.0.0 · src/tensor/from_values_contract.bend:270

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/storage/LAWS.bend as StorageLaws
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

270def fill_lift(+values: List<&2, F32>, +shape: Shape.Shape, +cursor: Nat, +prefix: List<&2, StorageLaws.Op>,
271  room: {Nat.is_le(Nat.add(cursor, List.length(&2, F32, values)), U32.to_nat(Shape.count(shape))) == True{} : Bool},
272  -P: Result<&2, &1, Core.Error, Core.Tensor<shape>> -> Type, h: Filled(shape, values, cursor, prefix, P)) ->
273  @-valid: {Lifecycle.logical_length(base(shape, prefix)) == Shape.logical_numel(Shape.dimensions(shape)) : Nat} ->
274    P(Core.fill_values(values, shape, Core.TTensor{base(shape, prefix), valid}, cursor)):
275  match values:
276    case Nil{}:
277      h
278    case +value <> +rest:
279      +room = room
280      valid => decided_step(shape, value, rest, cursor, prefix, U32.from_nat(cursor),
281        Shape.bool_case(Nat.is_eq(U32.to_nat(U32.from_nat(cursor)), cursor)),
282        cursor_exact(cursor, List.length(&2, F32, rest), Shape.count(shape), room),
283        cursor_inside(cursor, List.length(&2, F32, rest), Shape.count(shape), room), valid, P,
284        fill_lift(rest, shape, 1n+cursor, List.append(&2, StorageLaws.Op, prefix, [StorageLaws.Write{U32.from_nat(cursor), value}]),
285          room_next(cursor, List.length(&2, F32, rest), U32.to_nat(Shape.count(shape)), room), P,
286          filled_next(shape, value, rest, cursor, prefix, P, h)))

Uses (29)

Used by (1)