-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_svector.t
124 lines (109 loc) · 3.55 KB
/
test_svector.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
import "terratest/terratest"
local SVector = require('svector')
local nfloat = require("nfloat")
local io = terralib.includec("stdio.h")
local float1024 = nfloat.FixedFloat(1024)
for _,T in ipairs{int32,float,double, float1024} do
for N=2,4 do
testenv(N, T) "Static vector" do
local svec = SVector.StaticVector(T,N)
testset "new, size, get, set" do
terracode
var v = svec.new()
for i=0,N do
v:set(i, i+1)
end
end
test v:size()==N
for i=0,N-1 do
test v:get(i) == T(i+1)
end
end
testset "zeros" do
terracode
var v = svec.zeros()
end
test v:size()==N
for i=0,N-1 do
test v:get(i) == 0
end
end
testset "ones" do
terracode
var v = svec.ones()
end
test v:size()==N
for i=0,N-1 do
test v:get(i) == T(1)
end
end
testset "all" do
terracode
var v = svec.all(T(3))
end
test v:size()==N
for i=0,N-1 do
test v:get(i) == T(3)
end
end
end --N
testenv "Fixed N" do
testset "from (N=2)" do
local svec = SVector.StaticVector(T, 2)
terracode
var v = svec.from(1, 2)
end
test v:size() == 2
test v:get(0) == 1
test v:get(1) == 2
end
testset "from (N=3)" do
local svec = SVector.StaticVector(T, 3)
terracode
var v = svec.from(1, 2, 3)
end
test v:size() == 3
test v:get(0) == 1
test v:get(1) == 2
test v:get(2) == 3
end
testset "copy (N=4)" do
local svec = SVector.StaticVector(T, 4)
terracode
var v = svec.from(1, 2, 3, 4)
var w = svec.new()
w:copy(&v)
end
test w:size() == 4
for i = 0, 3 do
test w:get(i) == i + 1
end
end
testset "axpy (N=5)" do
local svec = SVector.StaticVector(T, 5)
terracode
var v = svec.from(1, 2, 3, 4, 5)
var w = svec.from(5, 4, 3, 2, 1)
w:axpy(T(1), &v)
end
test w:size() == 5
for i = 0, 4 do
test w:get(i) == 6
end
end
testset "dot (N=6)" do
local svec = SVector.StaticVector(T, 6)
terracode
var v = svec.from(1, 2, 3, 4, 5, 6)
var w = svec.from(5, 4, 3, 2, 1, 0)
var res = w:dot(&v)
end
test res == 35
end
end
end
end