Skip to content

Commit

Permalink
add tests for skew-symmerty and fancy skew-symmetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mtghorbani committed Jul 17, 2024
1 parent 7da9053 commit 4329cd4
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/fancy-symmetry.stur
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
symbols: N
A(i, j) := B(i, j)
A:D(i, j) := (0 <= i < N) * (0 <= j < N)
B:D(i, j) := (0 <= i < N) * (0 <= j < N)
B:U(i, j) := (0 <= i <= j < N)
B:R(i, j, ip, jp) := -21.5 * (0 <= j < i < N) * (ip = j) * (jp = i)
6 changes: 6 additions & 0 deletions examples/skew-symmetry.stur
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
symbols: N
A(i, j) := B(i, j)
A:D(i, j) := (0 <= i < N) * (0 <= j < N)
B:D(i, j) := (0 <= i < N) * (0 <= j < N)
B:U(i, j) := (0 <= i <= j < N)
B:R(i, j, ip, jp) := -1 * (0 <= j < i < N) * (ip = j) * (jp = i)
41 changes: 41 additions & 0 deletions src/test/resources/correct_test_outputs/fancy-symmetry_wo_body.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#include <iostream>
#include <random>
#include <algorithm>
#include <chrono>

using namespace std;
using namespace std::chrono;

extern "C"
void fn(double ** A, double ** B, int N) {


long time_computation = 0, start_computation, end_computation;
start_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
for (int i = 0; i < N; ++i) {

for (int j = max({0, i}); j < N; ++j) {

A[i][j] += B[i][j];
}
}
end_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_computation = end_computation - start_computation;
cout << time_computation << endl;
long time_reconstruction = 0, start_reconstruction, end_reconstruction;
start_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();


for (int ip = 0; ip < N; ++ip) {
int j = ip;
for (int jp = max({0, (ip) + 1}); jp < N; ++jp) {
int i = jp;
A[i][j] = (A[ip][jp] * -21.5);
}
}
end_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_reconstruction = end_reconstruction - start_reconstruction;
cout << time_reconstruction << endl;

}
41 changes: 41 additions & 0 deletions src/test/resources/correct_test_outputs/skew-symmetry_wo_body.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#include <iostream>
#include <random>
#include <algorithm>
#include <chrono>

using namespace std;
using namespace std::chrono;

extern "C"
void fn(double ** A, double ** B, int N) {


long time_computation = 0, start_computation, end_computation;
start_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
for (int i = 0; i < N; ++i) {

for (int j = max({0, i}); j < N; ++j) {

A[i][j] += B[i][j];
}
}
end_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_computation = end_computation - start_computation;
cout << time_computation << endl;
long time_reconstruction = 0, start_reconstruction, end_reconstruction;
start_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();


for (int ip = 0; ip < N; ++ip) {
int j = ip;
for (int jp = max({0, (ip) + 1}); jp < N; ++jp) {
int i = jp;
A[i][j] = (A[ip][jp] * -1);
}
}
end_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_reconstruction = end_reconstruction - start_reconstruction;
cout << time_reconstruction << endl;

}
44 changes: 44 additions & 0 deletions src/test/scala/uk/ac/ed/dal/structtensor/codegen/CodegenTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2042,4 +2042,48 @@ class CodegenTest extends AnyFlatSpec with Matchers {
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}

it should "generate code for skew-symmetry structure without the body" in {
Utils.cnt = 0
Main.main(
Array(
"-i",
"examples/skew-symmetry.stur",
"-o",
"src/test/resources/test_outputs/skew-symmetry_wo_body_test.cpp"
)
)

val file1 = scala.io.Source.fromFile(
"src/test/resources/correct_test_outputs/skew-symmetry_wo_body.cpp"
)
val file2 = scala.io.Source.fromFile(
"src/test/resources/test_outputs/skew-symmetry_wo_body_test.cpp"
)
val lines1 = file1.getLines().toList
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}

it should "generate code for fancy-symmetry structure without the body" in {
Utils.cnt = 0
Main.main(
Array(
"-i",
"examples/fancy-symmetry.stur",
"-o",
"src/test/resources/test_outputs/fancy-symmetry_wo_body_test.cpp"
)
)

val file1 = scala.io.Source.fromFile(
"src/test/resources/correct_test_outputs/fancy-symmetry_wo_body.cpp"
)
val file2 = scala.io.Source.fromFile(
"src/test/resources/test_outputs/fancy-symmetry_wo_body_test.cpp"
)
val lines1 = file1.getLines().toList
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}
}

0 comments on commit 4329cd4

Please sign in to comment.