Skip to content

Commit c98008d

Browse files
committed
swap in new allClose function
1 parent 08e7aa7 commit c98008d

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

eidos/eidos_test_builtins.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ for (iter in 1:100)
111111
xbuiltin = cumProduct(x);
112112
xuserdef = cumProduct_func(x);
113113
// tolerance because product() can get a little roundoff error due to SIMD
114-
if (!all(abs(xbuiltin - xuserdef) < abs(xuserdef) * 1e-10 + 1e-15)) stop('Mismatch in test of cumProduct(f)');
114+
if (!allClose(xbuiltin, xuserdef)) stop('Mismatch in test of cumProduct(f)');
115115
}
116116

117117
// ***********************************************************************************************
@@ -136,7 +136,7 @@ for (iter in 1:100)
136136
xbuiltin = cumSum(x);
137137
xuserdef = cumSum_func(x);
138138
// tolerance because sum() can get a little roundoff error due to SIMD
139-
if (!all(abs(xbuiltin - xuserdef) < 1e-10)) stop('Mismatch in test of cumSum(f)');
139+
if (!allClose(xbuiltin, xuserdef)) stop('Mismatch in test of cumSum(f)');
140140
}
141141

142142
// ***********************************************************************************************
@@ -272,7 +272,7 @@ for (iter in 1:100)
272272
xbuiltin = mean(x);
273273
xuserdef = mean_func(x);
274274
// tolerance because sum() can get a little roundoff error due to SIMD
275-
if (!all(abs(xbuiltin - xuserdef) < 1e-10)) stop('Mismatch in test of mean(f)');
275+
if (!allClose(xbuiltin, xuserdef)) stop('Mismatch in test of mean(f)');
276276
}
277277

278278
// ***********************************************************************************************
@@ -420,7 +420,7 @@ for (iter in 1:100)
420420
xbuiltin = product(x);
421421
xuserdef = product_func(x);
422422
// tolerance because product() can get a little roundoff error due to SIMD
423-
if (abs(xbuiltin - xuserdef) > abs(xuserdef) * 1e-10 + 1e-15) stop('Mismatch in test of product(f)');
423+
if (!allClose(xbuiltin, xuserdef)) stop('Mismatch in test of product(f)');
424424
}
425425

426426
// ***********************************************************************************************
@@ -795,7 +795,7 @@ for (iter in 1:100)
795795
xbuiltin = sum(x);
796796
xuserdef = sum_func(x);
797797
// tolerance because sum() can get a little roundoff error due to SIMD
798-
if (!all(abs(xbuiltin - xuserdef) < 1e-10)) stop('Mismatch in test of sum(f)');
798+
if (!allClose(xbuiltin, xuserdef)) stop('Mismatch in test of sum(f)');
799799
}
800800

801801
// ***********************************************************************************************

eidos/eidos_test_functions_other.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void _RunFunctionMatrixArrayTests(void)
350350
EidosAssertScriptSuccess_I("tr(matrix(1:9, ncol=3));", 1 + 5 + 9);
351351
EidosAssertScriptSuccess_F("tr(matrix(1.0:9, ncol=3));", 1 + 5 + 9);
352352
EidosAssertScriptSuccess_F("tr(matrix(c(1.25, -7.8, 3.4, 6.1, 4.75, 8.2, -0.3, 8.6, -1.5), ncol=3));", 1.25 + 4.75 + -1.5);
353-
EidosAssertScriptSuccess_L("x = matrix(runif(100), ncol=10); abs(tr(x) - sum(diag(x))) < 1e-10;", true); // tolerance for SIMD
353+
EidosAssertScriptSuccess_L("x = matrix(runif(100), ncol=10); allClose(tr(x), sum(diag(x)));", true); // tolerance for SIMD
354354
EidosAssertScriptSuccess_L("x = matrix(rdunif(100, -1000, 1000), ncol=10); identical(tr(x), sum(diag(x)));", true);
355355

356356
// upperTri()
@@ -377,15 +377,15 @@ void _RunFunctionMatrixArrayTests(void)
377377
EidosAssertScriptSuccess_L("x = 1.0:12; y = matrix(x, nrow=3); identical(rowSums(y), c(22.0, 26, 30));", true);
378378
EidosAssertScriptSuccess_L("x = (rbinom(100, 1, 0.4) == 1); y = matrix(x, nrow=10); identical(rowSums(y), apply(y, 0, 'sum(applyValue);'));", true);
379379
EidosAssertScriptSuccess_L("x = rdunif(100, -1000, 1000); y = matrix(x, nrow=10); identical(rowSums(y), apply(y, 0, 'sum(applyValue);'));", true);
380-
EidosAssertScriptSuccess_L("x = runif(100); y = matrix(x, nrow=10); all(abs(rowSums(y) - apply(y, 0, 'sum(applyValue);')) < 1e-10);", true); // tolerance for SIMD
380+
EidosAssertScriptSuccess_L("x = runif(100); y = matrix(x, nrow=10); allClose(rowSums(y), apply(y, 0, 'sum(applyValue);'));", true); // tolerance for SIMD
381381

382382
// colSums()
383383
EidosAssertScriptSuccess_L("x = c(T,T,F,F,T,F,F,T,T,F,F,T); y = matrix(x, nrow=3); identical(colSums(y), c(2, 1, 2, 1));", true);
384384
EidosAssertScriptSuccess_L("x = 1:12; y = matrix(x, nrow=3); identical(colSums(y), c(6, 15, 24, 33));", true);
385385
EidosAssertScriptSuccess_L("x = 1.0:12; y = matrix(x, nrow=3); identical(colSums(y), c(6.0, 15, 24, 33));", true);
386386
EidosAssertScriptSuccess_L("x = (rbinom(100, 1, 0.4) == 1); y = matrix(x, nrow=10); identical(colSums(y), apply(y, 1, 'sum(applyValue);'));", true);
387387
EidosAssertScriptSuccess_L("x = rdunif(100, -1000, 1000); y = matrix(x, nrow=10); identical(colSums(y), apply(y, 1, 'sum(applyValue);'));", true);
388-
EidosAssertScriptSuccess_L("x = runif(100); y = matrix(x, nrow=10); all(abs(colSums(y) - apply(y, 1, 'sum(applyValue);')) < 1e-10);", true); // tolerance for SIMD
388+
EidosAssertScriptSuccess_L("x = runif(100); y = matrix(x, nrow=10); allClose(colSums(y), apply(y, 1, 'sum(applyValue);'));", true); // tolerance for SIMD
389389
}
390390

391391
#pragma mark filesystem access

0 commit comments

Comments
 (0)