Published unlisted
Edited
Nov 22, 2019
5 stars
Insert cell
Insert cell
stdlib = require( 'https://unpkg.com/@stdlib/stdlib@0.0.90' )
Insert cell
Insert cell
help( 'base.sin' )
Insert cell
Insert cell
stdlib.base.erf( 0.5 )
Insert cell
Insert cell
y_erf = [ ...stdlib.iterMap( stdlib.iterLinspace( -2.5, 2.5, 500 ), stdlib.base.erf ) ]
Insert cell
Insert cell
y_bessel = {
var x = stdlib.iterIncrspace( 0.01, 20.0, 0.01 );
return [
[ ...stdlib.iterMap( x, stdlib.base.besselj0 ) ],
[ ...stdlib.iterMap( x, stdlib.base.besselj1 ) ],
[ ...stdlib.iterMap( x, stdlib.base.bessely0 ) ],
[ ...stdlib.iterMap( x, stdlib.base.bessely1 ) ]
];
}
Insert cell
Insert cell
{
var xi = [ ...stdlib.iterIncrspace( 0.01, 20.0, 0.01 ) ];
var x = [ xi, xi, xi, xi ];

var plt = new stdlib.Plot( x, y_bessel );
plt.xMin = 0.0;
plt.xMax = 20.0;
plt.yMin = -1.1;
plt.yMax = 1.1;
plt.width = 500;
plt.height = 450;
plt.title = 'Bessel Functions';
plt.labels = [
'First kind, order 0',
'First kind, order 1',
'Second kind, order 0',
'Second kind, order 1'
];
plt.colors = [
'#d62728',
'#2ca02c',
'#ff7f0e',
'#1f77b4'
];
return html`${plt.render( 'html' )}`;
}
Insert cell
Insert cell
y_pdfs = {
var x = stdlib.iterIncrspace( 0.01, 12.0, 0.01 );
return [
[ ...stdlib.iterMap( x, stdlib.base.dists.normal.pdf.factory( 2.0, 1.0 ) ) ],
[ ...stdlib.iterMap( x, stdlib.base.dists.exponential.pdf.factory( 1.0 ) ) ],
[ ...stdlib.iterMap( x, stdlib.base.dists.gamma.pdf.factory( 5.0, 1.0 ) ) ],
[ ...stdlib.iterMap( x, stdlib.base.dists.chisquare.pdf.factory( 3.0 ) ) ]
];
}
Insert cell
Insert cell
{
var xi = [ ...stdlib.iterIncrspace( 0.01, 12.0, 0.01 ) ];
var x = [ xi, xi, xi, xi ];

var plt = new stdlib.Plot( x, y_pdfs );
plt.xMin = -0.01;
plt.xMax = 12.01;
plt.yMin = 0.0;
plt.yMax = 0.7;
plt.width = 600;
plt.height = 500;
plt.title = 'Probability Density Functions';
plt.labels = [
'normal',
'exponential',
'gamma',
'chi^2'
];
return html`${plt.render( 'html' )}`;
}
Insert cell
Insert cell
xy_prngs = {
var opts = {
'iter': 1000
};
var x = [
[ ...stdlib.random.iterators.normal( 30.0, 7.5, opts ) ],
[ ...stdlib.random.iterators.normal( 40.0, 12.5, opts ) ]
];
var y = [
[ ...stdlib.random.iterators.normal( 50.0, 10.0, opts ) ],
[ ...stdlib.random.iterators.normal( 30.0, 5.0, opts ) ]
];
return [ x, y ];
}
Insert cell
Insert cell
{
var opts = {
'width': 600,
'height': 480,
'xMin': 0.0,
'xMax': 100.0,
'yMin': 0.0,
'yMax': 100.0,
'lineStyle': 'none',
'symbols': 'closed-circle',
'symbolsSize': 6,
'symbolsOpacity': 0.2,
'xRug': true,
'yRug': true,
'xRugOrient': 'top',
'yRugOrient': 'right'
};
var plt = stdlib.plot( xy_prngs[0], xy_prngs[1], opts );
return html`${plt.render( 'html' )}`;
}
Insert cell
Insert cell
{
function indicator( v ) {
return v[ 0 ];
}
var arr = [
'be',
'bo',
'fo',
'ba'
];
return stdlib.groupBy( arr, indicator );
}
Insert cell
Insert cell
{
function predicate( key, value ) {
return ( value > 1 );
}
var obj = {
'a': 1,
'b': 2,
'c': 3
};
return stdlib.omitBy( obj, predicate );
}
Insert cell
Insert cell
stdlib.isComplex128( new stdlib.Complex128( 3.0, -5.0 ) )
Insert cell
Insert cell
stdlib.isMatrixLike( stdlib.ndarray( 'float64', 2 )( [1,2,3,4], [2,2], [2,1], 0, 'row-major' ) )
Insert cell
Insert cell
stdlib.deepHasOwnProp( { 'a': { 'b': { 'c': { 'd': 'e' } } } }, 'a.b.c.d' )
Insert cell
Insert cell
stdlib.isEmailAddress( 'foo@bar.com' )
Insert cell
Insert cell
stdlib.isLeapYear( 2000 )
Insert cell
Insert cell
{
var x = new stdlib.Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var y = new stdlib.Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
var alpha = 5.0;
return stdlib.base.daxpy( x.length, alpha, x, 1, y, 1 );
}
Insert cell
Insert cell
bench( 'sin', function benchmark( b ) {
var randu;
var sin;
var x;
var y;
var i;
// Alias to prevent walking the object path:
randu = stdlib.base.random.randu;
sin = stdlib.base.sin;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu();
y = sin( x );
if ( y !== y ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( y !== y ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Insert cell
Insert cell
Insert cell
Insert cell
base_url = 'https://github.com/stdlib-js/stdlib'
Insert cell
base_pkgs_url = 'https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib'
Insert cell
stdlib_flat_help = require( "https://unpkg.com/@stdlib/stdlib@0.0.90/dist/stdlib-flat-help.min.js" )
Insert cell
/**
* Returns help text for a provided alias.
*
* @param {string} alias - alias
* @returns {string} help text
*/
function help( alias ) {
var txt = stdlib_flat_help.help( alias );
if ( txt === null ) {
txt = 'Error: unrecognized alias. Ensure that the provided alias is spelled correctly, including capitalization.';
}
return md`\`\`\`${txt}\`\`\``;
}
Insert cell
/**
* Promisifies the stdlib benchmark harness in order to asynchronously resolve benchmark results.
*
* @param {string} description - benchmark description
* @param {Object} [options] - benchmark options
* @param {Function} clbk - benchmark function
* @returns {Promise} promisified harness
*/
function bench( /* description, [options,] clbk */ ) {
var harness;
var args;
var p;
var i;
// Copy input arguments to an array:
args = [];
for ( i = 0; i < arguments.length; i++ ) {
args.push( arguments[ i ] );
}
return new Promise( executor );
function executor( resolve, reject ) {
var harness;
var results;
var stream;
results = '';
// Create a new benchmark harness:
harness = stdlib.harness.createHarness( onFinish );
// Create a stream for benchmark results:
stream = harness.createStream();
// Listen for 'data' events (i.e., benchmark results):
stream.on( 'data', onResults );
// Run the provided benchmark:
harness.apply( harness, args );
function onResults( data ) {
results += data.toString();
}
function onFinish() {
// Once a benchmark finishes, close the harness:
harness.close();
// Return the benchmark results:
resolve( results );
}
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more