Skip to content

Commit b58ab49

Browse files
authored
#38 add assertclose support bump chapel versions (#40)
* [#38]: update minimum chapel version and github workflow to use 2.8.0, fix minor chplcheck issues * [#38]: add assertClose to appropriate test procedures. cleanup formatting for chplcheck. --- Signed-off-by: Jared Magnusson <jmag722@gmail.com>
1 parent bb5cdd9 commit b58ab49

File tree

8 files changed

+51
-71
lines changed

8 files changed

+51
-71
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
# whatever's not 'deprecated' on Spack
13-
chapel-version: ['2.6.0', '2.5.0', '2.4.0']
12+
chapel-version: [
13+
'2.8.0',
14+
]
1415
container:
1516
image: chapel/chapel:${{ matrix.chapel-version }}
1617
steps:
@@ -25,5 +26,4 @@ jobs:
2526
run: mason test --show
2627
- name: Running chplcheck...
2728
id: code-check
28-
# TODO: remove --disable-rule after dropping chapel 2.4.0 support
29-
run: chplcheck --disable-rule CamelCaseFunctions $(find . -type f -iname "*.chpl")
29+
run: chplcheck $(find . -type f -iname "*.chpl")

Mason.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[brick]
22
name="SciChap"
33
version="0.1.0"
4-
chplVersion="2.4.0"
4+
chplVersion="2.8.0"
55
license="BSD-3-Clause"
66
type="library"
77

src/SciChap/Array.chpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Array {
1212
:rtype: [] T
1313
*/
1414
proc diff(const ref arr: [?D] ?T): [0..<D.size-1] T
15-
where (D.rank == 1 && isNumeric(T)){
15+
where D.rank == 1 && isNumeric(T) {
1616
return arr[D.first+1..] - arr[..<D.last];
1717
}
1818

@@ -25,7 +25,7 @@ module Array {
2525
:rtype: bool
2626
*/
2727
proc isMonotonic(const ref x: [?D] ?T): bool
28-
where (isNumeric(T) && !isComplex(T)){
28+
where isNumeric(T) && !isComplex(T) {
2929
if D.size < 2 then return true;
3030
const h: [0..<D.size - 1] real = diff(x);
3131
return (&& reduce (h > 0)) || (&& reduce (h < 0));
@@ -44,7 +44,7 @@ module Array {
4444
*/
4545
proc linspace(in start: ?T, in end: T, in num: int,
4646
in endpoint: bool=true): [0..<num] T
47-
where (isNumeric(T) && !isIntegral(T)){
47+
where isNumeric(T) && !isIntegral(T) {
4848
var arr: [0..<num] T;
4949
const divisor: int = if endpoint && num > 1 then num - 1 else num;
5050
const increment: T = (end - start) / divisor;

src/SciChap/Integration.chpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ module Integration {
7171
where D.rank == 1 {
7272
if x.size < 3 {
7373
return trapezoid(y=y, x=x);
74-
}
75-
else {
74+
} else {
7675
if !Array.isMonotonic(x) {
7776
throw new owned Error("Domain not strictly increasing or decreasing.");
7877
}

test/ArrayTest.chpl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ module ArrayTest {
1010
test.assertEqual(Array.diff([-12.0, 3.0, 7.0, 5.0, -60.1]),
1111
[15.0, 4.0, -2.0, -65.1]);
1212
}
13-
proc diff_int(test: borrowed Test) throws{
13+
proc diff_int(test: borrowed Test) throws {
1414
test.assertEqual(Array.diff([1, 3, -9]), [2, -12]);
1515
}
16-
proc diff_complex(test: borrowed Test) throws{
16+
proc diff_complex(test: borrowed Test) throws {
1717
test.assertEqual(Array.diff([1+2i, 3+5i]), [2+3i]);
1818
}
19-
proc diff_len2(test: borrowed Test) throws{
19+
proc diff_len2(test: borrowed Test) throws {
2020
test.assertEqual(Array.diff([1.0, 3.0]), [2.0]);
2121
}
22-
proc diff_len1(test: borrowed Test) throws{
22+
proc diff_len1(test: borrowed Test) throws {
2323
var empty: [1..0] real;
2424
test.assertEqual(Array.diff([1.0]), empty);
2525
}
@@ -47,39 +47,39 @@ module ArrayTest {
4747
var start = 0.0;
4848
var end = 5.0;
4949
var num = 6;
50-
test.assertEqual(Array.linspace(start, end, num),
50+
test.assertClose(Array.linspace(start, end, num),
5151
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]);
52-
test.assertEqual(Array.linspace(start, end, num, endpoint=false),
52+
test.assertClose(Array.linspace(start, end, num, endpoint=false),
5353
[0.0, 5.0/6, 5.0/3, 2.5, 10.0/3, 25.0/6]);
5454
}
5555
proc linspace_decreasing(test: borrowed Test) throws {
56-
var atol: real = 0.0;
57-
var rtol: real = 1e-15;
5856
var start = 6.0;
5957
var end = -2.0;
6058
var num = 8;
61-
var expectNoEnd = [6.0,34.0/7, 26.0/7, 18.0/7, 10.0/7, 2.0/7, -6.0/7, -2.0];
62-
test.assertLessThan(abs(Array.linspace(start, end, num) - expectNoEnd),
63-
atol + rtol*(expectNoEnd));
64-
test.assertEqual(Array.linspace(start, end, num, endpoint=false),
59+
var expectNoEnd = [
60+
6.0, 34.0/7, 26.0/7, 18.0/7, 10.0/7, 2.0/7, -6.0/7, -2.0
61+
];
62+
test.assertClose(Array.linspace(start, end, num), expectNoEnd,
63+
relTol=1e-12);
64+
test.assertClose(Array.linspace(start, end, num, endpoint=false),
6565
[6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0, -1.0]);
6666
}
6767
proc linspace_complex(test: borrowed Test) throws {
68-
test.assertEqual(Array.linspace(-3.0+0i, 3.0+2i, 3),
68+
test.assertClose(Array.linspace(-3.0+0i, 3.0+2i, 3),
6969
[-3.0+0i, 0.0+1i, 3.0+2i]);
70-
test.assertEqual(Array.linspace(-3.0+0i, 3.0+2i, 3, endpoint=false),
70+
test.assertClose(Array.linspace(-3.0+0i, 3.0+2i, 3, endpoint=false),
7171
[-3.0+0i, -1.0+2.0i/3, 1.0+4.0i/3]);
7272
}
7373

7474
proc linspace_len2(test: borrowed Test) throws {
75-
test.assertEqual(Array.linspace(-16.0, -32.0, 2), [-16.0, -32.0]);
76-
test.assertEqual(Array.linspace(-16.0, -32.0, 2, endpoint=false),
75+
test.assertClose(Array.linspace(-16.0, -32.0, 2), [-16.0, -32.0]);
76+
test.assertClose(Array.linspace(-16.0, -32.0, 2, endpoint=false),
7777
[-16.0, -24.0]);
7878
}
7979

8080
proc linspace_len1(test: borrowed Test) throws {
81-
test.assertEqual(Array.linspace(-16.0, -32.0, 1), [-16.0]);
82-
test.assertEqual(Array.linspace(-16.0, -32.0, 1, endpoint=false), [-16.0]);
81+
test.assertClose(Array.linspace(-16.0, -32.0, 1), [-16.0]);
82+
test.assertClose(Array.linspace(-16.0, -32.0, 1, endpoint=false), [-16.0]);
8383
}
8484

8585
proc empty_1(test: borrowed Test) throws {

test/IntegrationTest.chpl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,28 @@ module IntegrationTest {
1919
var dom: domain(1) = {0..<5};
2020
var x: [dom] real = [0, 1, 2, 3, 4];
2121
var y: [dom] real = [0, 3, 6, 9, 12];
22-
test.assertEqual(Integration.trapezoid(y, x), 24.0);
22+
test.assertClose(Integration.trapezoid(y, x), 24.0, relTol=1e-15);
2323
}
2424

2525
proc trapezoid_cos(test: borrowed Test) throws {
2626
var dom: domain(1) = {0..<4};
2727
var x: [dom] real = [0.0, 0.3, 0.6, 0.95];
2828
var y: [dom] real = cos(x);
29-
var actual = Integration.trapezoid(y, x);
30-
var expected = 0.8066295622395069;
31-
var atol: real = 0.0;
32-
var rtol: real = 1e-15;
33-
test.assertLessThan(abs(actual - expected), atol + rtol*(expected));
29+
test.assertClose(Integration.trapezoid(y, x), 0.8066295622395069,
30+
relTol=1e-15);
3431
}
3532

3633
proc simpson_linearOdd(test: borrowed Test) throws {
3734
var dom: domain(1) = {0..5};
3835
var x: [dom] real = [1, 2, 3, 4, 5, 6];
3936
var y: [dom] real = [2, 4, 6, 8, 10, 12];
40-
test.assertEqual(Integration.simpson(y=y, x=x), 35.0);
37+
test.assertClose(Integration.simpson(y=y, x=x), 35.0, relTol=1e-15);
4138
}
4239
proc simpson_linearEven(test: borrowed Test) throws {
4340
var dom: domain(1) = {0..6};
4441
var x: [dom] real = [1, 2, 3, 4, 5, 6, 8];
4542
var y: [dom] real = [2, 4, 6, 8, 10, 12, 16];
46-
test.assertEqual(Integration.simpson(y=y, x=x), 63.0);
43+
test.assertClose(Integration.simpson(y=y, x=x), 63.0, relTol=1e-15);
4744
}
4845
proc simpson_quadraticEven(test: borrowed Test) throws {
4946
var n: int = 400;
@@ -56,9 +53,7 @@ module IntegrationTest {
5653
}
5754
var actual: real = Integration.simpson(y=y, x=x);
5855
var expected: real = 1.0/3.0 * dom.last**3 + 3 * dom.last;
59-
var atol: real = 0.0;
60-
var rtol: real = 1e-15;
61-
test.assertLessThan(abs(actual - expected), atol + rtol*(expected));
56+
test.assertClose(actual, expected, relTol=1e-15);
6257
}
6358
proc simpson_cubicOdd(test: borrowed Test) throws {
6459
var n: int = 525;
@@ -74,7 +69,7 @@ module IntegrationTest {
7469
var expected: real = 1.0/4.0 * xN**4 + 5.0/3.0 * xN**3 + 6.0 * xN;
7570
var atol: real = 0.0;
7671
var rtol: real = 1e-15;
77-
test.assertLessThan(abs(actual - expected), atol + rtol*(expected));
72+
test.assertClose(actual, expected, relTol=1e-15);
7873
}
7974

8075
proc main() throws {

test/KdTreeModTest.chpl

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ module KdTreeModTest {
55
use UnitTest;
66
import SciChap.Spatial;
77

8-
/*
9-
Determine if 2 1D arrays are equal, with NaN meaning they are.
10-
*/
11-
proc assertEqualsNanArray(const ref actual: [?D] real,
12-
const ref expected: [D] real): bool
13-
where D.rank == 1 {
14-
var equals: bool = true;
15-
for i in D {
16-
if isNan(expected[i]) {
17-
equals &&= isNan(actual[i]);
18-
} else {
19-
equals &&= actual[i] == expected[i];
20-
}
21-
}
22-
return equals;
23-
}
24-
258
proc init_simple(test: borrowed Test) throws {
269
var x: [{5..6, 11..12}] real = [1.0, 2.0; 3.0, 4.0];
2710
var tree : Spatial.KdTree = new owned Spatial.KdTree(x);
@@ -32,10 +15,12 @@ module KdTreeModTest {
3215

3316
var expectedDom = {0..#10*x.shape[tree.ptsAxis]};
3417
test.assertEqual(tree.nodesDom, expectedDom);
18+
3519
var en: real = tree.emptyNodeVal;
3620
var expectedNodeArr: [expectedDom] real = en;
3721
expectedNodeArr[0] = 2.0;
38-
test.assertTrue(assertEqualsNanArray(tree.nodes, expectedNodeArr));
22+
test.assertClose(tree.nodes, expectedNodeArr, relTol=1e-15);
23+
3924
var ea: int = tree.emptyAxisVal;
4025
var expectedAxisArr: [expectedDom] int = ea;
4126
expectedAxisArr[0] = 0;
@@ -84,7 +69,7 @@ module KdTreeModTest {
8469
var (indices, distances) = tree.query(queryPoint);
8570
var expectedDist = dist2query(x[queryIdx, ..], queryPoint);
8671
test.assertEqual(indices[0], queryIdx);
87-
test.assertEqual(distances[0], expectedDist);
72+
test.assertClose(distances[0], expectedDist, relTol=1e-15);
8873
}
8974
}
9075

@@ -100,7 +85,7 @@ module KdTreeModTest {
10085
test.assertEqual(indices, [2, 3, 0, 4, 1]);
10186
var expectDists = dist2query(x, queryPoint);
10287
sort(expectDists);
103-
test.assertEqual(distances, expectDists);
88+
test.assertClose(distances, expectDists, relTol=1e-15);
10489
}
10590

10691
proc query_nnearestTooBig(test: borrowed Test) throws {
@@ -111,7 +96,7 @@ module KdTreeModTest {
11196
test.assertEqual(indices.size, 1);
11297
test.assertEqual(indices[0], 0);
11398
var expectedDist = dist2query(x[0, ..], queryPoint);
114-
test.assertEqual(distances[0], expectedDist);
99+
test.assertClose(distances[0], expectedDist, relTol=1e-15);
115100
}
116101

117102
proc query2D(test: borrowed Test) throws {
@@ -131,7 +116,7 @@ module KdTreeModTest {
131116
test.assertEqual(indices, [4, 2, 3, 6, 5, 0, 1, 7]);
132117
var expectDists = dist2query(x, queryPoint);
133118
sort(expectDists);
134-
test.assertEqual(distances, expectDists);
119+
test.assertClose(distances, expectDists, relTol=1e-15);
135120
}
136121

137122
proc query1D(test: borrowed Test) throws {
@@ -150,7 +135,7 @@ module KdTreeModTest {
150135
test.assertEqual(indices, [3, 2, 5, 4, 0, 1, 6]);
151136
var expectDists = dist2query(x, queryPoint);
152137
sort(expectDists);
153-
test.assertEqual(distances, expectDists);
138+
test.assertClose(distances, expectDists, relTol=1e-15);
154139
}
155140

156141
proc queryBallPoint(test: borrowed Test) throws {
@@ -170,9 +155,10 @@ module KdTreeModTest {
170155
var queryPoint = [0.0, 0.0];
171156
var (indices, distances) = tree.queryBallPoint(queryPoint, radius=1);
172157
test.assertEqual(indices, [6, 4, 5, 8, 7]);
173-
var expectDists = dist2query(x, queryPoint);
174-
sort(expectDists);
175-
test.assertEqual(distances, expectDists[0..#5]);
158+
var allDists = dist2query(x, queryPoint);
159+
sort(allDists);
160+
var expectedDists = allDists[0..#5];
161+
test.assertClose(distances, expectedDists, relTol=1e-15);
176162
}
177163

178164
proc splitMidpointMaxSpread_subdomain(test: borrowed Test) throws {

test/RootTest.chpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ module RootTest {
1111

1212
proc bisect_polyOdd(test: borrowed Test) throws {
1313
var func = proc(in x: real): real {return x**3 - x**5;};
14-
test.assertEqual(Root.bisect(func, -0.5, 0.5), 0.0);
15-
test.assertEqual(Root.bisect(func, 2.5, 0.8, 1e-200), 1.0);
16-
test.assertEqual(Root.bisect(func, -2.5, -0.8, 1e-200), -1.0);
14+
test.assertClose(Root.bisect(func, -0.5, 0.5), 0.0);
15+
test.assertClose(Root.bisect(func, 2.5, 0.8), 1.0);
16+
test.assertClose(Root.bisect(func, -2.5, -0.8), -1.0);
1717
}
1818
proc bisect_DoubleRoot(test: borrowed Test) throws {
1919
var func = proc(in x: real): real {return (x-2)**2 * (-2*x+5);};
20-
test.assertEqual(Root.bisect(func, 1.8, 2.51, 1e-50), 2.5);
20+
test.assertClose(Root.bisect(func, 1.8, 2.51), 2.5);
2121
var funcPrime = proc(in x: real): real {
2222
return 2*(x-2)*(-2*x+5) - 2*(x-2)**2;
2323
};
2424
// to find double root, run bisection on derivative
25-
test.assertEqual(Root.bisect(funcPrime, 0.0, 2.2, 1e-50), 2.0);
25+
test.assertClose(Root.bisect(funcPrime, 0.0, 2.2), 2.0);
2626
}
2727

2828
proc main() throws {

0 commit comments

Comments
 (0)