diff --git a/.github/.keepalive b/.github/.keepalive new file mode 100644 index 0000000..a876b6e --- /dev/null +++ b/.github/.keepalive @@ -0,0 +1 @@ +2024-04-01T02:21:02.513Z diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 010fb9d..3eec50e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -214,8 +214,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f + # Pin action to full length commit SHA + uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index feef543..41be3b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,8 +91,8 @@ jobs: # Send status to Slack channel if job fails: - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f + # Pin action to full length commit SHA + uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index 912e7fe..f5410dd 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -113,8 +113,8 @@ jobs: # Send Slack notification if job fails: - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f + # Pin action to full length commit SHA + uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index 530a204..8425f9e 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -77,8 +77,8 @@ jobs: # Send Slack notification if job fails: - name: 'Send notification to Slack in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f + # Pin action to full length commit SHA + uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} steps: ${{ toJson(steps) }} diff --git a/CONTRIBUTORS b/CONTRIBUTORS index bfb0b09..4500383 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -36,6 +36,7 @@ Joris Labie Justin Dennison Karthik Prakash <116057817+skoriop@users.noreply.github.com> Khaldon +Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Lovelin <100030865+lovelindhoni@users.noreply.github.com> Manik Sharma Marcus Fantham @@ -45,6 +46,7 @@ Milan Raj Momtchil Momtchev Muhammad Haris Naresh Jagadeesan +NightKnight Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Ognjen Jevremović Oneday12323 <107678750+Oneday12323@users.noreply.github.com> @@ -54,6 +56,7 @@ Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> Priyansh <88396544+itsspriyansh@users.noreply.github.com> +Pushpendra Chandravanshi Raunak Kumar Gupta Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Ricky Reusser @@ -64,6 +67,7 @@ Ryan Seal Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Seyyed Parsa Neshaei Shashank Shekhar Singh +Shivam <11shivam00@gmail.com> Shraddheya Shendre Shubham Mishra Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> @@ -71,6 +75,7 @@ Spandan Barve Stephannie Jiménez Gacha Suraj kumar <125961509+kumarsuraj212003@users.noreply.github.com> Tirtadwipa Manunggal +Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com> Utkarsh Utkarsh Raj Varad Gupta diff --git a/README.md b/README.md index 5e1d23a..838970a 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,11 @@ For more information on the project, filing bug reports and feature requests, an --- +## License + +See [LICENSE][stdlib-license]. + + ## Copyright Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. @@ -256,6 +261,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors +[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-base-tools-evalpoly-compile/main/LICENSE + [@stdlib/math/base/tools/evalpoly]: https://github.com/stdlib-js/math-base-tools-evalpoly diff --git a/dist/index.js b/dist/index.js index 3e704d0..d31a2d9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,24 +1,5 @@ +"use strict";var L=function(e,l){return function(){return l||e((l={exports:{}}).exports,l),l.exports}};var y=L(function(q,u){ +var f=require("path").join,s=require('@stdlib/fs-read-file/dist').sync,T=require('@stdlib/string-replace/dist'),E=require('@stdlib/assert-is-integer/dist').isPrimitive,A=require('@stdlib/array-float32/dist'),v={encoding:"utf8"},p=f(__dirname,"templates"),_=s(f(p,"single_coefficient.js.txt"),v),g=s(f(p,"evalpoly.js.txt"),v),P=s(f(p,"evalpoly.float32.js.txt"),v),x=s(f(p,"empty.js.txt"),v),m=s(f(p,"loop.js.txt"),v),F=s(f(p,"loop.float32.js.txt"),v),O=68;function j(e,l){var i,a,n,r,o,d,t;if(a={dtype:"float64"},arguments.length>1&&(a.dtype=l.dtype||a.dtype),o=e.length,o===0)return x;if(a.dtype==="float32"&&(e=new A(e)),o===1)return r=e[0].toString(),E(e[0])&&(r+=".0"),T(_,"{{coefficient}}",r);if(d=o-1,o>500){for(r="",t=0;tO?" // eslint-disable-line max-len":"")}u.exports=j +});var M=y();module.exports=M; /** @license Apache-2.0 */ - -'use strict'; - -/** -* Compile a module for evaluating a polynomial. -* -* @module @stdlib/math-base-tools-evalpoly-compile -* -* @example -* var compile = require( '@stdlib/math-base-tools-evalpoly-compile' ); -* -* var str = compile( [3.0,2.0,1.0] ); // 3*10^0 + 2*10^1 + 1*10^2 -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; +//# sourceMappingURL=index.js.map diff --git a/dist/main.js b/dist/main.js deleted file mode 100644 index 9c16b94..0000000 --- a/dist/main.js +++ /dev/null @@ -1,170 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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 join = require( 'path' ).join; -var readFile = require( '@stdlib/fs-read-file' ).sync; -var replace = require( '@stdlib/string-replace' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var Float32Array = require( '@stdlib/array-float32' ); - - -// VARIABLES // - -var opts = { - 'encoding': 'utf8' -}; -var dir = join( __dirname, 'templates' ); - -// Templates: -var SINGLE_COEFFICIENT_TEMPLATE = readFile( join( dir, 'single_coefficient.js.txt' ), opts ); // eslint-disable-line id-length - -var EVALPOLY_TEMPLATE = readFile( join( dir, 'evalpoly.js.txt' ), opts ); -var EVALPOLY_FLOAT32_TEMPLATE = readFile( join( dir, 'evalpoly.float32.js.txt' ), opts ); - -var EMPTY_TEMPLATE = readFile( join( dir, 'empty.js.txt' ), opts ); - -var LOOP_TEMPLATE = readFile( join( dir, 'loop.js.txt' ), opts ); -var LOOP_FLOAT32_TEMPLATE = readFile( join( dir, 'loop.float32.js.txt' ), opts ); - -var MAX_CHARS = 68; // max-len (80) - chars already in line ('tab': 4, 'return ': 7, ';': 1) - - -// MAIN // - -/** -* Compiles a module string which exports a function for evaluating a polynomial. -* -* @param {NumericArray} c - polynomial coefficients sorted in ascending degree -* @param {Options} [options] - function options -* @param {string} [options.dtype='float64'] - input value floating-point data type -* @returns {string} module string exporting a function for evaluating a polynomial -* -* @example -* var str = compile( [ 3.0, 2.0, 1.0 ] ); -* // returns -*/ -function compile( c, options ) { - var horner; - var opts; - var tmpl; - var str; - var n; - var m; - var i; - - opts = { - 'dtype': 'float64' - }; - if ( arguments.length > 1 ) { - opts.dtype = options.dtype || opts.dtype; - } - n = c.length; - - // If no coefficients, the function always returns 0... - if ( n === 0 ) { - return EMPTY_TEMPLATE; - } - if ( opts.dtype === 'float32' ) { - // Ensure that coefficients have been converted to single-precision: - c = new Float32Array( c ); - } - // If only one coefficient, the function always returns that coefficient... - if ( n === 1 ) { - str = c[ 0 ].toString(); - if ( isInteger( c[ 0 ] ) ) { - str += '.0'; - } - return replace( SINGLE_COEFFICIENT_TEMPLATE, '{{coefficient}}', str ); - } - m = n - 1; - - // Avoid exceeding the maximum stack size on V8 by using a simple loop :(. Note that the choice of `500` was empirically determined... - if ( n > 500 ) { - str = ''; - for ( i = 0; i < n; i++ ) { - str += '\t' + c[ i ].toString(); - if ( isInteger( c[ i ] ) ) { - str += '.0'; - } - if ( i < m ) { - str += ',\n'; - } - } - if ( opts.dtype === 'float32' ) { - tmpl = LOOP_FLOAT32_TEMPLATE; - } else { - tmpl = LOOP_TEMPLATE; - } - return replace( tmpl, '{{coefficients}}', str ); - } - // If more than one coefficient, apply Horner's method... - if ( opts.dtype === 'float32' ) { - horner = 'float64ToFloat32('; - } else { - horner = ''; - } - horner += c[ 0 ].toString(); - if ( isInteger( c[ 0 ] ) ) { - horner += '.0'; - } - for ( i = 1; i < n; i++ ) { - if ( opts.dtype === 'float32' ) { - horner += ' + float64ToFloat32(x * '; - if ( i < m ) { - horner += 'float64ToFloat32('; - } - } else { - horner += ' + (x * '; - if ( i < m ) { - horner += '('; - } - } - horner += c[ i ].toString(); - if ( isInteger( c[ i ] ) ) { - horner += '.0'; - } - } - // Close all the parentheses... - for ( i = 0; i < (2*(n-1))-1; i++ ) { - horner += ')'; - } - if ( opts.dtype === 'float32' ) { - horner += ')'; - } - str = c[ 0 ].toString(); - if ( isInteger( c[ 0 ] ) ) { - str += '.0'; - } - if ( opts.dtype === 'float32' ) { - tmpl = EVALPOLY_FLOAT32_TEMPLATE; - } else { - tmpl = EVALPOLY_TEMPLATE; - } - str = replace( tmpl, '{{coefficient}}', str ); - str = replace( str, '{{horner}}', horner ); - return replace( str, '{{eslint}}', ( horner.length > MAX_CHARS ) ? ' // eslint-disable-line max-len' : '' ); -} - - -// EXPORTS // - -module.exports = compile; diff --git a/dist/templates/empty.js.txt b/dist/templates/empty.js.txt deleted file mode 100644 index 48c2c8a..0000000 --- a/dist/templates/empty.js.txt +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -// MAIN // - -/** -* Evaluates a polynomial. -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly() { - return 0.0; -} - - -// EXPORTS // - -module.exports = evalpoly; diff --git a/dist/templates/evalpoly.float32.js.txt b/dist/templates/evalpoly.float32.js.txt deleted file mode 100644 index b11ccf0..0000000 --- a/dist/templates/evalpoly.float32.js.txt +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -// MODULES // - -var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' ); - - -// MAIN // - -/** -* Evaluates a polynomial. -* -* ## Notes -* -* - The implementation uses [Horner's rule][horners-method] for efficient computation. -* -* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly( x ) { - if ( x === 0.0 ) { - return {{coefficient}}; - } - return {{horner}};{{eslint}} -} - - -// EXPORTS // - -module.exports = evalpoly; diff --git a/dist/templates/evalpoly.js.txt b/dist/templates/evalpoly.js.txt deleted file mode 100644 index fdb24bb..0000000 --- a/dist/templates/evalpoly.js.txt +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -// MAIN // - -/** -* Evaluates a polynomial. -* -* ## Notes -* -* - The implementation uses [Horner's rule][horners-method] for efficient computation. -* -* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly( x ) { - if ( x === 0.0 ) { - return {{coefficient}}; - } - return {{horner}};{{eslint}} -} - - -// EXPORTS // - -module.exports = evalpoly; diff --git a/dist/templates/loop.float32.js.txt b/dist/templates/loop.float32.js.txt deleted file mode 100644 index 28ac616..0000000 --- a/dist/templates/loop.float32.js.txt +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -// MODULES // - -var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' ); - - -// VARIABLES // - -var C = [ -{{coefficients}} -]; -var END = C.length - 1; - - -// MAIN // - -/** -* Evaluates a polynomial. -* -* ## Notes -* -* - The implementation uses [Horner's rule][horners-method] for efficient computation. -* -* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly( x ) { - var p; - var i; - - if ( x === 0.0 ) { - return C[ 0 ]; - } - i = END; - p = float64ToFloat32( float64ToFloat32( C[ i ] * x ) + C[ i-1 ] ); - i -= 2; - while ( i >= 0 ) { - p = float64ToFloat32( float64ToFloat32( p * x ) + C[ i ] ); - i -= 1; - } - return p; -} - - -// EXPORTS // - -module.exports = evalpoly; diff --git a/dist/templates/loop.js.txt b/dist/templates/loop.js.txt deleted file mode 100644 index 4ca8fe8..0000000 --- a/dist/templates/loop.js.txt +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -// VARIABLES // - -var C = [ -{{coefficients}} -]; -var END = C.length - 1; - - -// MAIN // - -/** -* Evaluates a polynomial. -* -* ## Notes -* -* - The implementation uses [Horner's rule][horners-method] for efficient computation. -* -* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly( x ) { - var p; - var i; - - if ( x === 0.0 ) { - return C[ 0 ]; - } - i = END; - p = ( C[ i ] * x ) + C[ i-1 ]; - i -= 2; - while ( i >= 0 ) { - p = ( p * x ) + C[ i ]; - i -= 1; - } - return p; -} - - -// EXPORTS // - -module.exports = evalpoly; diff --git a/dist/templates/single_coefficient.js.txt b/dist/templates/single_coefficient.js.txt deleted file mode 100644 index 96684c1..0000000 --- a/dist/templates/single_coefficient.js.txt +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -// MAIN // - -/** -* Evaluates a polynomial. -* -* @private -* @param {number} x - value at which to evaluate the polynomial -* @returns {number} evaluated polynomial -*/ -function evalpoly() { - return {{coefficient}}; -} - - -// EXPORTS // - -module.exports = evalpoly;