src/tensor/slice_LAWS.bend open laws/TODOs
raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/slice_LAWS.bend as Slice_LAWS
9 imports
import Base import ../shape/core.bend as Shape import ../storage/model.bend as Model import ../storage/refinement.bend as Refinement import ./core.bend as Core import ./layout.bend as Layout import ./transforms.bend as Transforms import ./elementwise_totality.bend as Totality import ./slice.bend as Slice
Laws
law slice_start_kept provedin PROOF.bendsource · line 30 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @inside:{Nat.is_le(start, extent) == True{} : Bool} -> {low(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) == start : Nat}PyTorch's clamp of a slice to an axis of extent n. A start at most n is kept, a start past n becomes n.
law slice_start_clamped provedin PROOF.bendsource · line 37 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @past:{Nat.is_le(extent, start) == True{} : Bool} -> {low(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) == extent : Nat}
law slice_stop_kept provedin PROOF.bendsource · line 46 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @+after:{Nat.is_le(start, stop) == True{} : Bool} -> @+inside:{Nat.is_le(stop, extent) == True{} : Bool} -> {high(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) == stop : Nat}A stop from the start to n is kept, a stop past n becomes n, and a stop at or before the start ends the slice at its start: an empty axis.
law slice_stop_clamped provedin PROOF.bendsource · line 54 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @past:{Nat.is_le(extent, stop) == True{} : Bool} -> {high(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) == extent : Nat}
law slice_stop_empty provedin PROOF.bendsource · line 61 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @before:{Nat.is_le(stop, start) == True{} : Bool} -> {high(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) == low(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.bounds(extent, start, stop)) : Nat}
law slice_length_below provedin PROOF.bendsource · line 72 · raw
@+start:Nat -> @+stop:Nat -> @+step:Nat -> @+k:Nat -> @below:{Nat.is_lt(k, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Bounds{start, stop}, step)) == True{} : Bool} -> {Nat.is_lt(Nat.add(start, Nat.mul(k, step)), stop) == True{} : Bool}The length of the sliced axis is the number of indices start, start + step, start + 2 step, ... below the stop: each index below the length lies below the stop, and, for a positive step, the index at the length does not.
law slice_length_reaches provedin PROOF.bendsource · line 80 · raw
@+start:Nat -> @+stop:Nat -> @+step:Nat -> @positive:{Nat.is_lt(0n, step) == True{} : Bool} -> {Nat.is_le(stop, Nat.add(start, Nat.mul(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.length(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Bounds{start, stop}, step), step))) == True{} : Bool}
law slice_view_around provedin PROOF.bendsource · line 90 · raw
@+prefix:List<&2, U32> -> @+extent:U32 -> @+suffix:List<&2, U32> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.view(List.append(&2, U32, prefix, extent <> suffix), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(prefix)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.View{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(prefix), U32.to_nat(extent), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(suffix)} : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.View}The row-major view around axis dim of dimensions prefix ++ [extent] ++
suffix, with dim the rank of the prefix: the element count of the
prefix, the extent, and the element count of the suffix.
law slice_resized_around provedin PROOF.bendsource · line 99 · raw
@+prefix:List<&2, U32> -> @+extent:U32 -> @+suffix:List<&2, U32> -> @+other:U32 -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.resized(List.append(&2, U32, prefix, extent <> suffix), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(prefix), other) == List.append(&2, U32, prefix, other <> suffix) : List<&2, U32>}The sliced output keeps every other axis and takes the new extent at the
axis; select drops the axis.
law select_dropped_around provedin PROOF.bendsource · line 107 · raw
@+prefix:List<&2, U32> -> @+extent:U32 -> @+suffix:List<&2, U32> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.dropped(List.append(&2, U32, prefix, extent <> suffix), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(prefix)) == List.append(&2, U32, prefix, suffix) : List<&2, U32>}
law slice_plan_axis provedin PROOF.bendsource · line 144 · raw
@+prefix:List<&2, U32> -> @+extent:U32 -> @+suffix:List<&2, U32> -> @+dim:U32 -> @at:{U32.to_nat(dim) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(prefix) : Nat} -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> {axis_part(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan_of(List.append(&2, U32, prefix, extent <> suffix), dim, start, stop, step)) == axis_spec(U32.to_nat(extent), U32.to_nat(start), U32.to_nat(stop), U32.to_nat(step)) : Pair(Nat, Pair(Nat, Pair(Nat, Nat)))}The plan of a request at axis dim of prefix ++ [extent] ++ suffix, with
dim the rank of the prefix, holds the request's own start, stop and step,
clamped to that extent, whatever the other extents, an empty input's
included.
law slice_plan_view provedin PROOF.bendsource · line 158 · raw
@+prefix:List<&2, U32> -> @+extent:U32 -> @+suffix:List<&2, U32> -> @+dim:U32 -> @at:{U32.to_nat(dim) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(prefix) : Nat} -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @nonempty:{Nat.is_lt(0n, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(List.append(&2, U32, prefix, extent <> suffix))) == True{} : Bool} -> {view_part(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan_of(List.append(&2, U32, prefix, extent <> suffix), dim, start, stop, step)) == (0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(prefix), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(suffix)) : Pair(Nat, Nat)}For an input with an element, the plan's view is the element counts of the prefix and of the suffix, the row-major view around the axis.
law slice_plan_empty_view provedin PROOF.bendsource · line 174 · raw
@+dimensions:List<&2, U32> -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @empty:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(dimensions) == 0n : Nat} -> {view_part(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan_of(dimensions, dim, start, stop, step)) == (0n, 0n) : Pair(Nat, Nat)}An input with no element gets a plan with no view: neither build has a cell then, so the plan forms no product of the other extents, which can pass the largest Nat the runtime holds although no element exists.
law slice_axis_refused provedin PROOF.bendsource · line 185 · raw
@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @outside:{Nat.is_lt(U32.to_nat(dim), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input))) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan(input, dim, start, stop, step) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.LayoutError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.AxisOutOfBounds{}}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned>}PyTorch's checks, in its order. An axis at or past the rank (every axis of a rank-0 input) is refused first, then a step of 0.
law slice_step_refused provedin PROOF.bendsource · line 195 · raw
@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @inside:{Nat.is_lt(U32.to_nat(dim), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.rank_dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input))) == True{} : Bool} -> @zero:{U32.to_nat(step) == 0n : Nat} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan(input, dim, start, stop, step) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.StepNotPositive{}} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned>}
law slice_planned provedin PROOF.bendsource · line 217 · raw
@+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> PlannedAs(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(input), dim, start, stop, step, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan(input, dim, start, stop, step))
law slice_refused provedin PROOF.bendsource · line 226 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @error:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error -> @refused:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.plan(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_totality.dynamic_shape(input), dim, start, stop, step) == Fail{error} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned>} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.slice(input, dim, start, stop, step) == (input, Fail{error}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}A refused plan fails the slice with its error and hands the input back.
law narrow_slices provedin PROOF.bendsource · line 246 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+start:U32 -> @+length:U32 -> @inside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == True{} : Bool} -> @fits:{Nat.is_le(Nat.add(U32.to_nat(start), U32.to_nat(length)), extent_of(input, dim)) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.narrow(input, dim, start, length) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.slice(input, dim, start, U32.add(start, length), 1) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}PyTorch's narrow(dim, start, length) is the slice start:start + length with step 1, once the axis is in range and start + length is at most the extent; a start + length past the extent is refused with OutOfRange, an axis past the rank as a slice refuses it.
law narrow_out_of_range provedin PROOF.bendsource · line 256 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+start:U32 -> @+length:U32 -> @inside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == True{} : Bool} -> @past:{Nat.is_le(Nat.add(U32.to_nat(start), U32.to_nat(length)), extent_of(input, dim)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.narrow(input, dim, start, length) == (input, Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.OutOfRange{}}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}
law narrow_axis_refused provedin PROOF.bendsource · line 265 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+start:U32 -> @+length:U32 -> @outside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.narrow(input, dim, start, length) == (input, Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.LayoutError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.AxisOutOfBounds{}}}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}
law select_slices provedin PROOF.bendsource · line 297 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+index:U32 -> @inside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == True{} : Bool} -> @below:{Nat.is_lt(U32.to_nat(index), extent_of(input, dim)) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.select(input, dim, index) == reshaped(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.dropped(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_totality.dynamic_shape(input)), U32.to_nat(dim)), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.slice(input, dim, index, U32.add(index, 1), 1)) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}PyTorch's select(dim, index) is the slice index:index + 1 with step 1, reshaped to the input's dimensions without the axis, once the axis is in range and the index below the extent; an index at or past the extent is refused with OutOfRange, an axis past the rank as a slice refuses it.
law select_out_of_range provedin PROOF.bendsource · line 307 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+index:U32 -> @inside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == True{} : Bool} -> @past:{Nat.is_lt(U32.to_nat(index), extent_of(input, dim)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.select(input, dim, index) == (input, Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.OutOfRange{}}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}
law select_axis_refused provedin PROOF.bendsource · line 315 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> @+index:U32 -> @outside:{Nat.is_lt(U32.to_nat(dim), rank_of(input)) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.select(input, dim, index) == (input, Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.LayoutError{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/layout.AxisOutOfBounds{}}}) : Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)}
law slice_build_cells provedin PROOF.bendsource · line 333 · raw
@+depth:Nat -> @+splits:Nat -> @+outer:Nat -> @+extent:Nat -> @+inner:Nat -> @+start:Nat -> @+step:Nat -> @+length:Nat -> @+count:Nat -> @+base:Nat -> @+da:Nat -> @-A:Array<F32> -> @a:Array<F32> -> @same:{a == A : Array<F32>} -> @valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, da, A) -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @+o:Nat -> @+k:Nat -> @+r:Nat -> @k_below:{Nat.is_lt(k, length) == True{} : Bool} -> @r_below:{Nat.is_lt(r, inner) == True{} : Bool} -> @at:{Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base) == position(length, inner, o, k, r) : Nat} -> @inside:{Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), count) == True{} : Bool} -> Holds<{0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.build(depth, splits, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan{outer, extent, inner, start, step, length}, count, base, a), path) == 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, da, A, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/refinement.route(da, U32.from_nat(position(extent, inner, o, Nat.add(start, Nat.mul(k, step)), r)))) : Maybe<&2, F32>}>For a balanced input array A and every split, the slot of the forward build that holds output cell (o, k, r), below the count, holds input cell (o, start + k * step, r): the word PyTorch's slice puts there.
law slice_scatter_hit provedin PROOF.bendsource · line 364 · raw
@+depth:Nat -> @+splits:Nat -> @+outer:Nat -> @+extent:Nat -> @+inner:Nat -> @+start:Nat -> @+step:Nat -> @+length:Nat -> @+count:Nat -> @+base:Nat -> @+dg:Nat -> @-G:Array<F32> -> @g:Array<F32> -> @same:{g == G : Array<F32>} -> @valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, dg, G) -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @+o:Nat -> @+k:Nat -> @+r:Nat -> @positive:{Nat.is_lt(0n, step) == True{} : Bool} -> @k_below:{Nat.is_lt(k, length) == True{} : Bool} -> @i_below:{Nat.is_lt(Nat.add(start, Nat.mul(k, step)), extent) == True{} : Bool} -> @r_below:{Nat.is_lt(r, inner) == True{} : Bool} -> @at:{Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base) == position(extent, inner, o, Nat.add(start, Nat.mul(k, step)), r) : Nat} -> @inside:{Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), count) == True{} : Bool} -> Holds<{0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.scatter_build(depth, splits, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan{outer, extent, inner, start, step, length}, count, base, g), path) == 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, dg, G, 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/refinement.route(dg, U32.from_nat(position(length, inner, o, k, r)))) : Maybe<&2, F32>}>For a balanced gradient array G and every split, the slot of the backward build that holds input cell (o, start + k * step, r), with k below the length and a positive step, holds gradient cell (o, k, r) ...
law slice_scatter_miss provedin PROOF.bendsource · line 395 · raw
@+depth:Nat -> @+splits:Nat -> @+outer:Nat -> @+extent:Nat -> @+inner:Nat -> @+start:Nat -> @+step:Nat -> @+length:Nat -> @+count:Nat -> @+base:Nat -> @+dg:Nat -> @-G:Array<F32> -> @g:Array<F32> -> @same:{g == G : Array<F32>} -> @valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, dg, G) -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(depth) -> @+o:Nat -> @+i:Nat -> @+r:Nat -> @i_below:{Nat.is_lt(i, extent) == True{} : Bool} -> @r_below:{Nat.is_lt(r, inner) == True{} : Bool} -> @missed:(@+k:Nat -> @below:{Nat.is_lt(k, length) == True{} : Bool} -> {Nat.is_eq(Nat.add(start, Nat.mul(k, step)), i) == False{} : Bool}) -> @at:{Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base) == position(extent, inner, o, i, r) : Nat} -> @inside:{Nat.is_lt(Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(depth, path), base), count) == True{} : Bool} -> Holds<{0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, depth, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.scatter_build(depth, splits, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan{outer, extent, inner, start, step, length}, count, base, g), path) == Some{0.0} : Maybe<&2, F32>}>... and the slot of input cell (o, i, r) where no k below the length has i = start + k * step holds +0.0, as PyTorch's slice_backward leaves it.
Types
type Holds source · line 17 · raw
@-P:Type -> Data
Holds@-P:Type -> @-proof:P -> Holds<P>
Definitions
def low source · line 20 · raw
@+clamped:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Bounds -> Nat
def high source · line 24 · raw
@+clamped:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Bounds -> Nat
def axis_part source · line 116 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan -> Pair(Nat, Pair(Nat, Pair(Nat, Nat)))
What a plan holds along its axis (the extent, the clamped start, the step and the length) and around it (the element counts before and after it).
def view_part source · line 120 · raw
@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan -> Pair(Nat, Nat)
def clamp source · line 126 · raw
@+position:Nat -> @+extent:Nat -> Nat
PyTorch's clamp of a slice position to an axis of extent n: the position if it is at most n, else n.
def clamped_stop source · line 131 · raw
@+start:Nat -> @+stop:Nat -> @+extent:Nat -> Nat
The stop after the clamp: the clamped stop, or the clamped start where the clamped stop falls before it, so the axis is empty.
def axis_spec source · line 136 · raw
@+extent:Nat -> @+start:Nat -> @+stop:Nat -> @+step:Nat -> Pair(Nat, Pair(Nat, Pair(Nat, Nat)))
What a request start:stop:step plans along an axis of extent n: the extent, the clamped start, the step, and the length of the clamped range.
def PlannedAs source · line 208 · raw
@+dimensions:List<&2, U32> -> @+dim:U32 -> @+start:U32 -> @+stop:U32 -> @+step:U32 -> @result:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned> -> Type
What an accepted slice plans: the view around the axis, the start and stop clamped to the extent, the step, the length of the sliced axis, and the output's dimensions, the input's with that length at the axis.
def rank_of source · line 236 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Nat
def extent_of source · line 239 · raw
@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+dim:U32 -> Nat
def reshape_as_slice source · line 275 · raw
@result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/transforms.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>
A slice's result with its output reshaped to dimensions.
def reshaped source · line 284 · raw
@+dimensions:List<&2, U32> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)
def position source · line 327 · raw
@+rows:Nat -> @+inner:Nat -> @+o:Nat -> @+i:Nat -> @+r:Nat -> Nat
The cells of the builds, in the coordinates of the views: output cell (o, k, r) of [outer, length, inner] sits at row-major position (o * length + k) * inner + r, and input cell (o, i, r) of [outer, extent, inner] at (o * extent + i) * inner + r.