src/tensor/read_write_records.bend
bendtorch-core@0.1.0.0 · 47 lines · 6 definitions
1import Base
2import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
3import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
4import bendtorch-core@0.1.0.0/src/tensor/observation.bend as Observation
5
6type ReadContract<-shape: Shape.Shape, -fill: F32, -index: U32, -code: U32> is Type:
7 ReadContract{
8 outcome: {Observation.read_code(shape, index, Core.new(shape, fill)) == Some{code} : Maybe<&2, U32>},
9 retained_dimensions: {Observation.after_dimensions(shape, index, Core.new(shape, fill)) == Some{Shape.dimensions(shape)} : Maybe<&2, List<&2, U32>>},
10 retained_count: {Observation.after_length(shape, index, Core.new(shape, fill)) == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>},
11 retained_word_count: {Observation.after_count(shape, index, Core.new(shape, fill)) == Some{Shape.count(shape)} : Maybe<&2, U32>},
12 retained_value: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(shape))) == True{} : Bool} ->
13 {Observation.after_value(shape, index, other, Core.new(shape, fill)) == Some{fill} : Maybe<&2, F32>}}
14
15type ReadInside<-shape: Shape.Shape, -fill: F32, -index: U32> is Type:
16 ReadInside{
17 read: ReadContract<shape, fill, index, 0>,
18 value: {Observation.point(shape, index, Core.new(shape, fill)) == Some{fill} : Maybe<&2, F32>}}
19
20type WriteContract<-shape: Shape.Shape, -fill: F32, -index: U32, -value: F32, -code: U32> is Type:
21 WriteContract{
22 outcome: {Observation.write_code(shape, index, value, Core.new(shape, fill)) == Some{code} : Maybe<&2, U32>},
23 retained_dimensions: {Observation.written_dimensions(shape, index, value, Core.new(shape, fill)) == Some{Shape.dimensions(shape)} : Maybe<&2, List<&2, U32>>},
24 retained_count: {Observation.written_length(shape, index, value, Core.new(shape, fill)) == Some{Shape.logical_numel(Shape.dimensions(shape))} : Maybe<&2, Nat>},
25 retained_word_count: {Observation.written_count(shape, index, value, Core.new(shape, fill)) == Some{Shape.count(shape)} : Maybe<&2, U32>}}
26
27type WriteInside<-shape: Shape.Shape, -fill: F32, -index: U32, -value: F32> is Type:
28 WriteInside{
29 write: WriteContract<shape, fill, index, value, 0>,
30 written: {Observation.written_value(shape, index, value, index, Core.new(shape, fill)) == Some{value} : Maybe<&2, F32>},
31 frame: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(shape))) == True{} : Bool} ->
32 @different: {Nat.is_eq(U32.to_nat(index), U32.to_nat(other)) == False{} : Bool} ->
33 {Observation.written_value(shape, index, value, other, Core.new(shape, fill)) == Some{fill} : Maybe<&2, F32>}}
34
35type WriteOutside<-shape: Shape.Shape, -fill: F32, -index: U32, -value: F32> is Type:
36 WriteOutside{
37 write: WriteContract<shape, fill, index, value, 8>,
38 retained_value: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(shape))) == True{} : Bool} ->
39 {Observation.written_value(shape, index, value, other, Core.new(shape, fill)) == Some{fill} : Maybe<&2, F32>}}
40
41type CoordinateInside<-shape: Shape.Shape, -fill: F32, -coordinates: List<&2, U32>, -index: U32, -value: F32> is Type:
42 CoordinateInside{
43 read: {Observation.coordinate_value(shape, index, value, coordinates, Core.new(shape, fill)) == Some{value} : Maybe<&2, F32>},
44 written: {Observation.coordinate_written(shape, coordinates, value, index, Core.new(shape, fill)) == Some{value} : Maybe<&2, F32>},
45 frame: @+other: U32 -> @inside: {Nat.is_lt(U32.to_nat(other), Shape.logical_numel(Shape.dimensions(shape))) == True{} : Bool} ->
46 @different: {Nat.is_eq(U32.to_nat(index), U32.to_nat(other)) == False{} : Bool} ->
47 {Observation.coordinate_written(shape, coordinates, value, other, Core.new(shape, fill)) == Some{fill} : Maybe<&2, F32>}}