Skip to content

Commit 3a246bd

Browse files
chore: use mpmath for non-integer n
--- 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: missing_dependencies - 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 74d2441 commit 3a246bd

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

lib/node_modules/@stdlib/math/base/special/legendre-polynomial/test/fixtures/python/decimals.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/legendre-polynomial/test/fixtures/python/runner.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import json
2323
import numpy as np
24+
from mpmath import mp, legendre as mp_legendre
2425
from scipy.special import eval_legendre
2526

2627
# Get the file path:
@@ -64,6 +65,33 @@ def gen(n, x, name):
6465
outfile.write("\n")
6566

6667

68+
def gen_mp(n, x, name):
69+
"""Generate fixture data using mpmath and write to file.
70+
71+
# Arguments
72+
73+
* `n`: degree
74+
* `x`: evaluation point
75+
* `name::str`: output filename
76+
"""
77+
mp.dps = 35
78+
y = [float(mp_legendre(ni, xi)) for ni, xi in zip(n, x)]
79+
y = ["PINF" if np.isposinf(val) else "NINF" if np.isneginf(val) else val for val in y]
80+
data = {
81+
"n": n.tolist(),
82+
"x": x.tolist(),
83+
"expected": y,
84+
}
85+
86+
# Based on the script directory, create an output filepath:
87+
filepath = os.path.join(DIR, name)
88+
89+
# Write the data to the output filepath as JSON:
90+
with open(filepath, "w", encoding="utf-8") as outfile:
91+
json.dump(data, outfile)
92+
outfile.write("\n")
93+
94+
6795
def main():
6896
"""Generate fixture data."""
6997
# Integer degrees, x in [-1, 1]:
@@ -76,7 +104,7 @@ def main():
76104
n = 1000
77105
n_vals = np.linspace(-20.0, 20.0, n)
78106
x = np.linspace(-1.0, 1.0, n)
79-
gen(n_vals, x, "decimals.json")
107+
gen_mp(n_vals, x, "decimals.json")
80108

81109
# Large integer degrees, x in [-1, 1]:
82110
n = 500

lib/node_modules/@stdlib/math/base/special/legendre-polynomial/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ tape( 'the function correctly evaluates the Legendre polynomial', function test(
156156
t.strictEqual( v, NINF, 'returns expected value' );
157157
continue;
158158
}
159-
t.strictEqual( isAlmostSameValue( v, expected[ i ], 2.1e12 ), true, 'returns expected value' );
159+
t.strictEqual( isAlmostSameValue( v, expected[ i ], 5e9 ), true, 'returns expected value' );
160160
}
161161
t.end();
162162
});

0 commit comments

Comments
 (0)