From 73b0b00ee96383f1b054675fcf1547f02056f372 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 16:28:02 +0000
Subject: [PATCH 01/15] feat: add array/base/linspace2d
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
.../@stdlib/array/base/linspace2d/README.md | 128 ++++++++++++++++++
.../base/linspace2d/benchmark/benchmark.js | 48 +++++++
.../linspace2d/benchmark/benchmark.size.js | 95 +++++++++++++
.../array/base/linspace2d/docs/repl.txt | 32 +++++
.../base/linspace2d/docs/types/index.d.ts | 51 +++++++
.../array/base/linspace2d/docs/types/test.ts | 71 ++++++++++
.../array/base/linspace2d/examples/index.js | 34 +++++
.../array/base/linspace2d/lib/index.js | 43 ++++++
.../@stdlib/array/base/linspace2d/lib/main.js | 84 ++++++++++++
.../array/base/linspace2d/package.json | 67 +++++++++
.../array/base/linspace2d/test/test.js | 105 ++++++++++++++
11 files changed, 758 insertions(+)
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/README.md
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.js
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/docs/types/test.ts
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/examples/index.js
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/package.json
create mode 100644 lib/node_modules/@stdlib/array/base/linspace2d/test/test.js
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
new file mode 100644
index 000000000000..babc2b5712a1
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -0,0 +1,128 @@
+
+
+# linspace2d
+
+> Generate a linearly spaced two-dimensional nested numeric array.
+
+
+
+## Usage
+
+```javascript
+var linspace2d = require( '@stdlib/array/base/linspace2d' );
+```
+
+#### linspace2d( start, stop, shape, colexicographic )
+
+Generates a linearly spaced two-dimensional nested numeric array.
+
+```javascript
+var x = linspace2d( 0, 100, [ 2, 3 ], false );
+// returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
+
+x = linspace2d( 0, 100, [ 2, 3 ], true );
+// returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
+```
+
+
+
+
+
+
+
+## Notes
+
+- The function assumes that the product of number of rows and columns is greater than or equal to `2`.
+
+- The output `array` is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
+
+ ```javascript
+ var arr = linspace2d( 0, 10, [ 2, 2 ], false );
+ // returns [ [ 0, 3.3333333333333335 ], [ 6.666666666666667, 10 ] ]
+ ```
+
+ If you desire more control over element precision, consider using [`roundn`][@stdlib/math/base/special/roundn]:
+
+ ```javascript
+ var roundn = require( '@stdlib/math/base/special/roundn' );
+
+ // Create an array subject to floating-point rounding errors:
+ var arr = linspace( 0, 10, [ 3, 3 ], false );
+
+ // Round each value to the nearest hundredth:
+ var i;
+ var j;
+ for ( i = 0; i < arr.length; i++ ) {
+ for ( j = 0; j < arr[i].length; j++ ) {
+ arr[ i ][ j ] = roundn( arr[ i ][ j ], -2 );
+ }
+ }
+ console.log( arr.join( '\n' ) );
+ ```
+
+
+
+
+
+
+
+## Examples
+
+
+
+```javascript
+var linspace2d = require( '@stdlib/array/base/linspace2d' );
+
+var out = linspace2d( 0, 10, [ 2, 5 ], false );
+console.log( out );
+
+out = linspace2d( 0, 10, [ 2, 3 ], true );
+console.log( out );
+
+out = linspace2d( 0, 10, [ 4, 2 ], true );
+console.log( out );
+
+// Create an array of arrays with decremented values:
+out = linspace2d( 10, 0, [ 2, 5 ], false );
+console.log( out );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+[@stdlib/math/base/special/roundn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/roundn
+
+
+
+
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.js
new file mode 100644
index 000000000000..809b638dec9c
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.js
@@ -0,0 +1,48 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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 bench = require( '@stdlib/bench' );
+var isArrayArray = require( '@stdlib/assert/is-array-array' );
+var pkg = require( './../package.json' ).name;
+var linspace2d = require( './../lib' );
+
+
+// MAIN //
+
+bench( pkg, function benchmark( b ) {
+ var i;
+ var v;
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ v = linspace2d( 0.0, 100.0, [ 2, 3 ], false );
+ if ( typeof v !== 'object' ) {
+ b.fail( 'should return an array of arrays' );
+ }
+ }
+ b.toc();
+ if ( !isArrayArray( v ) ) {
+ b.fail( 'should return an array of arrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
new file mode 100644
index 000000000000..3964b6193c6b
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
@@ -0,0 +1,95 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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 bench = require( '@stdlib/bench' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var sqrt = require( '@stdlib/math/base/special/sqrt' );
+var isArrayArray = require( '@stdlib/assert/is-array-array' );
+var pkg = require( './../package.json' ).name;
+var linspace2d = require( './../lib' );
+
+
+// FUNCTIONS //
+
+/**
+* Creates a benchmark function.
+*
+* @private
+* @param {PositiveInteger} N - array lengths
+* @returns {Function} benchmark function
+*/
+function createBenchmark( N ) {
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var v;
+ var i;
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ v = linspace2d( 0.0, 100.0, [ N, N ], false );
+ if ( typeof v !== 'object' ) {
+ b.fail( 'should return an array of arrays' );
+ }
+ }
+ b.toc();
+ if ( !isArrayArray( v ) ) {
+ b.fail( 'should return an array of arrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var N;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1; // 10^min
+ max = 6; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ N = floor( sqrt( pow( 10, i ) ) );
+ f = createBenchmark( N );
+ bench( pkg+'::square_matrix:size='+(N*N), f );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
new file mode 100644
index 000000000000..c31943313c36
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
@@ -0,0 +1,32 @@
+
+{{alias}}( start, stop, shape, colexicographic )
+ Generates a linearly spaced two-dimensional nested numeric array.
+
+ The output array is guaranteed to include the `start` and `stop` values.
+
+ Parameters
+ ----------
+ start: number
+ First array value.
+
+ stop: number
+ Last array value.
+
+ shape: Array
+ Array shape.
+
+ colexicographic: boolean
+ specifies whether the array values should be in colexicographic order
+
+ Returns
+ -------
+ out: Array
+ Linearly spaced two-dimensional nested numeric array.
+
+ Examples
+ --------
+ > var arr = {{alias}}( 0, 10, [ 2, 3 ], false )
+ [ [ 0, 2, 4 ], [ 6, 8, 10 ] ]
+
+ See Also
+ --------
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
new file mode 100644
index 000000000000..fdecb803d240
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
@@ -0,0 +1,51 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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.
+*/
+
+// TypeScript Version: 4.1
+
+import { Shape2D } from '@stdlib/types/ndarray';
+
+/**
+* Two-dimensional nested array.
+*/
+type Array2D = Array>;
+
+/**
+* Generates a linearly spaced two-dimensional nested numeric array.
+*
+* @param start - first array value
+* @param stop - last array value
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
+* @returns {Array} linearly spaced numeric array
+*
+* @example
+* var linspace2d = require( '@stdlib/array/base/linspace2d' );
+*
+* var x = linspace2d( 0, 100, [ 2, 3 ], false );
+* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
+
+* x = linspace2d( 0, 100, [ 2, 3 ], true );
+* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
+*/
+declare function linspace2d( start: number, end: number, shape: Shape2D, colexicographic: boolean ): Array2D;
+
+
+// EXPORTS //
+
+export = linspace2d;
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/test.ts
new file mode 100644
index 000000000000..03545e0a546d
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/test.ts
@@ -0,0 +1,71 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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.
+*/
+
+import linspace2d = require( './index' );
+
+
+// TESTS //
+
+// The function returns an array of arrays...
+{
+ linspace2d( 0, 11, [ 2, 3 ], false ); // $ExpectType Array2D
+}
+
+// The compiler throws an error if the function is provided values other than two numbers for the first two parameters...
+{
+ linspace2d( true, 10, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( false, 10, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( '5', 10, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( [], 10, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( {}, 10, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( ( x: number ): number => x, 10, [ 2, 3 ], false ); // $ExpectError
+
+ linspace2d( 9, true, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( 9, false, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( 5, '5', [ 2, 3 ], false ); // $ExpectError
+ linspace2d( 8, [], [ 2, 3 ], false ); // $ExpectError
+ linspace2d( 9, {}, [ 2, 3 ], false ); // $ExpectError
+ linspace2d( 8, ( x: number ): number => x, [ 2, 3 ], false ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a value other than an array of numbers for the third parameter...
+{
+ linspace2d( 3, 20, true, false ); // $ExpectError
+ linspace2d( 4, 20, false, false ); // $ExpectError
+ linspace2d( 2, 20, '5', false ); // $ExpectError
+ linspace2d( 2, 20, [], false ); // $ExpectError
+ linspace2d( 9, 20, {}, false ); // $ExpectError
+ linspace2d( 9, 20, ( x: number ): number => x, false ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a value other than a boolean for the fourth parameter...
+{
+ linspace2d( 3, 20, [ 2, 3 ], false, '5' ); // $ExpectError
+ linspace2d( 4, 20, [ 2, 3 ], false, 2 ); // $ExpectError
+ linspace2d( 2, 20, [ 2, 3 ], false, [] ); // $ExpectError
+ linspace2d( 2, 20, [ 2, 3 ], false, {} ); // $ExpectError
+ linspace2d( 9, 20, [ 2, 3 ], ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided insufficient arguments...
+{
+ linspace2d(); // $ExpectError
+ linspace2d( 3, 20 ); // $ExpectError
+ linspace2d( 3, 20, [ 2, 3 ] ); // $ExpectError
+ linspace2d( 3, 20, [ 2, 3 ], false, {} ); // $ExpectError
+}
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/examples/index.js b/lib/node_modules/@stdlib/array/base/linspace2d/examples/index.js
new file mode 100644
index 000000000000..a4f07ee8f423
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/examples/index.js
@@ -0,0 +1,34 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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';
+
+var linspace2d = require( './../lib' );
+
+var out = linspace2d( 0, 10, [ 2, 5 ], false );
+console.log( out );
+
+out = linspace2d( 0, 10, [ 2, 3 ], true );
+console.log( out );
+
+out = linspace2d( 0, 10, [ 4, 2 ], true );
+console.log( out );
+
+// Create an array with decremented values:
+out = linspace2d( 10, 0, [ 2, 5 ], false );
+console.log( out );
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
new file mode 100644
index 000000000000..afd88d1cbf24
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
@@ -0,0 +1,43 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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';
+
+/**
+* Generate a linearly spaced two-dimensional nested numeric array.
+*
+* @module @stdlib/array/base/linspace2d
+*
+* @example
+* var linspace2d = require( '@stdlib/array/base/linspace2d' );
+*
+* var x = linspace2d( 0, 100, [ 2, 3 ], false );
+* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
+
+* x = linspace2d( 0, 100, [ 2, 3 ], true );
+* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
+*/
+
+// MODULES //
+
+var main = require( './main.js' );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
new file mode 100644
index 000000000000..30585a37d257
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -0,0 +1,84 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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 zeros2d = require( '@stdlib/array/base/zeros2d' );
+var linspace = require( '@stdlib/array/base/linspace' );
+
+
+// MAIN //
+
+/**
+* Generates a linearly spaced two-dimensional nested numeric array.
+*
+* @param {number} x1 - first array value
+* @param {number} x2 - last array value
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
+* @returns {Array} linearly spaced numeric array
+*
+* @example
+* var x = linspace2d( 0, 100, [ 2, 3 ], false );
+* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
+
+* x = linspace2d( 0, 100, [ 2, 3 ], true );
+* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
+*/
+function linspace2d( x1, x2, shape, colexicographic ) {
+ var out;
+ var arr;
+ var s0;
+ var i0;
+ var s1;
+ var i1;
+ var n;
+
+ s0 = shape[ 1 ];
+ s1 = shape[ 0 ];
+
+ n = s0 * s1;
+ if ( n === 0 ) {
+ return [];
+ }
+
+ arr = linspace( x1, x2, n );
+ out = zeros2d( shape );
+
+ if ( colexicographic ) {
+ for ( i1 = 0; i1 < s1; i1++ ) {
+ for ( i0 = 0; i0 < s0; i0++ ) {
+ out[ i1 ][ i0 ] = arr[ i0 * s1 + i1 ];
+ }
+ }
+ } else {
+ for ( i1 = 0; i1 < s1; i1++ ) {
+ for ( i0 = 0; i0 < s0; i0++ ) {
+ out[ i1 ][ i0 ] = arr[ i1 * s0 + i0 ];
+ }
+ }
+ }
+ return out;
+}
+
+
+// EXPORTS //
+
+module.exports = linspace2d;
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/package.json b/lib/node_modules/@stdlib/array/base/linspace2d/package.json
new file mode 100644
index 000000000000..42d31cfc8ced
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/package.json
@@ -0,0 +1,67 @@
+{
+ "name": "@stdlib/array/base/linspace2d",
+ "version": "0.0.0",
+ "description": "Generate a linearly spaced two-dimensional nested numeric array.",
+ "license": "Apache-2.0",
+ "author": {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ },
+ "contributors": [
+ {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ }
+ ],
+ "main": "./lib",
+ "directories": {
+ "benchmark": "./benchmark",
+ "doc": "./docs",
+ "example": "./examples",
+ "lib": "./lib",
+ "test": "./test"
+ },
+ "types": "./docs/types",
+ "scripts": {},
+ "homepage": "https://github.com/stdlib-js/stdlib",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/stdlib-js/stdlib.git"
+ },
+ "bugs": {
+ "url": "https://github.com/stdlib-js/stdlib/issues"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.10.0",
+ "npm": ">2.7.0"
+ },
+ "os": [
+ "aix",
+ "darwin",
+ "freebsd",
+ "linux",
+ "macos",
+ "openbsd",
+ "sunos",
+ "win32",
+ "windows"
+ ],
+ "keywords": [
+ "stdlib",
+ "stdmath",
+ "utilities",
+ "utils",
+ "mathematics",
+ "math",
+ "generic",
+ "array",
+ "array2d",
+ "matlab",
+ "linear",
+ "linspace",
+ "linspace2d",
+ "nested"
+ ]
+}
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/test/test.js b/lib/node_modules/@stdlib/array/base/linspace2d/test/test.js
new file mode 100644
index 000000000000..9e82fc8a9aa7
--- /dev/null
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/test/test.js
@@ -0,0 +1,105 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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 tape = require( 'tape' );
+var isArrayArray = require( '@stdlib/assert/is-array-array' );
+var linspace2d = require( './../lib' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof linspace2d, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function returns a linearly spaced two-dimensional nested array', function test( t ) {
+ var expected;
+ var actual;
+ var start;
+ var stop;
+ var sh;
+
+ start = 0;
+ stop = 10;
+ sh = [ 2, 3 ];
+
+ actual = linspace2d( start, stop, sh, false );
+
+ // Verify that the output is a nested array:
+ t.strictEqual( isArrayArray( actual ), true, 'returns expected value' );
+
+ // Verify that the returned array includes the start and stop values:
+ t.strictEqual( actual[0][0], start, 'returns expected value' );
+ t.strictEqual( actual[actual.length-1][2], 10, 'returns expected value' );
+
+ // Verify correct values:
+ actual = linspace2d( 0, 100, sh, false );
+ expected = [ [ 0, 20, 40 ], [ 60, 80, 100 ] ];
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ // Decrement:
+ actual = linspace2d( 100, 0, sh, false );
+ expected = [ [ 100, 80, 60 ], [ 40, 20, 0 ] ];
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns a linearly spaced two-dimensional nested array (colexicographic)', function test( t ) {
+ var expected;
+ var actual;
+ var start;
+ var stop;
+ var sh;
+
+ start = 0;
+ stop = 10;
+ sh = [ 2, 3 ];
+
+ actual = linspace2d( start, stop, sh, true );
+
+ // Verify that the output is a nested array:
+ t.strictEqual( isArrayArray( actual ), true, 'returns expected value' );
+
+ // Verify that the returned array includes the start and stop values:
+ t.strictEqual( actual[0][0], start, 'returns expected value' );
+ t.strictEqual( actual[actual.length-1][2], 10, 'returns expected value' );
+
+ // Verify correct values:
+ actual = linspace2d( 0, 100, sh, true );
+ expected = [ [ 0, 40, 80 ], [ 20, 60, 100 ] ];
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ // Decrement:
+ actual = linspace2d( 100, 0, sh, true );
+ expected = [ [ 100, 60, 20 ], [ 80, 40, 0 ] ];
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns an empty array if the product of the number of rows and columns is `0`', function test( t ) {
+ t.deepEqual( linspace2d( 0, 10, [ 2, 0 ], false ), [], 'returns expected value' );
+ t.end();
+});
From 19f11f5c6380b244953ae11359b1503202665462 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 16:44:55 +0000
Subject: [PATCH 02/15] fix: idx and docs
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
.../array/base/linspace2d/docs/types/index.d.ts | 10 +++++-----
.../@stdlib/array/base/linspace2d/lib/main.js | 16 ++++++++++------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
index fdecb803d240..459c4f6a5a58 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
@@ -30,20 +30,20 @@ type Array2D = Array>;
*
* @param start - first array value
* @param stop - last array value
-* @param {NonNegativeIntegerArray} shape - array shape
-* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
-* @returns {Array} linearly spaced numeric array
+* @param shape - array shape
+* @param colexicographic - specifies whether the array values should be in colexicographic order
+* @returns linearly spaced numeric array
*
* @example
* var linspace2d = require( '@stdlib/array/base/linspace2d' );
*
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
-
+*
* x = linspace2d( 0, 100, [ 2, 3 ], true );
* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
*/
-declare function linspace2d( start: number, end: number, shape: Shape2D, colexicographic: boolean ): Array2D;
+declare function linspace2d( start: number, stop: number, shape: Shape2D, colexicographic: boolean ): Array2D;
// EXPORTS //
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 30585a37d257..900b20316688 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -29,8 +29,8 @@ var linspace = require( '@stdlib/array/base/linspace' );
/**
* Generates a linearly spaced two-dimensional nested numeric array.
*
-* @param {number} x1 - first array value
-* @param {number} x2 - last array value
+* @param {number} start - first array value
+* @param {number} stop - last array value
* @param {NonNegativeIntegerArray} shape - array shape
* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
* @returns {Array} linearly spaced numeric array
@@ -42,9 +42,10 @@ var linspace = require( '@stdlib/array/base/linspace' );
* x = linspace2d( 0, 100, [ 2, 3 ], true );
* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
*/
-function linspace2d( x1, x2, shape, colexicographic ) {
+function linspace2d( start, stop, shape, colexicographic ) {
var out;
var arr;
+ var idx;
var s0;
var i0;
var s1;
@@ -59,19 +60,22 @@ function linspace2d( x1, x2, shape, colexicographic ) {
return [];
}
- arr = linspace( x1, x2, n );
+ arr = linspace( start, stop, n );
out = zeros2d( shape );
+ idx = 0;
if ( colexicographic ) {
for ( i1 = 0; i1 < s1; i1++ ) {
for ( i0 = 0; i0 < s0; i0++ ) {
- out[ i1 ][ i0 ] = arr[ i0 * s1 + i1 ];
+ idx = ( i0 * s1 ) + i1;
+ out[ i1 ][ i0 ] = arr[ idx ];
}
}
} else {
for ( i1 = 0; i1 < s1; i1++ ) {
for ( i0 = 0; i0 < s0; i0++ ) {
- out[ i1 ][ i0 ] = arr[ i1 * s0 + i0 ];
+ idx = ( i1 * s0 ) + i0;
+ out[ i1 ][ i0 ] = arr[ idx ];
}
}
}
From 7c179b10c767bdb305996fc150d63147ec507e17 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 21:47:48 +0500
Subject: [PATCH 03/15] docs: apply suggestions from code review
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
lib/node_modules/@stdlib/array/base/linspace2d/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
index babc2b5712a1..80eaea6d68d4 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/README.md
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -50,7 +50,7 @@ x = linspace2d( 0, 100, [ 2, 3 ], true );
## Notes
-- The function assumes that the product of number of rows and columns is greater than or equal to `2`.
+- The function assumes that the product of the number of rows and columns is greater than or equal to `2`.
- The output `array` is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
From 159c7fb2981a7d142005308aef353d871d230dc3 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 21:50:47 +0500
Subject: [PATCH 04/15] docs: apply suggestions from code review
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
index c31943313c36..c64c45a158d4 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
@@ -16,7 +16,7 @@
Array shape.
colexicographic: boolean
- specifies whether the array values should be in colexicographic order
+ Specifies whether the array values should be in colexicographic order
Returns
-------
From cf48e17a84a3b585aacabfb82a04f75067db74b1 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 21:53:53 +0500
Subject: [PATCH 05/15] fix: apply suggestions from code review
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
.../@stdlib/array/base/linspace2d/benchmark/benchmark.size.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
index 3964b6193c6b..997c4ac02238 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/benchmark/benchmark.size.js
@@ -76,9 +76,9 @@ function createBenchmark( N ) {
* @private
*/
function main() {
- var N;
var min;
var max;
+ var N;
var f;
var i;
From 4358c3e926185b3caf16853d019b658e9e5d0ec2 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 21:56:19 +0500
Subject: [PATCH 06/15] docs: apply suggestions from code review
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
.../@stdlib/array/base/linspace2d/docs/types/index.d.ts | 2 +-
lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
index 459c4f6a5a58..1c5823d40d3d 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
@@ -32,7 +32,7 @@ type Array2D = Array>;
* @param stop - last array value
* @param shape - array shape
* @param colexicographic - specifies whether the array values should be in colexicographic order
-* @returns linearly spaced numeric array
+* @returns linearly spaced two-dimensional nested numeric array
*
* @example
* var linspace2d = require( '@stdlib/array/base/linspace2d' );
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 900b20316688..14ec90fd86c2 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -33,7 +33,7 @@ var linspace = require( '@stdlib/array/base/linspace' );
* @param {number} stop - last array value
* @param {NonNegativeIntegerArray} shape - array shape
* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
-* @returns {Array} linearly spaced numeric array
+* @returns {Array} linearly spaced two-dimensional nested numeric array
*
* @example
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
From 58040669318ff464e0edbf253e9b9480df1301d9 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 17:17:49 +0000
Subject: [PATCH 07/15] refactor: remove the extra loop
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
.../@stdlib/array/base/linspace2d/lib/main.js | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 14ec90fd86c2..8dd8655c6682 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -63,20 +63,14 @@ function linspace2d( start, stop, shape, colexicographic ) {
arr = linspace( start, stop, n );
out = zeros2d( shape );
idx = 0;
-
- if ( colexicographic ) {
- for ( i1 = 0; i1 < s1; i1++ ) {
- for ( i0 = 0; i0 < s0; i0++ ) {
+ for ( i1 = 0; i1 < s1; i1++ ) {
+ for ( i0 = 0; i0 < s0; i0++ ) {
+ if ( colexicographic ) {
idx = ( i0 * s1 ) + i1;
- out[ i1 ][ i0 ] = arr[ idx ];
- }
- }
- } else {
- for ( i1 = 0; i1 < s1; i1++ ) {
- for ( i0 = 0; i0 < s0; i0++ ) {
+ } else {
idx = ( i1 * s0 ) + i0;
- out[ i1 ][ i0 ] = arr[ idx ];
}
+ out[ i1 ][ i0 ] = arr[ idx ];
}
}
return out;
From c72a036549ae653b95cd481aae4ca48d4b619e59 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 26 Feb 2025 17:26:52 +0000
Subject: [PATCH 08/15] refactor: optimize the function
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
.../@stdlib/array/base/linspace2d/lib/main.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 8dd8655c6682..319264f81108 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -21,7 +21,6 @@
// MODULES //
var zeros2d = require( '@stdlib/array/base/zeros2d' );
-var linspace = require( '@stdlib/array/base/linspace' );
// MAIN //
@@ -44,12 +43,12 @@ var linspace = require( '@stdlib/array/base/linspace' );
*/
function linspace2d( start, stop, shape, colexicographic ) {
var out;
- var arr;
var idx;
var s0;
var i0;
var s1;
var i1;
+ var d;
var n;
s0 = shape[ 1 ];
@@ -60,9 +59,10 @@ function linspace2d( start, stop, shape, colexicographic ) {
return [];
}
- arr = linspace( start, stop, n );
+ d = ( stop - start ) / ( n - 1 );
out = zeros2d( shape );
idx = 0;
+
for ( i1 = 0; i1 < s1; i1++ ) {
for ( i0 = 0; i0 < s0; i0++ ) {
if ( colexicographic ) {
@@ -70,7 +70,7 @@ function linspace2d( start, stop, shape, colexicographic ) {
} else {
idx = ( i1 * s0 ) + i0;
}
- out[ i1 ][ i0 ] = arr[ idx ];
+ out[ i1 ][ i0 ] = start + ( idx * d );
}
}
return out;
From dd68407ece6e77268810a842940a6b445fe5d6d6 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Mon, 7 Apr 2025 16:53:23 +0000
Subject: [PATCH 09/15] docs: refactor readme
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/array/base/linspace2d/README.md | 27 ++++++++++++-------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
index 80eaea6d68d4..61425b531de2 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/README.md
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -42,6 +42,13 @@ x = linspace2d( 0, 100, [ 2, 3 ], true );
// returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
```
+The function accepts the following arguments:
+
+- **start**: First array value.
+- **stop**: Last array value.
+- **shape**: Array shape.
+- **colexicographic**: Specifies whether generated array values should be stored in colexicographic order.
+
@@ -63,19 +70,19 @@ x = linspace2d( 0, 100, [ 2, 3 ], true );
```javascript
var roundn = require( '@stdlib/math/base/special/roundn' );
+ var map2d = require( '@stdlib/array/base/map2d' );
// Create an array subject to floating-point rounding errors:
- var arr = linspace( 0, 10, [ 3, 3 ], false );
-
- // Round each value to the nearest hundredth:
- var i;
- var j;
- for ( i = 0; i < arr.length; i++ ) {
- for ( j = 0; j < arr[i].length; j++ ) {
- arr[ i ][ j ] = roundn( arr[ i ][ j ], -2 );
- }
+ var arr = linspace2d( 0, 11, [ 3, 3 ], false );
+ // returns [ [ 0, 1.375, 2.75 ], [ 4.125, 5.5, 6.875 ], [ 8.25, 9.625, 11 ] ]
+
+ // Round each value to the nearest tenth:
+ var out = map2d( arr, [ 3, 3 ], clbk );
+ // returns [ [ 0, 1.4, 2.8 ], [ 4.1, 5.5, 6.9 ], [ 8.3, 9.6, 11 ] ]
+
+ function clbk( v ) {
+ return roundn( v, -1 );
}
- console.log( arr.join( '\n' ) );
```
From 254a0175ce1511c3c9508d941ce1f0eff50b0926 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Mon, 7 Apr 2025 16:57:14 +0000
Subject: [PATCH 10/15] refactor: apply suggestions from code review
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt | 3 ++-
.../@stdlib/array/base/linspace2d/docs/types/index.d.ts | 4 +---
lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js | 2 +-
lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js | 2 +-
4 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
index c64c45a158d4..5a81829026f7 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/repl.txt
@@ -16,7 +16,8 @@
Array shape.
colexicographic: boolean
- Specifies whether the array values should be in colexicographic order
+ Specifies whether generated array values should be stored in
+ colexicographic order.
Returns
-------
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
index 1c5823d40d3d..7d7589090437 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/docs/types/index.d.ts
@@ -31,12 +31,10 @@ type Array2D = Array>;
* @param start - first array value
* @param stop - last array value
* @param shape - array shape
-* @param colexicographic - specifies whether the array values should be in colexicographic order
+* @param colexicographic - specifies whether generated array values should be stored in colexicographic order
* @returns linearly spaced two-dimensional nested numeric array
*
* @example
-* var linspace2d = require( '@stdlib/array/base/linspace2d' );
-*
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
*
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
index afd88d1cbf24..e7ea2553250a 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/index.js
@@ -28,7 +28,7 @@
*
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
-
+*
* x = linspace2d( 0, 100, [ 2, 3 ], true );
* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
*/
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 319264f81108..3653037817e5 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -31,7 +31,7 @@ var zeros2d = require( '@stdlib/array/base/zeros2d' );
* @param {number} start - first array value
* @param {number} stop - last array value
* @param {NonNegativeIntegerArray} shape - array shape
-* @param {boolean} colexicographic - specifies whether the array values should be in colexicographic order
+* @param {boolean} colexicographic - specifies whether generated array values should be stored in colexicographic order
* @returns {Array} linearly spaced two-dimensional nested numeric array
*
* @example
From 6fdf82f0da5dea0d87ba83b28c49788e98fc2f23 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Mon, 7 Apr 2025 17:21:10 +0000
Subject: [PATCH 11/15] refactor: make single pass
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/array/base/linspace2d/lib/main.js | 21 ++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 3653037817e5..001dd3e15307 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -37,11 +37,13 @@ var zeros2d = require( '@stdlib/array/base/zeros2d' );
* @example
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
-
+*
* x = linspace2d( 0, 100, [ 2, 3 ], true );
* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
*/
function linspace2d( start, stop, shape, colexicographic ) {
+ var inc0;
+ var inc1;
var out;
var idx;
var s0;
@@ -61,17 +63,22 @@ function linspace2d( start, stop, shape, colexicographic ) {
d = ( stop - start ) / ( n - 1 );
out = zeros2d( shape );
- idx = 0;
+ if ( colexicographic ) {
+ inc0 = s1;
+ inc1 = 1;
+ } else {
+ inc0 = 1;
+ inc1 = s0;
+ }
+
+ idx = 0;
for ( i1 = 0; i1 < s1; i1++ ) {
for ( i0 = 0; i0 < s0; i0++ ) {
- if ( colexicographic ) {
- idx = ( i0 * s1 ) + i1;
- } else {
- idx = ( i1 * s0 ) + i0;
- }
out[ i1 ][ i0 ] = start + ( idx * d );
+ idx += inc0;
}
+ idx += inc1 - ( s0 * inc0 );
}
return out;
}
From 237c3d1308ac1ead8b8e01dfdcf6d2829a6cd505 Mon Sep 17 00:00:00 2001
From: Athan
Date: Tue, 8 Apr 2025 22:43:32 -0700
Subject: [PATCH 12/15] Apply suggestions from code review
Signed-off-by: Athan
---
.../@stdlib/array/base/linspace2d/README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
index 61425b531de2..faa6e67b2349 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/README.md
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -44,10 +44,10 @@ x = linspace2d( 0, 100, [ 2, 3 ], true );
The function accepts the following arguments:
-- **start**: First array value.
-- **stop**: Last array value.
-- **shape**: Array shape.
-- **colexicographic**: Specifies whether generated array values should be stored in colexicographic order.
+- **start**: first array value.
+- **stop**: last array value.
+- **shape**: array shape.
+- **colexicographic**: specifies whether generated array values should be stored in colexicographic order.
@@ -59,7 +59,7 @@ The function accepts the following arguments:
- The function assumes that the product of the number of rows and columns is greater than or equal to `2`.
-- The output `array` is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
+- The output array is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
```javascript
var arr = linspace2d( 0, 10, [ 2, 2 ], false );
From 093808f98ad8e66862035f49231f571dec0f157f Mon Sep 17 00:00:00 2001
From: Athan
Date: Tue, 8 Apr 2025 23:32:32 -0700
Subject: [PATCH 13/15] refactor: create the output array in a single pass
Signed-off-by: Athan
---
.../@stdlib/array/base/linspace2d/lib/main.js | 25 ++++++++-----------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
index 001dd3e15307..a0e8c73fdfbd 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/lib/main.js
@@ -18,11 +18,6 @@
'use strict';
-// MODULES //
-
-var zeros2d = require( '@stdlib/array/base/zeros2d' );
-
-
// MAIN //
/**
@@ -45,6 +40,7 @@ function linspace2d( start, stop, shape, colexicographic ) {
var inc0;
var inc1;
var out;
+ var tmp;
var idx;
var s0;
var i0;
@@ -60,25 +56,24 @@ function linspace2d( start, stop, shape, colexicographic ) {
if ( n === 0 ) {
return [];
}
-
d = ( stop - start ) / ( n - 1 );
- out = zeros2d( shape );
-
if ( colexicographic ) {
- inc0 = s1;
- inc1 = 1;
+ inc0 = s1; // index increment for the innermost loop
+ inc1 = 1 - ( s0 * inc0 ); // index increment for the outermost loop
} else {
- inc0 = 1;
- inc1 = s0;
+ inc0 = 1; // index increment for the innermost loop
+ inc1 = 0; // index increment for the outermost loop
}
-
+ out = [];
idx = 0;
for ( i1 = 0; i1 < s1; i1++ ) {
+ tmp = [];
for ( i0 = 0; i0 < s0; i0++ ) {
- out[ i1 ][ i0 ] = start + ( idx * d );
+ tmp.push( start + ( idx * d ) );
idx += inc0;
}
- idx += inc1 - ( s0 * inc0 );
+ out.push( tmp );
+ idx += inc1;
}
return out;
}
From 6a8dac4fd4b7897b801d2138439008e791c4800f Mon Sep 17 00:00:00 2001
From: Athan
Date: Tue, 8 Apr 2025 23:42:54 -0700
Subject: [PATCH 14/15] docs: demonstrate floating-point rounding error
Signed-off-by: Athan
---
.../@stdlib/array/base/linspace2d/README.md | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
index faa6e67b2349..f6938fc4cbb3 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/README.md
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -62,23 +62,22 @@ The function accepts the following arguments:
- The output array is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
```javascript
- var arr = linspace2d( 0, 10, [ 2, 2 ], false );
- // returns [ [ 0, 3.3333333333333335 ], [ 6.666666666666667, 10 ] ]
+ var arr = linspace2d( 0, 1, [ 1, 3 ], false );
+ // returns [ [ 0, ~0.5, 1 ] ]
```
- If you desire more control over element precision, consider using [`roundn`][@stdlib/math/base/special/roundn]:
+ where `arr[0][1]` is only guaranteed to be approximately equal to `0.5`. If you desire more control over element precision, consider using [`roundn`][@stdlib/math/base/special/roundn]:
```javascript
var roundn = require( '@stdlib/math/base/special/roundn' );
var map2d = require( '@stdlib/array/base/map2d' );
- // Create an array subject to floating-point rounding errors:
- var arr = linspace2d( 0, 11, [ 3, 3 ], false );
- // returns [ [ 0, 1.375, 2.75 ], [ 4.125, 5.5, 6.875 ], [ 8.25, 9.625, 11 ] ]
+ var arr = linspace2d( 0, 1, [ 1, 3 ], false );
+ // returns [ [ 0, ~0.5, 1 ] ]
// Round each value to the nearest tenth:
- var out = map2d( arr, [ 3, 3 ], clbk );
- // returns [ [ 0, 1.4, 2.8 ], [ 4.1, 5.5, 6.9 ], [ 8.3, 9.6, 11 ] ]
+ var out = map2d( arr, [ 1, 3 ], clbk );
+ // returns [ [ 0, 0.5, 1 ] ]
function clbk( v ) {
return roundn( v, -1 );
From 6cb219613f5a96e349345ccf0be909545a8e6a0f Mon Sep 17 00:00:00 2001
From: Athan
Date: Tue, 8 Apr 2025 23:47:13 -0700
Subject: [PATCH 15/15] docs: remove note
Signed-off-by: Athan
---
lib/node_modules/@stdlib/array/base/linspace2d/README.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/lib/node_modules/@stdlib/array/base/linspace2d/README.md b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
index f6938fc4cbb3..db2cdf5f6941 100644
--- a/lib/node_modules/@stdlib/array/base/linspace2d/README.md
+++ b/lib/node_modules/@stdlib/array/base/linspace2d/README.md
@@ -57,8 +57,6 @@ The function accepts the following arguments:
## Notes
-- The function assumes that the product of the number of rows and columns is greater than or equal to `2`.
-
- The output array is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
```javascript