Skip to content

Commit

Permalink
add e2e test for extra variable inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
mtghorbani committed Jul 19, 2024
1 parent c01211f commit 684752f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/including-extra-variable.stur
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
symbols: N, M
iters: covar -> iter, i, j, k
covar(j, k) := X(i, j) * X(i, k) * (0 <= iter < 1000)
covar:D(i, j) := (0 <= i < N) * (0 <= j < N)
X:D(i, j) := (0 <= i < M) * (0 <= j < N)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

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

using namespace std;
using namespace std::chrono;

extern "C"
void fn(double ** covar, double ** X, int N, int M) {


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

for (int i = 0; i < M; ++i) {

for (int j = 0; j < N; ++j) {

for (int k = 0; k < min({(j) + 1, N}); ++k) {

covar[j][k] += (X[i][k] * X[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 j = 0; j < N; ++j) {

int kp = j;
for (int k = max({(j) + 1, 0}); k < N; ++k) {

int jp = k;
covar[j][k] = covar[jp][kp];
}
}
end_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_reconstruction = end_reconstruction - start_reconstruction;
cout << time_reconstruction << endl;

}
22 changes: 22 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 @@ -2174,4 +2174,26 @@ class CodegenTest extends AnyFlatSpec with Matchers {
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}

it should "generate correct code while including a non-bound extra variable while mentioning it in the variable ordering without the body" in {
Utils.cnt = 0
Main.main(
Array(
"-i",
"examples/including-extra-variable.stur",
"-o",
"src/test/resources/test_outputs/including-extra-variable_wo_body_test.cpp"
)
)

val file1 = scala.io.Source.fromFile(
"src/test/resources/correct_test_outputs/including-extra-variable_wo_body.cpp"
)
val file2 = scala.io.Source.fromFile(
"src/test/resources/test_outputs/including-extra-variable_wo_body_test.cpp"
)
val lines1 = file1.getLines().toList
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}
}

0 comments on commit 684752f

Please sign in to comment.