Skip to content

Commit

Permalink
test added
Browse files Browse the repository at this point in the history
  • Loading branch information
mtghorbani committed Oct 28, 2024
1 parent 9b38cab commit ada4766
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/self-inner-product.stur
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
symbols: N
A() := B(i) * B(i)
B:D(i) := (0 <= i) * (i < N)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#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) {

A += (B[i] * B[i]);
}
}
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();

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

it should "generate correct code for self inner product without the body" in {
Utils.cnt = 0
Main.main(
Array(
"-i",
"examples/self-inner-product.stur",
"-o",
"src/test/resources/test_outputs/self-inner-product_wo_body_test.cpp"
)
)

val file1 = scala.io.Source.fromFile(
"src/test/resources/correct_test_outputs/self-inner-product_wo_body.cpp"
)
val file2 = scala.io.Source.fromFile(
"src/test/resources/test_outputs/self-inner-product_wo_body_test.cpp"
)
val lines1 = file1.getLines().toList
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}
}

0 comments on commit ada4766

Please sign in to comment.