diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/LICENSE b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/LICENSE new file mode 100644 index 000000000000..3e825d2f4fbe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/LICENSE @@ -0,0 +1,196 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +DEPENDENCIES & ATTRIBUTION + +The library links against the following external libraries or contains +implementations from the following external libraries, which have their own +licenses: + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/README.md b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/README.md new file mode 100644 index 000000000000..7ea6e93a803a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/README.md @@ -0,0 +1,148 @@ + + +# Chebyshev Series + +> Evaluate a [Chebyshev series][chebyshev-series] using double-precision floating-point arithmetic. + +
+ +A [Chebyshev series][chebyshev-series] in a variable `x` can be expressed as + + + +```math +\sum_{i=0}^{n} c_i T_i(x/2) +``` + + + + + +where `c_n, c_{n-1}, ..., c_0` are constants and `T_i` are Chebyshev polynomials of the first kind. + +
+ + + +
+ +## Usage + +```javascript +var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' ); +``` + +#### chebyshevSeries( x, c ) + +Evaluates a [Chebyshev series][chebyshev-series] having coefficients `c` at a value `x`. + +```javascript +var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); +// returns 0.75 +``` + +The function evaluates Chebyshev polynomials at `x/2`. + +#### chebyshevSeries.factory( c ) + +Uses code generation to in-line coefficients and return a function for evaluating a [Chebyshev series][chebyshev-series] using double-precision floating-point arithmetic. + +```javascript +var evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); + +// 0.5 * T_0(0.5) + 1.0 * T_1(0.5) +var v = evaluate( 1.0 ); +// returns 0.75 +``` + +The returned function evaluates Chebyshev polynomials at `x/2`. + +
+ + + +
+ +## Notes + +- The value at which to evaluate a Chebyshev series is expected to reside on the interval `[-2, 2]`. +- The coefficients `c` **must be** be ordered in **descending** degree. +- For hot code paths in which coefficients are invariant, a compiled function will be more performant than `chebyshevSeries()`. +- While code generation can boost performance, its use may be problematic in browser contexts enforcing a strict [content security policy][mdn-csp] (CSP). If running in or targeting an environment with a CSP, avoid using code generation. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' ); + +// Create an array of random coefficients: +var coef = discreteUniform( 10, -100, 100 ); + +// Evaluate the series at random values using the direct function: +var v = uniform( 100, -2.0, 2.0 ); +var i; +for ( i = 0; i < v.length; i++ ) { + console.log( 'f(%d) = %d', v[ i ], chebyshevSeries( v[ i ], coef ) ); +} + +// Generate a chebyshev series evaluation function: +var evaluate = chebyshevSeries.factory( coef ); +var x = uniform( 100, -2.0, 2.0 ); +logEachMap( 'f(%d) = %d', x, evaluate ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.js new file mode 100644 index 000000000000..cce6d388e222 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib/factory.js' ); + + +// MAIN // + +bench( format( '%s::create:factory', pkg ), function benchmark( b ) { + var values; + var f; + var i; + + values = [ + uniform( 10, 0.0, 100.0 ), + uniform( 10, 0.0, 100.0 ), + uniform( 10, 0.0, 100.0 ) + ]; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = factory( values[ i%values.length ] ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::evaluate:factory', pkg ), function benchmark( b ) { + var values; + var v; + var f; + var i; + + f = factory( uniform( 10, 0.0, 100.0 ) ); + values = uniform( 10, -2.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = f( values[ i%values.length ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.length.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.length.js new file mode 100644 index 000000000000..bae226224dc5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.factory.length.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib/factory.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var evaluate = factory( uniform( len, 0.0, 100.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var x; + var v; + var i; + + x = uniform( 10, -2.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = evaluate( x[ i%x.length ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:factory:len=%u', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.js new file mode 100644 index 000000000000..97a44242ee14 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var chebyshevSeries = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var coefs; + var x; + var v; + var i; + + coefs = [ + uniform( 10, 0.0, 100.0 ), + uniform( 10, 0.0, 100.0 ), + uniform( 10, 0.0, 100.0 ) + ]; + x = uniform( 10, -2.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = chebyshevSeries( x[ i%x.length ], coefs[ i%coefs.length ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.length.js new file mode 100644 index 000000000000..a449fd487686 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/benchmark/benchmark.length.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var chebyshevSeries = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var c = uniform( len, 0.0, 100.0 ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var x; + var v; + var i; + + x = uniform( 10, -2.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = chebyshevSeries( x[ i%x.length ], c ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%u', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/repl.txt b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/repl.txt new file mode 100644 index 000000000000..fcedfadde21d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/repl.txt @@ -0,0 +1,55 @@ + +{{alias}}( x, c ) + Evaluates a Chebyshev series using double-precision floating-point + arithmetic. + The implementation uses Clenshaw's recurrence algorithm and follows the + convention where the constant term is halved and polynomials are evaluated + at x/2. + + Parameters + ---------- + x: number + Value at which to evaluate the Chebyshev series (expected to be in + [-2, 2]). + + c: Array + Chebyshev series coefficients ordered in descending degree. + + Returns + ------- + out: number + Evaluated Chebyshev series. + + Examples + -------- + > var c = [ 1.0, 0.5 ]; + > var v = {{alias}}( 1.0, c ) + 0.75 + + +{{alias}}.factory( c ) + Returns a function for evaluating a Chebyshev series using double-precision + floating-point arithmetic. + The returned function uses Clenshaw's recurrence algorithm and follows the + convention where the constant term is halved and polynomials are evaluated + at x/2. + + Parameters + ---------- + c: Array + Chebyshev series coefficients ordered in descending degree. + + Returns + ------- + fcn: Function + Function for evaluating a Chebyshev series. + + Examples + -------- + > var f = {{alias}}.factory( [ 1.0, 0.5 ] ); + > var v = f( 1.0 ) + 0.75 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/index.d.ts new file mode 100644 index 000000000000..2873e8324570 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Evaluates a Chebyshev series using double-precision floating-point arithmetic. +* +* @param x - value at which to evaluate a Chebyshev series +* @returns evaluated Chebyshev series +*/ +type ChebyshevSeriesFunction = ( x: number ) => number; + +/** +* Interface for evaluating Chebyshev series. +*/ +interface ChebyshevSeries { + /** + * Evaluates a Chebyshev series using double-precision floating-point arithmetic. + * + * ## Notes + * + * - The implementation uses [Clenshaw's recurrence algorithm][clenshaw]. + * - The function evaluates Chebyshev polynomials at `x/2`. + * + * [clenshaw]: https://en.wikipedia.org/wiki/Clenshaw_algorithm + * + * @param x - value at which to evaluate the Chebyshev series (expected to be in `[-2, 2]`) + * @param c - Chebyshev series coefficients ordered in descending degree + * @returns evaluated Chebyshev series + * + * @example + * var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); // 1*T_0(1/2) + 0.5*T_1(1/2) + * // returns 0.75 + */ + ( x: number, c: Collection ): number; + + /** + * Generates a function for evaluating a Chebyshev series using double-precision floating-point arithmetic. + * + * ## Notes + * + * - The compiled function uses [Clenshaw's recurrence algorithm][clenshaw]. + * - The function evaluates Chebyshev polynomials at `x/2`. + * + * [clenshaw]: https://en.wikipedia.org/wiki/Clenshaw_algorithm + * + * @param c - Chebyshev series coefficients ordered in descending degree + * @returns function for evaluating a Chebyshev series + * + * @example + * var evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); + * + * var v = evaluate( 1.0 ); + * // returns 0.75 + */ + factory( c: Collection ): ChebyshevSeriesFunction; +} + +/** +* Evaluates a Chebyshev series using double-precision floating-point arithmetic. +* +* ## Notes +* +* - The implementation uses [Clenshaw's recurrence algorithm][clenshaw]. +* - The function evaluates Chebyshev polynomials at `x/2`. +* +* [clenshaw]: https://en.wikipedia.org/wiki/Clenshaw_algorithm +* +* @param x - value at which to evaluate the Chebyshev series (expected to be in `[-2, 2]`) +* @param c - Chebyshev series coefficients ordered in descending degree +* @returns evaluated Chebyshev series +* +* @example +* var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); // 1*T_0(1/2) + 0.5*T_1(1/2) +* // returns 0.75 +* +* @example +* var evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); // 1*T_0(1/2) + 0.5*T_1(1/2) +* +* var v = evaluate( 1.0 ); +* // returns 0.75 +*/ +declare var chebyshevSeries: ChebyshevSeries; + + +// EXPORTS // + +export = chebyshevSeries; diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/test.ts new file mode 100644 index 000000000000..5e5ef91a5bbb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/docs/types/test.ts @@ -0,0 +1,103 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import chebyshevSeries = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + chebyshevSeries( '5', [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( true, [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( false, [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( null, [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( undefined, [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( [], [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( {}, [ 1.0, 2.0 ] ); // $ExpectError + chebyshevSeries( ( x: number ): number => x, [ 1.0, 2.0 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + chebyshevSeries( 1.0, '5' ); // $ExpectError + chebyshevSeries( 1.0, true ); // $ExpectError + chebyshevSeries( 1.0, false ); // $ExpectError + chebyshevSeries( 1.0, null ); // $ExpectError + chebyshevSeries( 1.0, undefined ); // $ExpectError + chebyshevSeries( 1.0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + chebyshevSeries(); // $ExpectError + chebyshevSeries( 1.0 ); // $ExpectError + chebyshevSeries( 1.0, [ 1.0, 2.0 ], 3.0 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + chebyshevSeries.factory( [ 1.0, 0.5 ] ); // $ExpectType ChebyshevSeriesFunction +} + +// The function returned by the `factory` method returns a number... +{ + const evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); + evaluate( 1.0 ); // $ExpectType number +} + +// The compiler throws an error if the `factory` method is provided an argument which is not a collection... +{ + chebyshevSeries.factory( 5 ); // $ExpectError + chebyshevSeries.factory( true ); // $ExpectError + chebyshevSeries.factory( false ); // $ExpectError + chebyshevSeries.factory( null ); // $ExpectError + chebyshevSeries.factory( undefined ); // $ExpectError + chebyshevSeries.factory( {} ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + chebyshevSeries.factory(); // $ExpectError + chebyshevSeries.factory( [ 1.0, 2.0 ], 3.0 ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an argument which is not a number... +{ + const evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); + evaluate( '5' ); // $ExpectError + evaluate( true ); // $ExpectError + evaluate( false ); // $ExpectError + evaluate( null ); // $ExpectError + evaluate( undefined ); // $ExpectError + evaluate( [] ); // $ExpectError + evaluate( {} ); // $ExpectError + evaluate( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] ); + evaluate(); // $ExpectError + evaluate( 1.0, 2.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/examples/index.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/examples/index.js new file mode 100644 index 000000000000..519b3d69cfa1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var chebyshevSeries = require( './../lib' ); + +// Create an array of random coefficients: +var coef = discreteUniform( 10, -100, 100 ); + +// Evaluate the series at random values using the direct function: +var v = uniform( 100, -2.0, 2.0 ); +var i; +console.log( 'Direct evaluation:' ); +for ( i = 0; i < v.length; i++ ) { + console.log( 'f(%d) = %d', v[ i ], chebyshevSeries( v[ i ], coef ) ); +} + +// Generate a chebyshev series evaluation function: +var evaluate = chebyshevSeries.factory( coef ); +var x = uniform( 100, -2.0, 2.0 ); +logEachMap( 'f(%d) = %d', x, evaluate ); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/factory.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/factory.js new file mode 100644 index 000000000000..9227855150e5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/factory.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Fcn = require( '@stdlib/function/ctor' ); +var chebyshevSeries = require( './main.js' ); + + +// MAIN // + +/** +* Generates a function for evaluating a Chebyshev series. +* +* ## Notes +* +* - The compiled function uses [Clenshaw's algorithm][clenshaw-algorithm] for efficient computation. +* +* [clenshaw-algorithm]: https://en.wikipedia.org/wiki/Clenshaw_algorithm +* +* @param {NumericArray} c - Chebyshev series coefficients in descending degree order +* @returns {Function} function for evaluating a Chebyshev series +* +* @example +* var polyval = factory( [ 1.0, 0.5 ] ); +* +* var v = polyval( 1.0 ); // 1*T_0(1/2) + 0.5*T_1(1/2) +* // returns 0.75 +* +* var v = polyval( 0.0 ); // 1*T_0(0) + 0.5*T_1(0) +* // returns 0.5 +*/ +function factory( c ) { + var f; + var n; + var i; + + // Use the general implementation if the number of coefficients is large: + if ( c.length > 500 ) { + return evaluate; + } + + n = c.length; + + // Code generation. Start with the function definition... + f = 'return function chebyshevSeries(x){'; + f += 'var b0;'; + f += 'var b1;'; + f += 'var b2;'; + + // If no coefficients, the function always returns zero... + if ( n === 0 ) { + f += 'return 0.0;'; + } + // If only one coefficient, the function always returns that coefficient... + else if ( n === 1 ) { + f += 'return ' + ( 0.5 * c[ 0 ] ) + ';'; + } + // If more than one coefficient, apply Clenshaw's algorithm... + else { + // Initialize: + f += 'b0 = ' + c[ 0 ] + ';'; + f += 'b1 = 0.0;'; + + // Recurrence: + for ( i = 1; i < n; i++ ) { + f += 'b2 = b1;'; + f += 'b1 = b0;'; + f += 'b0 = (x*b1) - b2 + ' + c[ i ] + ';'; + } + f += 'return 0.5 * (b0 - b2);'; + } + + // Close the function: + f += '};'; + + // Add a source directive for debugging: + f += '//# sourceURL=chebyshevSeries.factory.js'; + + // Create the function in the global scope: + return ( new Fcn( f ) )(); + + /** + * Evaluates a Chebyshev series. + * + * @private + * @param {number} x - evaluation point + * @returns {number} evaluated series + */ + function evaluate( x ) { + return chebyshevSeries( x, c ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/index.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/index.js new file mode 100644 index 000000000000..8e6fc7889931 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/index.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Evaluate a Chebyshev series using double-precision floating-point arithmetic. +* +* @module @stdlib/math/base/tools/chebyshev-series +* +* @example +* var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' ); +* +* var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); // 1*T_0(1/2) + 0.5*T_1(1/2) +* // returns 0.75 +* +* @example +* var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' ); +* +* var polyval = chebyshevSeries.factory( [ 1.0, 0.5 ] ); +* +* var v = polyval( 1.0 ); // 1*T_0(1/2) + 0.5*T_1(1/2) +* // returns 0.75 +* +* var v = polyval( 0.0 ); // 1*T_0(0) + 0.5*T_1(0) +* // returns 0.5 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/main.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/main.js new file mode 100644 index 000000000000..f83389e4bfe9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/lib/main.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* +* ## Notice +* +* The original C code, long comment, copyright, and license are from [Cephes]{@link http://www.netlib.org/cephes}. The implementation follows the original, but has been modified for JavaScript. +* +* ```text +* Copyright 1984, 1995, 2000 by Stephen L. Moshier +* +* Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee. +* +* Stephen L. Moshier +* moshier@na-net.ornl.gov +* ``` +*/ + +'use strict'; + +// MAIN // + +/** +* Evaluates a Chebyshev series. +* +* ## Notes +* +* The function evaluates +* +* ```text +* N-1 +* - ' +* y = > c[i] T (x/2) +* - i +* i=0 +* ``` +* +* of Chebyshev polynomials `Ti` at argument `x/2`. +* +* A few comments: +* +* - Coefficients must be stored in reverse order (i.e., the zero order term is last in the array). Note `N` is the number of coefficients, not the order. +* - If coefficients are for the interval `a` to `b`, `x` must have been transformed to `x` -> `2(2x - b - a)/(b-a)` before entering the routine. This maps `x` from `(a, b)` to `(-1, 1)`, over which the Chebyshev polynomials are defined. +* - If the coefficients are for the inverted interval, in which `(a, b)` is mapped to `(1/b, 1/a)`, the transformation required is `x` -> `2(2ab/x - b - a)/(b-a)`. If `b` is infinity, this becomes `x` -> `4a/x - 1`. +* +* ### Performance +* +* - Taking advantage of the recurrence properties of the Chebyshev polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same degree. +* +* @param {number} x - evaluation point +* @param {NumericArray} c - series coefficients in descending degree order +* @returns {number} evaluated series +* +* @example +* var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] ); +* // returns 0.75 +* +* @example +* var v = chebyshevSeries( 0.0, [ 1.0, 0.5, 0.25 ] ); +* // returns -0.875 +* +* @example +* var v = chebyshevSeries( 0.0, [] ); +* // returns 0.0 +*/ +function chebyshevSeries( x, c ) { + var b0; + var b1; + var b2; + var n; + var i; + + n = c.length; + if ( n === 0 ) { + return 0.0; + } + if ( n === 1 ) { + return 0.5 * c[ 0 ]; + } + b0 = c[ 0 ]; + b1 = 0.0; + for ( i = 1; i < n; i++ ) { + b2 = b1; + b1 = b0; + b0 = ( x * b1 ) - b2 + c[ i ]; + } + return 0.5 * ( b0 - b2 ); +} + + +// EXPORTS // + +module.exports = chebyshevSeries; diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/package.json b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/package.json new file mode 100644 index 000000000000..70ee1c809cc3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/math/base/tools/chebyshev-series", + "version": "0.0.0", + "description": "Evaluate a Chebyshev series.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "math", + "mathematics", + "chebyshev", + "series", + "polynomial", + "eval", + "evaluate", + "approximation", + "clenshaw", + "number", + "tool", + "tools" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.factory.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.factory.js new file mode 100644 index 000000000000..d63b9bbbdb1e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.factory.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var factory = require( './../lib/factory.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var f = factory( [ 1.0, 2.0, 3.0 ] ); + t.strictEqual( typeof f, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty coefficient array, the function returns a function which always returns `0.0`', function test( t ) { + var f; + var v; + var i; + + f = factory( [] ); + for ( i = 0; i < 100; i++ ) { + v = f( i ); + t.strictEqual( v, 0.0, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if provided only one coefficient, the function returns a function which always returns the coefficient divided by two', function test( t ) { + var f; + var v; + var i; + + f = factory( [ 2.0 ] ); + for ( i = 0; i < 100; i++ ) { + v = f( i ); + t.strictEqual( v, 1.0, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns a function which evaluates a Chebyshev series', function test( t ) { + var f; + var v; + + f = factory( [ 0.5, 1.0 ] ); + v = f( 1.0 ); + t.strictEqual( v, 0.75, 'returns expected value' ); + + v = f( 2.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + f = factory( [ 1.0, 0.0, 0.0 ] ); + v = f( 2.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = f( 0.0 ); + t.strictEqual( v, -1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a function which evaluates a Chebyshev series (large number of coefficients)', function test( t ) { + var f; + var c; + var v; + var i; + + c = []; + for ( i = 0; i < 1000; i++ ) { + c.push( 0.0 ); + } + c[ 0 ] = 1.0; // Coefficient of highest degree (T_999) + f = factory( c ); + + // Chebyshev polynomials of the first kind always satisfy T_n(1) = 1 + v = f( 2.0 ); // T_999(2/2) = T_999(1) = 1 + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.js new file mode 100644 index 000000000000..1577465a55cb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var chebyshevSeries = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof chebyshevSeries, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a `factory` method', function test( t ) { + t.strictEqual( typeof chebyshevSeries.factory, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.main.js b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.main.js new file mode 100644 index 000000000000..79cc81a7a0ca --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/tools/chebyshev-series/test/test.main.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var chebyshevSeries = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof chebyshevSeries, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided an empty coefficient array, the function returns `0.0`', function test( t ) { + var v = chebyshevSeries( 1.0, [] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided only one coefficient, the function returns the coefficient divided by two', function test( t ) { + var v = chebyshevSeries( 1.0, [ 2.0 ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates a Chebyshev series', function test( t ) { + var c; + var v; + + c = [ 0.5, 1.0 ]; + v = chebyshevSeries( 1.0, c ); + t.strictEqual( v, 0.75, 'returns expected value' ); + + v = chebyshevSeries( 2.0, c ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + c = [ 1.0, 0.0, 0.0 ]; + v = chebyshevSeries( 2.0, c ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = chebyshevSeries( 0.0, c ); + t.strictEqual( v, -1.0, 'returns expected value' ); + + t.end(); +});