Skip to content

Commit

Permalink
refactor: use stdlib package to sum three numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Nov 21, 2023
1 parent 1f0ecb0 commit d3f4b2f
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 135 deletions.
30 changes: 6 additions & 24 deletions lib/node_modules/@stdlib/strided/base/ternary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ var ternary = require( '@stdlib/strided/base/ternary' );
Applies a ternary callback to strided input array elements and assigns results to elements in a strided output array.

```javascript
var add = require( '@stdlib/math/base/ops/add3' );
var Float64Array = require( '@stdlib/array/float64' );

function add( x, y, z ) {
return x + y + z;
}

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -66,12 +63,9 @@ The function accepts the following arguments:
The `shape` and `strides` parameters determine which elements in the strided input and output arrays are accessed at runtime. For example, to index every other value in the strided input arrays and to index the first `N` elements of the strided output array in reverse order,

```javascript
var add = require( '@stdlib/math/base/ops/add3' );
var Float64Array = require( '@stdlib/array/float64' );

function add( x, y, z ) {
return x + y + z;
}

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -84,12 +78,9 @@ ternary( [ x, y, z, w ], [ 3 ], [ 2, 2, 2, -1 ], add );
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

```javascript
var add = require( '@stdlib/math/base/ops/add3' );
var Float64Array = require( '@stdlib/array/float64' );

function add( x, y, z ) {
return x + y + z;
}

// Initial arrays...
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
Expand All @@ -113,12 +104,9 @@ Applies a ternary callback to strided input array elements and assigns results t
<!-- eslint-disable max-len -->

```javascript
var add = require( '@stdlib/math/base/ops/add3' );
var Float64Array = require( '@stdlib/array/float64' );

function add( x, y, z ) {
return x + y + z;
}

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -137,12 +125,9 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
<!-- eslint-disable max-len -->

```javascript
var add = require( '@stdlib/math/base/ops/add3' );
var Float64Array = require( '@stdlib/array/float64' );

function add( x, y, z ) {
return x + y + z;
}

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
Expand Down Expand Up @@ -172,12 +157,9 @@ ternary.ndarray( [ x, y, z, w ], [ 3 ], [ 2, 2, 2, -1 ], [ 1, 1, 1, w.length-1 ]
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarray = require( '@stdlib/array/filled' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var add = require( '@stdlib/math/base/ops/add3' );
var ternary = require( '@stdlib/strided/base/ternary' );

function add( x, y, z ) {
return x + y + z;
}

var N = 10;

var x = filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var round = require( '@stdlib/math/base/special/round' );
var filledarray = require( '@stdlib/array/filled' );
var add = require( '@stdlib/math/base/ops/add3' );
var pkg = require( './../package.json' ).name;
var ternary = require( './../lib/main.js' );

Expand All @@ -37,19 +38,6 @@ var types = [ 'float64' ];

// FUNCTIONS //

/**
* Returns the sum.
*
* @private
* @param {number} x - value
* @param {number} y - value
* @param {number} z - value
* @returns {number} sum
*/
function add( x, y, z ) {
return x + y + z;
}

/**
* Creates a benchmark function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var round = require( '@stdlib/math/base/special/round' );
var filledarray = require( '@stdlib/array/filled' );
var add = require( '@stdlib/math/base/ops/add3' );
var pkg = require( './../package.json' ).name;
var ternary = require( './../lib/ndarray.js' );

Expand All @@ -37,19 +38,6 @@ var types = [ 'float64' ];

// FUNCTIONS //

/**
* Returns the sum.
*
* @private
* @param {number} x - value
* @param {number} y - value
* @param {number} z - value
* @returns {number} sum
*/
function add( x, y, z ) {
return x + y + z;
}

/**
* Creates a benchmark function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ interface Routine {
* @param fcn - ternary callback
*
* @example
* var add = require( `@stdlib/math/base/ops/add3` );
* var Float64Array = require( `@stdlib/array/float64` );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -76,12 +73,9 @@ interface Routine {
* @param fcn - ternary callback
*
* @example
* var add = require( `@stdlib/math/base/ops/add3` );
* var Float64Array = require( `@stdlib/array/float64` );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -108,12 +102,9 @@ interface Routine {
* @param fcn - ternary callback
*
* @example
* var add = require( `@stdlib/math/base/ops/add3` );
* var Float64Array = require( `@stdlib/array/float64` );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -128,12 +119,9 @@ interface Routine {
* // => <Float64Array>[ 3.0, 6.0, 9.0, 12.0, 15.0 ]
*
* @example
* var add = require( `@stdlib/math/base/ops/add3` );
* var Float64Array = require( `@stdlib/array/float64` );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarray = require( '@stdlib/array/filled' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var add = require( '@stdlib/math/base/ops/add3' );
var ternary = require( './../lib' );

function add( x, y, z ) {
return x + y + z;
}

var N = 10;

var x = filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) );
Expand Down
10 changes: 2 additions & 8 deletions lib/node_modules/@stdlib/strided/base/ternary/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
* @module @stdlib/strided/base/ternary
*
* @example
* var add = require( '@stdlib/math/base/ops/add3' );
* var Float64Array = require( '@stdlib/array/float64' );
* var ternary = require( '@stdlib/strided/base/ternary' );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand All @@ -45,13 +42,10 @@
* // => <Float64Array>[ 3.0, 6.0, 9.0, 12.0, 15.0 ]
*
* @example
* var add = require( '@stdlib/math/base/ops/add3' );
* var Float64Array = require( '@stdlib/array/float64' );
* var ternary = require( '@stdlib/strided/base/ternary' );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand Down
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/strided/base/ternary/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@
* @returns {void}
*
* @example
* var add = require( '@stdlib/math/base/ops/add3' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand Down
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/strided/base/ternary/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
* @returns {void}
*
* @example
* var add = require( '@stdlib/math/base/ops/add3' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* function add( x, y, z ) {
* return x + y + z;
* }
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
Expand Down
39 changes: 0 additions & 39 deletions lib/node_modules/@stdlib/strided/base/ternary/test/fixtures/add.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );
var Float64Array = require( '@stdlib/array/float64' );
var add = require( '@stdlib/math/base/ops/add3' );
var ternary = require( './../lib/main.js' );


// FIXTURES //

var add = require( './fixtures/add.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@

var tape = require( 'tape' );
var Float64Array = require( '@stdlib/array/float64' );
var add = require( '@stdlib/math/base/ops/add3' );
var ternary = require( './../lib/ndarray.js' );


// FIXTURES //

var add = require( './fixtures/add.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
Expand Down

0 comments on commit d3f4b2f

Please sign in to comment.