Skip to content

Commit

Permalink
Add More Tests and Fix Minor Issues
Browse files Browse the repository at this point in the history
This adds some more tests, and fixes a number of minor issues around the
expansion function for interleaving assignments.
  • Loading branch information
DavePearce committed Jul 4, 2024
1 parent 5d91328 commit 7c0e6d2
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pkg/schema/assignment/interleave.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ func (p *Interleaving) ExpandTrace(tr tr.Trace) error {
data := make([]*fr.Element, height*width)
// Offset just gives the column index
offset := uint(0)
//
// Copy interleaved data
for i := uint(0); i < columns.Len(); i++ {
col := columns.Get(i)
for i := uint(0); i < width; i++ {
// Lookup source column
col := tr.Columns().Get(p.sources[i])
// Copy over
for j := uint(0); j < height; j++ {
data[offset+(j*width)] = col.Get(int(j))
}
Expand All @@ -108,7 +109,7 @@ func (p *Interleaving) ExpandTrace(tr tr.Trace) error {
// column in the interleaving.
padding := columns.Get(0).Padding()
// Colunm needs to be expanded.
columns.Add(trace.NewFieldColumn(p.module, p.target.Name(), width, data, padding))
columns.Add(trace.NewFieldColumn(p.module, p.target.Name(), multiplier*width, data, padding))
//
return nil
}
4 changes: 2 additions & 2 deletions pkg/schema/constraint/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (p *LookupConstraint[E]) Targets() []E {
//nolint:revive
func (p *LookupConstraint[E]) Accepts(tr trace.Trace) error {
// Determine height of enclosing module for source columns
src_height := tr.Modules().Get(p.source).Height()
tgt_height := tr.Modules().Get(p.target).Height()
src_height := tr.Modules().Get(p.source).Height() * p.source_multiplier
tgt_height := tr.Modules().Get(p.target).Height() * p.target_multiplier
// Go through every row of the source columns checking they are present in
// the target columns.
//
Expand Down
12 changes: 12 additions & 0 deletions pkg/test/ir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ func Test_Interleave_01(t *testing.T) {
Check(t, "interleave_01")
}

func Test_Interleave_02(t *testing.T) {
Check(t, "interleave_02")
}

func Test_Interleave_03(t *testing.T) {
Check(t, "interleave_03")
}

func Test_Interleave_04(t *testing.T) {
Check(t, "interleave_04")
}

// ===================================================================
// Complex Tests
// ===================================================================
Expand Down
4 changes: 4 additions & 0 deletions testdata/interleave_01.accepts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{ "X": [], "Y": [] }
{ "X": [0], "Y": [0] }
{ "X": [0,0], "Y": [0,0] }
{ "X": [0,0,0], "Y": [0,0,0] }
{ "X": [0,0,0,0], "Y": [0,0,0,0] }
11 changes: 11 additions & 0 deletions testdata/interleave_01.rejects
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
{ "X": [1], "Y": [0] }
{ "X": [0], "Y": [1] }
{ "X": [0,0], "Y": [0,1] }
{ "X": [0,0], "Y": [1,0] }
{ "X": [0,1], "Y": [0,0] }
{ "X": [1,0], "Y": [0,0] }
;;
{ "X": [1,0], "Y": [0,1] }
{ "X": [0,1], "Y": [0,1] }
{ "X": [1,0], "Y": [1,0] }
{ "X": [0,1], "Y": [1,0] }
{ "X": [1,0], "Y": [0,1] }
{ "X": [0,1], "Y": [0,1] }
16 changes: 16 additions & 0 deletions testdata/interleave_02.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ "X": [], "Y": [] }
{ "X": [0], "Y": [0] }
{ "X": [1], "Y": [1] }
{ "X": [1], "Y": [2] }
;;
{ "X": [0,0], "Y": [0,0] }
{ "X": [0,0], "Y": [0,1] }
{ "X": [0,1], "Y": [0,1] }
{ "X": [0,1], "Y": [1,1] }
{ "X": [1,1], "Y": [1,1] }
{ "X": [1,1], "Y": [1,2] }
{ "X": [1,2], "Y": [1,2] }
{ "X": [1,2], "Y": [2,2] }
{ "X": [1,2], "Y": [2,3] }
{ "X": [1,3], "Y": [2,3] }
{ "X": [1,3], "Y": [2,4] }
5 changes: 5 additions & 0 deletions testdata/interleave_02.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(column X)
(column Y)
(interleave Z (X Y))
;; Z[k]+1 == Z[k+1] || Z[k] == Z[k+1]
(vanish c1 (* (- (+ 1 Z) (shift Z 1)) (- Z (shift Z 1))))
16 changes: 16 additions & 0 deletions testdata/interleave_02.rejects
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ "X": [1], "Y": [0] }
{ "X": [0], "Y": [2] }
{ "X": [2], "Y": [2] }
;;
{ "X": [0,0], "Y": [1,0] }
{ "X": [0,1], "Y": [0,0] }
{ "X": [1,0], "Y": [0,0] }
{ "X": [1,0], "Y": [1,0] }
{ "X": [1,1], "Y": [1,0] }
{ "X": [1,2], "Y": [1,1] }
{ "X": [1,1], "Y": [2,1] }
{ "X": [2,1], "Y": [1,1] }
{ "X": [1,2], "Y": [2,1] }
{ "X": [2,1], "Y": [2,1] }
{ "X": [2,2], "Y": [2,1] }
{ "X": [1,1], "Y": [1,3] }
5 changes: 5 additions & 0 deletions testdata/interleave_03.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ "X": [], "Y": [] }
{ "X": [0], "Y": [0] }
{ "X": [0,0], "Y": [0,0] }
{ "X": [0,0,0], "Y": [0,0,0] }
{ "X": [0,0,0,0], "Y": [0,0,0,0] }
6 changes: 6 additions & 0 deletions testdata/interleave_03.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(column X)
(column Y)
(interleave A (X Y))
(interleave B (X Y))
(interleave Z (A B))
(vanish c1 Z)
13 changes: 13 additions & 0 deletions testdata/interleave_03.rejects
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ "X": [1], "Y": [0] }
{ "X": [0], "Y": [1] }
{ "X": [0,0], "Y": [0,1] }
{ "X": [0,0], "Y": [1,0] }
{ "X": [0,1], "Y": [0,0] }
{ "X": [1,0], "Y": [0,0] }
;;
{ "X": [1,0], "Y": [0,1] }
{ "X": [0,1], "Y": [0,1] }
{ "X": [1,0], "Y": [1,0] }
{ "X": [0,1], "Y": [1,0] }
{ "X": [1,0], "Y": [0,1] }
{ "X": [0,1], "Y": [0,1] }
20 changes: 20 additions & 0 deletions testdata/interleave_04.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ "X": [], "Y": [], "Z": [] }
{ "X": [0], "Y": [0], "Z": [0] }
{ "X": [1], "Y": [2], "Z": [1] }
;;
{ "X": [1,2], "Y": [3,4], "Z": [0,0] }
{ "X": [1,2], "Y": [3,4], "Z": [0,1] }
{ "X": [1,2], "Y": [3,4], "Z": [1,0] }
{ "X": [1,2], "Y": [3,4], "Z": [1,1] }
{ "X": [2,1], "Y": [3,4], "Z": [0,0] }
{ "X": [2,1], "Y": [3,4], "Z": [0,1] }
{ "X": [2,1], "Y": [3,4], "Z": [1,0] }
{ "X": [2,1], "Y": [3,4], "Z": [1,1] }
{ "X": [1,2], "Y": [4,3], "Z": [0,0] }
{ "X": [1,2], "Y": [4,3], "Z": [0,1] }
{ "X": [1,2], "Y": [4,3], "Z": [1,0] }
{ "X": [1,2], "Y": [4,3], "Z": [1,1] }
{ "X": [2,1], "Y": [4,3], "Z": [0,0] }
{ "X": [2,1], "Y": [4,3], "Z": [0,1] }
{ "X": [2,1], "Y": [4,3], "Z": [1,0] }
{ "X": [2,1], "Y": [4,3], "Z": [1,1] }
5 changes: 5 additions & 0 deletions testdata/interleave_04.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(column X)
(column Y)
(column Z)
(interleave A (X Y))
(lookup l1 (A) (Z))
17 changes: 17 additions & 0 deletions testdata/interleave_04.rejects
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ "X": [1], "Y": [2], "Z": [3] }
;;
{ "X": [1,2], "Y": [2,1], "Z": [0,3] }
{ "X": [1,2], "Y": [2,1], "Z": [3,0] }
;;
{ "X": [1,1,2], "Y": [4,4,5], "Z": [0,1,3] }
{ "X": [1,1,2], "Y": [4,4,5], "Z": [1,0,3] }
{ "X": [1,1,2], "Y": [4,4,5], "Z": [0,3,1] }
{ "X": [1,1,2], "Y": [4,4,5], "Z": [1,3,0] }
{ "X": [1,2,1], "Y": [4,5,4], "Z": [0,1,3] }
{ "X": [1,2,1], "Y": [4,5,4], "Z": [1,0,3] }
{ "X": [1,2,1], "Y": [4,5,4], "Z": [0,3,1] }
{ "X": [1,2,1], "Y": [4,5,4], "Z": [1,3,0] }
{ "X": [2,1,1], "Y": [5,4,4], "Z": [0,1,3] }
{ "X": [2,1,1], "Y": [5,4,4], "Z": [1,0,3] }
{ "X": [2,1,1], "Y": [5,4,4], "Z": [0,3,1] }
{ "X": [2,1,1], "Y": [5,4,4], "Z": [1,3,0] }

0 comments on commit 7c0e6d2

Please sign in to comment.