From 0977cf9fa5d5e7107cbeb51774e333398271deca Mon Sep 17 00:00:00 2001 From: hrshya Date: Tue, 8 Apr 2025 20:21:13 +0530 Subject: [PATCH 1/2] docs: replace manual for loop in examples --- .../math/base/special/ceil10/README.md | 16 +++++++-------- .../base/special/ceil10/examples/index.js | 16 +++++++-------- .../@stdlib/math/base/special/ceil2/README.md | 16 +++++++-------- .../math/base/special/ceil2/examples/index.js | 16 +++++++-------- .../math/base/special/ceilsd/README.md | 16 +++++++-------- .../base/special/ceilsd/examples/index.js | 16 +++++++-------- .../@stdlib/math/base/special/clamp/README.md | 20 +++++++++---------- .../math/base/special/clamp/examples/index.js | 20 +++++++++---------- .../math/base/special/clampf/README.md | 20 +++++++++---------- .../base/special/clampf/examples/index.js | 20 +++++++++---------- 10 files changed, 78 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ceil10/README.md b/lib/node_modules/@stdlib/math/base/special/ceil10/README.md index 538ba1c3541c..a702a97f1635 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil10/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceil10/README.md @@ -98,18 +98,16 @@ v = ceil10( NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceil10 = require( '@stdlib/math/base/special/ceil10' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = ceil10( x ); - console.log( 'Value: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %0.4f.', x, ceil10 ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/ceil10/examples/index.js b/lib/node_modules/@stdlib/math/base/special/ceil10/examples/index.js index 616433ed6f17..4aa0f9da13ff 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil10/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceil10/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceil10 = require( './../lib' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = ceil10( x ); - console.log( 'x: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %0.4f.', x, ceil10 ); diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/README.md b/lib/node_modules/@stdlib/math/base/special/ceil2/README.md index 8a4ccf519524..d4b9fe956e23 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/README.md @@ -83,18 +83,16 @@ v = ceil2( NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceil2 = require( '@stdlib/math/base/special/ceil2' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = ceil2( x ); - console.log( 'Value: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %0.4f.', x, ceil2 ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/examples/index.js b/lib/node_modules/@stdlib/math/base/special/ceil2/examples/index.js index d37f2a7d3c09..f643937aa367 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceil2 = require( './../lib' ); -var x; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -50.0, 50.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*100.0) - 50.0; - v = ceil2( x ); - console.log( 'x: %d. Rounded: %d.', x, v ); -} +logEachMap( 'x: %0.4f. Rounded: %0.4f.', x, ceil2 ); diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md index 3a60c3bab29a..62c650c7f4aa 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md @@ -65,18 +65,16 @@ v = ceilsd( 0.0313, 2, 2 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceilsd = require( '@stdlib/math/base/special/ceilsd' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -5000.0, 5000.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*10000.0) - 5000.0; - y = ceilsd( x, 5, 10 ); - console.log( 'x: %d. Rounded: %d.', x, y ); -} +logEachMap( 'x: %0.4f. y: %0.4f. z: %0.4f. Rounded: %0.4f.', x, 5, 10, ceilsd ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js index c963430fa476..3ed17e102408 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js @@ -18,15 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var ceilsd = require( './../lib' ); -var x; -var y; -var i; +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -5000.0, 5000.0, opts ); -for ( i = 0; i < 100; i++ ) { - x = (randu()*10000.0) - 5000.0; - y = ceilsd( x, 5, 10 ); - console.log( 'x: %d. Rounded: %d.', x, y ); -} +logEachMap( 'x: %0.4f. y: %0.4f. z: %0.4f. Rounded: %0.4f.', x, 5, 10, ceilsd ); diff --git a/lib/node_modules/@stdlib/math/base/special/clamp/README.md b/lib/node_modules/@stdlib/math/base/special/clamp/README.md index a2fde4940bbe..0ba800e12174 100644 --- a/lib/node_modules/@stdlib/math/base/special/clamp/README.md +++ b/lib/node_modules/@stdlib/math/base/special/clamp/README.md @@ -95,20 +95,18 @@ v = clamp( 3.14, 0.0, NaN ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var clamp = require( '@stdlib/math/base/special/clamp' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var min = discreteUniform( 100, 0, 10, opts ); +var max = discreteUniform( 100, 5, 15, opts ); +var v = discreteUniform( 100, -20, 20, opts ); -for ( i = 0; i < 100; i++ ) { - min = discreteUniform( 0.0, 10.0 ); - max = discreteUniform( 5.0, 15.0 ); - v = discreteUniform( -20.0, 20.0 ); - console.log( 'clamp(%d,%d,%d) => %d', v, min, max, clamp( v, min, max ) ); -} +logEachMap( 'clamp(%d,%d,%d) => %0.4f', v, min, max, clamp ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js b/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js index 5cd50db98ca0..98e71dbb3fc0 100644 --- a/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js @@ -18,17 +18,15 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var clamp = require( './../lib' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float64' +}; +var min = discreteUniform( 100, 0, 10, opts ); +var max = discreteUniform( 100, 5, 15, opts ); +var v = discreteUniform( 100, -20, 20, opts ); -for ( i = 0; i < 100; i++ ) { - min = discreteUniform( 0.0, 10.0 ); - max = discreteUniform( 5.0, 15.0 ); - v = discreteUniform( -20.0, 20.0 ); - console.log( 'clamp(%d,%d,%d) => %d', v, min, max, clamp( v, min, max ) ); -} +logEachMap( 'clamp(%d,%d,%d) => %0.4f', v, min, max, clamp ); diff --git a/lib/node_modules/@stdlib/math/base/special/clampf/README.md b/lib/node_modules/@stdlib/math/base/special/clampf/README.md index 6d106b3cb4f5..159d5c896fc9 100644 --- a/lib/node_modules/@stdlib/math/base/special/clampf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/clampf/README.md @@ -95,20 +95,18 @@ v = clampf( 3.14, 0.0, NaN ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var clampf = require( '@stdlib/math/base/special/clampf' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float32' +}; +var min = discreteUniform( 100, 0, 10, opts ); +var max = discreteUniform( 100, 5, 15, opts ); +var v = discreteUniform( 100, -20, 20, opts ); -for ( i = 0; i < 100; i++ ) { - min = discreteUniform( 0.0, 10.0 ); - max = discreteUniform( 5.0, 15.0 ); - v = discreteUniform( -20.0, 20.0 ); - console.log( 'clampf(%d,%d,%d) => %d', v, min, max, clampf( v, min, max ) ); -} +logEachMap( 'clampf(%d,%d,%d) => %0.4f', v, min, max, clampf ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js index 84b49bcc1dc0..35edfc5cd663 100644 --- a/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js @@ -18,17 +18,15 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var clampf = require( './../lib' ); -var min; -var max; -var v; -var i; +var opts = { + 'dtype': 'float32' +}; +var min = discreteUniform( 100, 0, 10, opts ); +var max = discreteUniform( 100, 5, 15, opts ); +var v = discreteUniform( 100, -20, 20, opts ); -for ( i = 0; i < 100; i++ ) { - min = discreteUniform( 0.0, 10.0 ); - max = discreteUniform( 5.0, 15.0 ); - v = discreteUniform( -20.0, 20.0 ); - console.log( 'clampf(%d,%d,%d) => %d', v, min, max, clampf( v, min, max ) ); -} +logEachMap( 'clampf(%d,%d,%d) => %0.4f', v, min, max, clampf ); From 41dfd53fe0c29fd4e321f923735d0a2ae2e93e1c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 8 Apr 2025 21:04:44 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/special/ceilsd/README.md | 2 +- .../@stdlib/math/base/special/ceilsd/examples/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/clamp/README.md | 2 +- .../@stdlib/math/base/special/clamp/examples/index.js | 2 +- lib/node_modules/@stdlib/math/base/special/clampf/README.md | 2 +- .../@stdlib/math/base/special/clampf/examples/index.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md index 62c650c7f4aa..290cc248de47 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/README.md @@ -74,7 +74,7 @@ var opts = { }; var x = uniform( 100, -5000.0, 5000.0, opts ); -logEachMap( 'x: %0.4f. y: %0.4f. z: %0.4f. Rounded: %0.4f.', x, 5, 10, ceilsd ); +logEachMap( 'x: %0.4f. y: %d. z: %d. Rounded: %0.4f.', x, 5, 10, ceilsd ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js index 3ed17e102408..d088d04e0d1e 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/ceilsd/examples/index.js @@ -27,4 +27,4 @@ var opts = { }; var x = uniform( 100, -5000.0, 5000.0, opts ); -logEachMap( 'x: %0.4f. y: %0.4f. z: %0.4f. Rounded: %0.4f.', x, 5, 10, ceilsd ); +logEachMap( 'x: %0.4f. y: %d. z: %d. Rounded: %0.4f.', x, 5, 10, ceilsd ); diff --git a/lib/node_modules/@stdlib/math/base/special/clamp/README.md b/lib/node_modules/@stdlib/math/base/special/clamp/README.md index 0ba800e12174..ddd660b5d93e 100644 --- a/lib/node_modules/@stdlib/math/base/special/clamp/README.md +++ b/lib/node_modules/@stdlib/math/base/special/clamp/README.md @@ -106,7 +106,7 @@ var min = discreteUniform( 100, 0, 10, opts ); var max = discreteUniform( 100, 5, 15, opts ); var v = discreteUniform( 100, -20, 20, opts ); -logEachMap( 'clamp(%d,%d,%d) => %0.4f', v, min, max, clamp ); +logEachMap( 'clamp(%d,%d,%d) => %d', v, min, max, clamp ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js b/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js index 98e71dbb3fc0..50989fc0d6cc 100644 --- a/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/clamp/examples/index.js @@ -29,4 +29,4 @@ var min = discreteUniform( 100, 0, 10, opts ); var max = discreteUniform( 100, 5, 15, opts ); var v = discreteUniform( 100, -20, 20, opts ); -logEachMap( 'clamp(%d,%d,%d) => %0.4f', v, min, max, clamp ); +logEachMap( 'clamp(%d,%d,%d) => %d', v, min, max, clamp ); diff --git a/lib/node_modules/@stdlib/math/base/special/clampf/README.md b/lib/node_modules/@stdlib/math/base/special/clampf/README.md index 159d5c896fc9..13fa954c468f 100644 --- a/lib/node_modules/@stdlib/math/base/special/clampf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/clampf/README.md @@ -106,7 +106,7 @@ var min = discreteUniform( 100, 0, 10, opts ); var max = discreteUniform( 100, 5, 15, opts ); var v = discreteUniform( 100, -20, 20, opts ); -logEachMap( 'clampf(%d,%d,%d) => %0.4f', v, min, max, clampf ); +logEachMap( 'clampf(%d,%d,%d) => %d', v, min, max, clampf ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js index 35edfc5cd663..2ab85bfad6a5 100644 --- a/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/clampf/examples/index.js @@ -29,4 +29,4 @@ var min = discreteUniform( 100, 0, 10, opts ); var max = discreteUniform( 100, 5, 15, opts ); var v = discreteUniform( 100, -20, 20, opts ); -logEachMap( 'clampf(%d,%d,%d) => %0.4f', v, min, max, clampf ); +logEachMap( 'clampf(%d,%d,%d) => %d', v, min, max, clampf );