Skip to content

Commit ada4766

Browse files
committed
test added
1 parent 9b38cab commit ada4766

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

examples/self-inner-product.stur

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
symbols: N
2+
A() := B(i) * B(i)
3+
B:D(i) := (0 <= i) * (i < N)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#include <iostream>
3+
#include <random>
4+
#include <algorithm>
5+
#include <chrono>
6+
7+
using namespace std;
8+
using namespace std::chrono;
9+
10+
extern "C"
11+
void fn(double & A, double * B, int N) {
12+
13+
14+
long time_computation = 0, start_computation, end_computation;
15+
start_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
16+
{
17+
for (int i = 0; i < N; ++i) {
18+
19+
A += (B[i] * B[i]);
20+
}
21+
}
22+
end_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
23+
time_computation = end_computation - start_computation;
24+
cout << time_computation << endl;
25+
long time_reconstruction = 0, start_reconstruction, end_reconstruction;
26+
start_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
27+
28+
end_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
29+
time_reconstruction = end_reconstruction - start_reconstruction;
30+
cout << time_reconstruction << endl;
31+
32+
}

src/test/scala/uk/ac/ed/dal/structtensor/codegen/CodegenTest.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,4 +2196,26 @@ class CodegenTest extends AnyFlatSpec with Matchers {
21962196
val lines2 = file2.getLines().toList
21972197
lines2 should be(lines1)
21982198
}
2199+
2200+
it should "generate correct code for self inner product without the body" in {
2201+
Utils.cnt = 0
2202+
Main.main(
2203+
Array(
2204+
"-i",
2205+
"examples/self-inner-product.stur",
2206+
"-o",
2207+
"src/test/resources/test_outputs/self-inner-product_wo_body_test.cpp"
2208+
)
2209+
)
2210+
2211+
val file1 = scala.io.Source.fromFile(
2212+
"src/test/resources/correct_test_outputs/self-inner-product_wo_body.cpp"
2213+
)
2214+
val file2 = scala.io.Source.fromFile(
2215+
"src/test/resources/test_outputs/self-inner-product_wo_body_test.cpp"
2216+
)
2217+
val lines1 = file1.getLines().toList
2218+
val lines2 = file2.getLines().toList
2219+
lines2 should be(lines1)
2220+
}
21992221
}

0 commit comments

Comments
 (0)