Skip to content

Commit 5031684

Browse files
chore: use absf inplace of abs & add a test
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 75a21c0 commit 5031684

4 files changed

Lines changed: 72 additions & 13 deletions

File tree

lib/node_modules/@stdlib/math/base/special/digammaf/test/fixtures/julia/runner.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@ gen( x, "near_integers.json" );
9090
# Generate fixture data for half-integer values (exact):
9191
x = range( -0.5f0, step = -1.0f0, length = 100 );
9292
gen( x, "half_integers.json" );
93+
94+
# Generate fixture for very large positie values:
95+
x = Float32[ 1.0e8, 5.0e8, 1.0e9, 1.0e10, 1.0e20 ];
96+
gen( x, "very_large_positive.json" );
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"expected":[18.420681,20.030119,20.723267,23.02585,46.0517],"x":[1.0e8,5.0e8,1.0e9,1.0e10,1.0e20]}

lib/node_modules/@stdlib/math/base/special/digammaf/test/test.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
25+
var absf = require( '@stdlib/math/base/special/absf' );
2626
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
2828
var digammaf = require( './../lib' );
@@ -36,6 +36,7 @@ var largePositive = require( './fixtures/julia/large_positive.json' );
3636
var negative = require( './fixtures/julia/negative.json' );
3737
var nearIntegers = require( './fixtures/julia/near_integers.json' );
3838
var halfIntegers = require( './fixtures/julia/half_integers.json' );
39+
var veryLargePositive = require( './fixtures/julia/very_large_positive.json' );
3940

4041

4142
// TESTS //
@@ -87,8 +88,8 @@ tape('the function evaluates the digamma function (half-integers)', function tes
8788
if (y === e) {
8889
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
8990
} else {
90-
delta = abs(y - e);
91-
tol = 150.0 * EPS * abs(e);
91+
delta = absf(y - e);
92+
tol = 150.0 * EPS * absf(e);
9293
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
9394
}
9495
}
@@ -113,8 +114,8 @@ tape('the function computes the digamma function (positive values)', function te
113114
if (y === e) {
114115
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
115116
} else {
116-
delta = abs(y - e);
117-
tol = 350.0 * EPS * abs(e);
117+
delta = absf(y - e);
118+
tol = 350.0 * EPS * absf(e);
118119
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
119120
}
120121
}
@@ -139,8 +140,8 @@ tape('the function computes the digamma function (small positive values)', funct
139140
if (y === e) {
140141
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
141142
} else {
142-
delta = abs(y - e);
143-
tol = 500.0 * EPS * abs(e);
143+
delta = absf(y - e);
144+
tol = 500.0 * EPS * absf(e);
144145
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
145146
}
146147
}
@@ -165,8 +166,8 @@ tape('the function computes the digamma function (large positive values)', funct
165166
if (y === e) {
166167
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
167168
} else {
168-
delta = abs(y - e);
169-
tol = 100.0 * EPS * abs(e);
169+
delta = absf(y - e);
170+
tol = 100.0 * EPS * absf(e);
170171
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
171172
}
172173
}
@@ -191,8 +192,8 @@ tape('the function computes the digamma function (negative values)', function te
191192
if (y === e) {
192193
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
193194
} else {
194-
delta = abs(y - e);
195-
tol = 500.0 * EPS * abs(e);
195+
delta = absf(y - e);
196+
tol = 500.0 * EPS * absf(e);
196197
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
197198
}
198199
}
@@ -217,8 +218,34 @@ tape('the function computes the digamma function (near integers)', function test
217218
if (y === e) {
218219
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
219220
} else {
220-
delta = abs(y - e);
221-
tol = 300.0 * EPS * abs(e);
221+
delta = absf(y - e);
222+
tol = 300.0 * EPS * absf(e);
223+
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
224+
}
225+
}
226+
t.end();
227+
});
228+
229+
tape('the function evaluates the digamma function (very large values)', function test(t) {
230+
var expected;
231+
var delta;
232+
var tol;
233+
var x;
234+
var y;
235+
var i;
236+
var e;
237+
238+
x = veryLargePositive.x;
239+
expected = veryLargePositive.expected;
240+
241+
for (i = 0; i < x.length; i++) {
242+
y = digammaf(x[i]);
243+
e = float64ToFloat32(expected[i]);
244+
if (y === e) {
245+
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
246+
} else {
247+
delta = absf(y - e);
248+
tol = 10.0 * EPS * absf(e);
222249
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
223250
}
224251
}

lib/node_modules/@stdlib/math/base/special/digammaf/test/test.native.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var largePositive = require( './fixtures/julia/large_positive.json' );
4444
var negative = require( './fixtures/julia/negative.json' );
4545
var nearIntegers = require( './fixtures/julia/near_integers.json' );
4646
var halfIntegers = require( './fixtures/julia/half_integers.json' );
47+
var veryLargePositive = require( './fixtures/julia/very_large_positive.json' );
4748

4849

4950
// TESTS //
@@ -232,3 +233,29 @@ tape('the function computes the digamma function (near integers)', opts, functio
232233
}
233234
t.end();
234235
});
236+
237+
tape('the function evaluates the digamma function (very large values)', opts, function test(t) {
238+
var expected;
239+
var delta;
240+
var tol;
241+
var x;
242+
var y;
243+
var i;
244+
var e;
245+
246+
x = veryLargePositive.x;
247+
expected = veryLargePositive.expected;
248+
249+
for (i = 0; i < x.length; i++) {
250+
y = digammaf(x[i]);
251+
e = expected[i];
252+
if (y === e) {
253+
t.strictEqual(y, e, 'x: ' + x[i] + '. E: ' + e);
254+
} else {
255+
delta = absf(y - e);
256+
tol = 10.0 * EPS * absf(e);
257+
t.ok(delta <= tol, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + e + '. tol: ' + tol + '. Δ: ' + delta + '.');
258+
}
259+
}
260+
t.end();
261+
});

0 commit comments

Comments
 (0)