Skip to content

Commit ad27831

Browse files
committed
feat: update the JS implementation
--- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 2ebec87 commit ad27831

File tree

4 files changed

+108
-131
lines changed

4 files changed

+108
-131
lines changed

Diff for: lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hyp2f1ra.js

-125
This file was deleted.

Diff for: lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hys2f1.js

+99-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
var isNonPositiveInteger = require( '@stdlib/math/base/assert/is-nonpositive-integer' );
2424
var PINF = require( '@stdlib/constants/float64/pinf' );
25+
var round = require( '@stdlib/math/base/special/round' );
2526
var abs = require( '@stdlib/math/base/special/abs' );
26-
var hyp2f1ra = require( './hyp2f1ra.js' );
2727

2828

2929
// VARIABLES //
@@ -32,6 +32,96 @@ var EPS = 1.0e-13;
3232
var MAX_ITERATIONS = 10000;
3333

3434

35+
// FUNCTIONS //
36+
37+
/**
38+
* Evaluates the Gaussian hypergeometric function by two-term recurrence in `a`.
39+
*
40+
* @private
41+
* @param {number} a - input value
42+
* @param {number} b - input value
43+
* @param {number} c - input value
44+
* @param {number} x - input value
45+
* @param {number} loss - starting loss of significance
46+
* @returns {Object} the function value and error
47+
*
48+
*/
49+
function hyp2f1ra( a, b, c, x, loss ) {
50+
var f2Val;
51+
var f1Val;
52+
var f0Val;
53+
var err;
54+
var da;
55+
var f1;
56+
var f0;
57+
var t;
58+
var n;
59+
60+
loss = 0.0;
61+
err = 0.0;
62+
63+
if ( ( c < 0 && a <= c ) || ( c >= 0 && a >= c ) ) {
64+
da = round( a - c );
65+
}
66+
else {
67+
da = round( a );
68+
}
69+
70+
t = a - da;
71+
if ( abs( da ) > MAX_ITERATIONS ) {
72+
loss = 1.0;
73+
return {
74+
'value': NaN,
75+
'error': loss
76+
};
77+
}
78+
79+
if ( da < 0 ) {
80+
f2Val = 0;
81+
f1 = hys2f1( t, b, c, x, err );
82+
loss += f1.error;
83+
err = f1.error;
84+
f0 = hys2f1( t - 1, b, c, x, err );
85+
loss += f0.error;
86+
t -= 1;
87+
f1Val = f1.value;
88+
f0Val = f0.value;
89+
for ( n = 1; n < -da; ++n ) {
90+
f2Val = f1Val;
91+
f1Val = f0Val;
92+
93+
// eslint-disable-next-line max-len
94+
f0Val = -(((((2 * t) - c) - (t * x) + (b * x)) * f1Val) + ((t * (x - 1)) * f2Val)) / (c - t);
95+
t -= 1;
96+
}
97+
}
98+
else {
99+
f2Val = 0;
100+
f1 = hys2f1( t, b, c, x, err );
101+
loss += f1.error;
102+
err = f1.error;
103+
f0 = hys2f1( t + 1, b, c, x, err ); // CHECK IF err is THE SAME OR NEW ONE
104+
loss += f0.error;
105+
t += 1;
106+
f1Val = f1.value;
107+
f0Val = f0.value;
108+
for ( n = 1; n < da; ++n ) {
109+
f2Val = f1Val;
110+
f1Val = f0Val;
111+
112+
// eslint-disable-next-line max-len
113+
f0Val = -(((((2 * t) - c) - (t * x) + (b * x)) * f1Val) + ((c - t) * f2Val)) / (t * (x - 1));
114+
t += 1;
115+
}
116+
}
117+
118+
return {
119+
'value': f0Val,
120+
'error': loss
121+
};
122+
}
123+
124+
35125
// MAIN //
36126

37127
/**
@@ -90,7 +180,10 @@ function hys2f1( a, b, c, x, loss ) {
90180
do {
91181
if ( abs( h ) < EPS ) {
92182
loss = 1.0;
93-
return PINF;
183+
return {
184+
'value': PINF,
185+
'error': loss
186+
};
94187
}
95188
m = k + 1.0;
96189
u *= ( ( f + k ) * ( g + k ) * x / ( ( h + k ) * m ) );
@@ -103,7 +196,10 @@ function hys2f1( a, b, c, x, loss ) {
103196
i += 1;
104197
if ( i > MAX_ITERATIONS ) {
105198
loss = 1.0;
106-
return s;
199+
return {
200+
'value': s,
201+
'error': loss
202+
};
107203
}
108204
} while ( s === 0 || abs( u / s ) > EPS );
109205

Diff for: lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hyt2f1.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
2424
var pow = require( '@stdlib/math/base/special/pow' );
2525
var max = require( '@stdlib/math/base/special/max' );
2626
var exp = require( '@stdlib/math/base/special/exp' );
27-
var log = require( '@stdlib/math/base/special/log' );
27+
var ln = require( '@stdlib/math/base/special/ln' );
2828
var round = require( '@stdlib/math/base/special/round' );
2929
var gamma = require( '@stdlib/math/base/special/gamma' );
3030
var gammaln = require( '@stdlib/math/base/special/gammaln' );
@@ -94,7 +94,7 @@ function hyt2f1(a, b, c, x, loss) {
9494
val = pow( s, -a ) * y.value;
9595
}
9696
else {
97-
y = hys2f1( a, c - b, c, -x / s, err );
97+
y = hys2f1( c - a, b, c, -x / s, err );
9898
val = pow( s, -b ) * y.value;
9999
}
100100
loss = y.error;
@@ -155,7 +155,7 @@ function hyt2f1(a, b, c, x, loss) {
155155
d2 = d;
156156
aid = -id;
157157
}
158-
ax = log( s );
158+
ax = ln( s );
159159

160160
// eslint-disable-next-line max-len
161161
y = digamma( 1.0 ) + digamma( 1.0 + e ) - digamma( a + d1 ) - digamma( b + d1 ) - ax;

Diff for: lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function hyp2f1( a, b, c, x ) {
8181
ia = round( a );
8282
ib = round( b );
8383
id = round( d );
84+
ic = round( c );
8485
s = 1.0 - x;
8586
d = c - a - b;
8687
negIntA = isNonPositiveInteger( a );
@@ -179,6 +180,7 @@ function hyp2f1( a, b, c, x ) {
179180
if ( y.error < ETHRESH ) {
180181
return y.value;
181182
}
183+
y = y.value;
182184
err = 0.0;
183185
aid = 2 - id;
184186
e = c + aid;
@@ -201,6 +203,10 @@ function hyp2f1( a, b, c, x ) {
201203
y = hys2f1( c - a, c - b, c, x, err );
202204
return pow( s, d ) * y.value;
203205
}
206+
207+
// IS IT NECESSARY TO HAVE THIS CONDITION?
208+
y = hyt2f1(a, b, c, x, err);
209+
return y.value;
204210
}
205211

206212

0 commit comments

Comments
 (0)