def shift

bendtorch-core@0.1.0.0 · src/tensor/contracts/pointwise_proof.bend:289

import bendtorch-core@0.1.0.0/src/tensor/contracts/pointwise_proof.bend as PointwiseProof
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/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/contracts/replayed.bend as Replayed
import bendtorch-core@0.1.0.0/src/tensor/contracts/pointwise.bend as Pointwise

289def shift(~O: Data, ~f: O -> F32 -> F32 -> F32, ~P: Data, ~ia: P -> Nat -> Nat, ~ib: P -> Nat -> Nat,
290  +rest: Nat, +operation: O, +plan: P, +left: Shape.Shape, +left_fill: F32, +left_ops: List<&2, StorageLaws.Op>,
291  +right: Shape.Shape, +right_fill: F32, +right_ops: List<&2, StorageLaws.Op>, +shape: Shape.Shape, +cursor: Nat,
292  -Q: (Core.Dynamic & Core.Dynamic) & Result<&2, &1, Core.Error, Core.Dynamic> -> Type,
293  next: Start(~O, ~f, ~P, ~ia, ~ib, rest, operation, plan, left, left_fill, left_ops, right, right_fill, right_ops, shape, 1n+cursor, Q)) ->
294  Shaped(~O, ~f, ~P, ~ia, ~ib, rest, operation, plan, left, right, shape, 1n+cursor,
295    Replayed.storage(left, left_fill, Replayed.snoc(List.append(&2, StorageLaws.Op, left_ops, Pointwise.reads(~P, ~ia, plan, cursor)),
296      StorageLaws.Read{U32.from_nat(ia(plan, cursor))})),
297    Replayed.storage(right, right_fill, Replayed.snoc(List.append(&2, StorageLaws.Op, right_ops, Pointwise.reads(~P, ~ib, plan, cursor)),
298      StorageLaws.Read{U32.from_nat(ib(plan, cursor))})),
299    Replayed.storage(shape, 0.0, Replayed.snoc(
300      Pointwise.writes(~O, ~f, ~P, ~ia, ~ib, cursor, operation, plan, left, left_fill, left_ops, right, right_fill, right_ops),
301      StorageLaws.Write{U32.from_nat(cursor),
302        f(operation, Replayed.value(left, left_fill, List.append(&2, StorageLaws.Op, left_ops, Pointwise.reads(~P, ~ia, plan, cursor)), U32.from_nat(ia(plan, cursor))),
303          Replayed.value(right, right_fill, List.append(&2, StorageLaws.Op, right_ops, Pointwise.reads(~P, ~ib, plan, cursor)), U32.from_nat(ib(plan, cursor))))})),
304    Q):
305  +left_read = {StorageLaws.Read{U32.from_nat(ia(plan, cursor))} : StorageLaws.Op}
306  +right_read = {StorageLaws.Read{U32.from_nat(ib(plan, cursor))} : StorageLaws.Op}
307  +left_seen = List.append(&2, StorageLaws.Op, left_ops, Pointwise.reads(~P, ~ia, plan, cursor))
308  +right_seen = List.append(&2, StorageLaws.Op, right_ops, Pointwise.reads(~P, ~ib, plan, cursor))
309  +x = Replayed.value(left, left_fill, left_seen, U32.from_nat(ia(plan, cursor)))
310  +y = Replayed.value(right, right_fill, right_seen, U32.from_nat(ib(plan, cursor)))
311  +left_word = Replayed.value(left, left_fill, left_ops, U32.from_nat(ia(plan, cursor)))
312  +right_word = Replayed.value(right, right_fill, right_ops, U32.from_nat(ib(plan, cursor)))
313  +history = Pointwise.writes(~O, ~f, ~P, ~ia, ~ib, cursor, operation, plan, left, left_fill, left_ops, right, right_fill, right_ops)
314  -left_after = Replayed.storage(left, left_fill, Replayed.snoc(left_seen, left_read))
315  -right_after = Replayed.storage(right, right_fill, Replayed.snoc(right_seen, right_read))
316  -output_after = Replayed.storage(shape, 0.0, Replayed.snoc(history, StorageLaws.Write{U32.from_nat(cursor), f(operation, x, y)}))
317  %Equal.cong(List<&2, StorageLaws.Op>, Storage.Storage, ops => Replayed.storage(left, left_fill, ops),
318    List.append(&2, StorageLaws.Op, left_ops, Replayed.snoc(Pointwise.reads(~P, ~ia, plan, cursor), left_read)), Replayed.snoc(left_seen, left_read),
319    append_snoc(left_ops, Pointwise.reads(~P, ~ia, plan, cursor), left_read)) :
320    Shaped(~O, ~f, ~P, ~ia, ~ib, rest, operation, plan, left, right, shape, 1n+cursor, _, right_after, output_after, Q)
321  %Equal.cong(List<&2, StorageLaws.Op>, Storage.Storage, ops => Replayed.storage(right, right_fill, ops),
322    List.append(&2, StorageLaws.Op, right_ops, Replayed.snoc(Pointwise.reads(~P, ~ib, plan, cursor), right_read)), Replayed.snoc(right_seen, right_read),
323    append_snoc(right_ops, Pointwise.reads(~P, ~ib, plan, cursor), right_read)) :
324    Shaped(~O, ~f, ~P, ~ia, ~ib, rest, operation, plan, left, right, shape, 1n+cursor,
325      input_storage(~P, ~ia, plan, left, left_fill, left_ops, 1n+cursor), _, output_after, Q)
326  %Equal.cong(F32, Storage.Storage, word => Replayed.storage(shape, 0.0, Replayed.snoc(history, StorageLaws.Write{U32.from_nat(cursor), word})),
327    f(operation, left_word, right_word), f(operation, x, y),
328    Equal.trans(F32, f(operation, left_word, right_word), f(operation, x, right_word), f(operation, x, y),
329      Equal.cong(F32, F32, word => f(operation, word, right_word), left_word, x,
330        Equal.sym(F32, x, left_word, value_reads(~P, ~ia, plan, cursor, left, left_fill, left_ops, U32.from_nat(ia(plan, cursor))))),
331      Equal.cong(F32, F32, word => f(operation, x, word), right_word, y,
332        Equal.sym(F32, y, right_word, value_reads(~P, ~ib, plan, cursor, right, right_fill, right_ops, U32.from_nat(ib(plan, cursor))))))) :
333    Shaped(~O, ~f, ~P, ~ia, ~ib, rest, operation, plan, left, right, shape, 1n+cursor,
334      input_storage(~P, ~ia, plan, left, left_fill, left_ops, 1n+cursor), input_storage(~P, ~ib, plan, right, right_fill, right_ops, 1n+cursor), _, Q)
335  next

Uses (25)

Used by (1)