forked from dawn-ico/dusk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sparse fill tests and improved reduction tests (dawn-ico#43)
* Improved reduction tests * Added simple sparse fill tests * Addressed PR review * Addressed review comments * Added ambiguous sparse fill tests
- Loading branch information
1 parent
6cce9ce
commit 7c494d5
Showing
2 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from dusk.script import * | ||
from test_util import transpile_and_validate | ||
|
||
|
||
def test_sparse_fill(): | ||
transpile_and_validate(sparse_order_2_fill) | ||
transpile_and_validate(longer_fills) | ||
transpile_and_validate(fill_with_reduction) | ||
transpile_and_validate(ambiguous_fill) | ||
transpile_and_validate(ambiguous_sparse_fill_bug) | ||
|
||
|
||
@stencil | ||
def sparse_order_2_fill( | ||
vertex: Field[Vertex], | ||
edge: Field[Edge, K], | ||
cell: Field[Cell], | ||
ve1: Field[Vertex > Edge, K], | ||
ve2: Field[Vertex > Edge, K], | ||
vc: Field[Vertex > Cell, K], | ||
ev1: Field[Edge > Vertex, K], | ||
ev2: Field[Edge > Vertex, K], | ||
ec: Field[Edge > Cell, K], | ||
cv1: Field[Cell > Vertex, K], | ||
cv2: Field[Cell > Vertex, K], | ||
ce: Field[Cell > Edge, K], | ||
): | ||
|
||
with levels_upward: | ||
|
||
with sparse[Vertex > Edge]: | ||
ve1 = edge + 5 * ve2 + log(vertex) | ||
with sparse[Vertex > Cell]: | ||
vc = cell - 6 | ||
with sparse[Edge > Vertex]: | ||
ev1 = vertex * 7 + ev2 | ||
with sparse[Edge > Cell]: | ||
ec = cell / 8 / sin(edge) | ||
with sparse[Cell > Vertex]: | ||
cv1 = max(max(vertex ** 9, cv2), cell) | ||
with sparse[Cell > Edge]: | ||
ce = sqrt(edge ** 2 + cell ** 2) | ||
|
||
|
||
@stencil | ||
def longer_fills( | ||
sparse1: Field[Vertex > Edge > Cell > Vertex > Edge > Cell], | ||
sparse2: Field[Cell > Edge > Cell > Edge > Cell > Edge], | ||
sparse3: Field[Edge > Cell > Vertex > Edge > Vertex > Edge], | ||
): | ||
with levels_upward: | ||
with sparse[Vertex > Edge > Cell > Vertex > Edge > Cell]: | ||
sparse1 = 50 | ||
|
||
with levels_upward: | ||
with sparse[Cell > Edge > Cell > Edge > Cell > Edge]: | ||
sparse2 = 50 | ||
|
||
with levels_upward: | ||
with sparse[Edge > Cell > Vertex > Edge > Vertex > Edge]: | ||
sparse3 = 50 | ||
|
||
|
||
@stencil | ||
def fill_with_reduction( | ||
sparse1: Field[Edge > Cell > Vertex], | ||
sparse2: Field[Edge > Cell > Vertex], | ||
vertex: Field[Vertex], | ||
edge: Field[Edge, K], | ||
cell: Field[Cell], | ||
): | ||
with levels_upward: | ||
with sparse[Edge > Cell > Vertex]: | ||
sparse1 = sum_over(Vertex > Cell, cell) | ||
sparse2 = min_over(Vertex > Edge, edge) | ||
|
||
with levels_upward: | ||
with sparse[Edge > Cell > Vertex]: | ||
sparse1 = sum_over(Edge > Vertex, vertex[Edge > Vertex]) | ||
sparse2 = sum_over(Edge > Cell, cell) | ||
|
||
with levels_upward: | ||
with sparse[Edge > Cell > Vertex]: | ||
sparse1 = sum_over(Vertex > Cell > Vertex, vertex[Vertex]) | ||
sparse2 = min_over(Vertex > Edge > Vertex, vertex[Vertex > Edge > Vertex]) | ||
|
||
|
||
@stencil | ||
def ambiguous_fill( | ||
sparse1: Field[Edge > Cell > Edge], | ||
sparse2: Field[Edge > Vertex > Edge], | ||
edge1: Field[Edge, K], | ||
edge2: Field[Edge, K], | ||
): | ||
with levels_downward: | ||
with sparse[Edge > Cell > Edge]: | ||
sparse1 = edge1[Edge] + 2 * edge2[Edge > Cell > Edge] | ||
|
||
with levels_downward: | ||
with sparse[Edge > Vertex > Edge]: | ||
sparse2 = edge2[Edge] - 4 * edge1[Edge > Vertex > Edge] | ||
|
||
|
||
@stencil | ||
def ambiguous_sparse_fill_bug( | ||
sparse_field: Field[Edge > Vertex > Edge, K], edge: Field[Edge, K], | ||
): | ||
with levels_downward: | ||
# different location chain in sparse fill than `sparse_field` | ||
with sparse[Edge > Cell > Edge]: | ||
# invalid sparse write | ||
sparse_field = edge[Edge > Cell > Edge] |