Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Mar 25, 2024
1 parent 951d686 commit bb92ef3
Show file tree
Hide file tree
Showing 28 changed files with 1,553 additions and 73 deletions.
29 changes: 12 additions & 17 deletions base/tools/evalpoly/benchmark/benchmark.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib/factory.js' );
Expand All @@ -30,18 +30,18 @@ var factory = require( './../lib/factory.js' );
// MAIN //

bench( pkg+'::create:factory', function benchmark( b ) {
var c;
var values;
var f;
var i;

c = [];
for ( i = 0; i < 10; i++ ) {
c.push( randu() );
}
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++ ) {
c[ 0 ] = randu();
f = factory( c );
f = factory( values[ i%values.length ] );
if ( typeof f !== 'function' ) {
b.fail( 'should return a function' );
}
Expand All @@ -55,22 +55,17 @@ bench( pkg+'::create:factory', function benchmark( b ) {
});

bench( pkg+'::evaluate:factory', function benchmark( b ) {
var x;
var values;
var v;
var f;
var c;
var i;

c = [];
for ( i = 0; i < 10; i++ ) {
c.push( randu() );
}
f = factory( c );
f = factory( uniform( 10, 0.0, 100.0 ) );
values = uniform( 10, 0.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 100.0;
v = f( x );
v = f( values[ i%values.length ] );
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
17 changes: 5 additions & 12 deletions base/tools/evalpoly/benchmark/benchmark.factory.length.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var pow = require( './../../../../base/special/pow' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib/factory.js' );
Expand All @@ -38,15 +38,7 @@ var factory = require( './../lib/factory.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var polyval;
var c;
var i;

c = [];
for ( i = 0; i < len; i++ ) {
c.push( randu() );
}
polyval = factory( c );
var polyval = factory( uniform( len, 0.0, 100.0 ) );
return benchmark;

/**
Expand All @@ -60,10 +52,11 @@ function createBenchmark( len ) {
var v;
var i;

x = uniform( 10, 0.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 100.0;
v = polyval( x );
v = polyval( x[ i%x.length ] );
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
19 changes: 10 additions & 9 deletions base/tools/evalpoly/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var evalpoly = require( './../lib' );
Expand All @@ -30,20 +30,21 @@ var evalpoly = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var c;
var coefs;
var x;
var v;
var i;

c = [];
for ( i = 0; i < 10; i++ ) {
c.push( randu() );
}
coefs = [
uniform( 10, 0.0, 100.0 ),
uniform( 10, 0.0, 100.0 ),
uniform( 10, 0.0, 100.0 )
];
x = uniform( 10, 0.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
c[ 0 ] = randu();
x = randu() * 100.0;
v = evalpoly( c, x );
v = evalpoly( coefs[ i%coefs.length ], x[ i%x.length ] );
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
15 changes: 5 additions & 10 deletions base/tools/evalpoly/benchmark/benchmark.length.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var pow = require( './../../../../base/special/pow' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var evalpoly = require( './../lib' );
Expand All @@ -38,13 +38,7 @@ var evalpoly = require( './../lib' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var c;
var i;

c = [];
for ( i = 0; i < len; i++ ) {
c.push( randu() );
}
var c = uniform( len, 0.0, 100.0 );
return benchmark;

/**
Expand All @@ -58,10 +52,11 @@ function createBenchmark( len ) {
var v;
var i;

x = uniform( 10, 0.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 100.0;
v = evalpoly( c, x );
v = evalpoly( c, x[ i%x.length ] );
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
6 changes: 3 additions & 3 deletions base/tools/evalpoly/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@

Examples
--------
> var polyval = {{alias}}.factory( [ 3.0, 2.0, 1.0 ] );
> var f = {{alias}}.factory( [ 3.0, 2.0, 1.0 ] );

// 3*10^0 + 2*10^1 + 1*10^2
> var v = polyval( 10.0 )
> var v = f( 10.0 )
123.0

// 3*5^0 + 2*5^1 + 1*5^2
> v = polyval( 5.0 )
> v = f( 5.0 )
38.0

See Also
Expand Down
12 changes: 6 additions & 6 deletions base/tools/evalpoly/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Collection } from '@stdlib/types/array';
* @param x - value at which to evaluate a polynomial
* @returns evaluated polynomial
*/
type EvaluationFunction = ( x: number ) => number;
type PolynomialFunction = ( x: number ) => number;

/**
* Interface for evaluating polynomials.
Expand All @@ -49,7 +49,7 @@ interface EvalPoly {
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*/
( c: Collection<number>, x: number ): number;
Expand All @@ -68,15 +68,15 @@ interface EvalPoly {
* @returns function for evaluating a polynomial
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
* var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
* // returns 38.0
*/
factory( c: Collection<number> ): EvaluationFunction;
factory( c: Collection<number> ): PolynomialFunction;
}

/**
Expand All @@ -94,11 +94,11 @@ interface EvalPoly {
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
* var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
Expand Down
24 changes: 12 additions & 12 deletions base/tools/evalpoly/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ import evalpoly = require( './index' );
// Attached to main export is a `factory` method which returns a function...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly.factory( c ); // $ExpectType EvaluationFunction
evalpoly.factory( c ); // $ExpectType PolynomialFunction
}

// The compiler throws an error if the `factory` method is provided a first argument which is not an array of numbers...
{
evalpoly.factory( true ); // $ExpectError
evalpoly.factory( false ); // $ExpectError
evalpoly.factory( 'abc' ); // $ExpectError
evalpoly.factory( 123 ); // $ExpectError
evalpoly.factory( {} ); // $ExpectError
evalpoly.factory( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the `factory` method is provided an unsupported number of arguments...
Expand All @@ -74,7 +84,7 @@ import evalpoly = require( './index' );
polyval( 1.0 ); // $ExpectType number
}

// The `factory` method returns a function which does not compile if provided a first argument which is not a number...
// The compiler throws an error if the function returned by the `factory` method is provided a first argument which is not a number...
{
const c = [ 3.0, 2.0, 1.0 ];
const polyval = evalpoly.factory( c );
Expand All @@ -85,13 +95,3 @@ import evalpoly = require( './index' );
polyval( {} ); // $ExpectError
polyval( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the `factory` method is provided a first argument which is not an array of numbers...
{
evalpoly.factory( true ); // $ExpectError
evalpoly.factory( false ); // $ExpectError
evalpoly.factory( 'abc' ); // $ExpectError
evalpoly.factory( 123 ); // $ExpectError
evalpoly.factory( {} ); // $ExpectError
evalpoly.factory( ( x: number ): number => x ); // $ExpectError
}
2 changes: 1 addition & 1 deletion base/tools/evalpoly/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var evalpoly = require( './main.js' );
* @returns {Function} function for evaluating a polynomial
*
* @example
* var polyval = factory( [3.0,2.0,1.0] );
* var polyval = factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
Expand Down
4 changes: 2 additions & 2 deletions base/tools/evalpoly/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* @example
* var evalpoly = require( '@stdlib/math/base/tools/evalpoly' );
*
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* @example
* var evalpoly = require( '@stdlib/math/base/tools/evalpoly' );
*
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
* var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
Expand Down
2 changes: 1 addition & 1 deletion base/tools/evalpoly/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @returns {number} evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*/
function evalpoly( c, x ) {
Expand Down
Loading

0 comments on commit bb92ef3

Please sign in to comment.