-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_momfit.t
46 lines (42 loc) · 1.44 KB
/
test_momfit.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
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local alloc = require("alloc")
local base = require("base")
local range = require("range")
local momfit = require("momfit")
local tmath = require("tmath")
import "terratest/terratest"
local tols = {
[float] = `1e-6f,
[double] = `1e-15,
}
for T, tol in pairs(tols) do
testenv(T) "Clenshaw-Curtis with constant weight" do
local Interval = momfit.IntervalFactory(T)
local ConstMom = momfit.ConstMom(T)
local DefaultAlloc = alloc.DefaultAllocator()
local io = terralib.includec("stdio.h")
for N = 1, 30 do
testset(N) "Order" do
terracode
var alloc: DefaultAlloc
var refdom = Interval.new(-1, 1)
var rec: ConstMom
var xq, wq = momfit.clenshawcurtis(&alloc, N, &rec, &refdom)
var res: T = 0
for xw in range.zip(&xq, &wq) do
var x, w = xw
res = res + w * x * x
end
var ref = [T](2) / 3
end
test tmath.isapprox(wq:sum(), 2, 2 * tol)
if N > 2 then
test tmath.isapprox(res, ref, ref * tol)
end
end
end
end
end