From e3c3225c197b98ec36cccf41cd48f5c4d2cce349 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Sat, 21 Mar 2026 12:12:20 +0200 Subject: [PATCH 1/7] feat: add initial implementation --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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 --- --- .../@stdlib/ndarray/base/eye/README.md | 137 ++++++++++++++++++ .../ndarray/base/eye/examples/index.js | 28 ++++ .../@stdlib/ndarray/base/eye/lib/index.js | 51 +++++++ .../@stdlib/ndarray/base/eye/lib/main.js | 130 +++++++++++++++++ .../@stdlib/ndarray/base/eye/package.json | 60 ++++++++ .../@stdlib/ndarray/base/eye/test/test.js | 33 +++++ 6 files changed, 439 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/README.md b/lib/node_modules/@stdlib/ndarray/base/eye/README.md new file mode 100644 index 000000000000..f443c79a73da --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/README.md @@ -0,0 +1,137 @@ + + +# eye + +> Create a two-dimensional array with ones on the kth diagonal and zeros elsewhere + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var eye = require( '@stdlib/ndarray/base/eye' ); +``` + +#### eye( dtype, rows, cols, k, order ) + +Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. + +```javascript +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); + +var x = eye( 'float64', 3, 3, 0, 'row-major'); +// returns + +var sh = getShape( x ); +// returns [ 3, 3 ] + +var dt = String( getDType( x ) ); +// returns 'float64' + +var v = x.get( 0, 0 ); +// returns 1.0 +``` + +The function accepts the following arguments: + +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. +- **rows**: number of rows. +- **cols**: number of columns. +- **k**: diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal. +- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). + + +
+ + + + + +
+ +## Notes + + +
+ + + + + +
+ +## Examples + + + +```javascript +var eye = require( '@stdlib/ndarray/base/eye' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = eye( 'float64', 3, 3, 1, 'row-major'); +console.log( ndarray2array( x ) ); + +x = eye( 'complex64', 3, 3, 1, 'row-major'); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/eye/examples/index.js new file mode 100644 index 000000000000..5cabec628648 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/examples/index.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var eye = require( './../lib' ); + +var x = eye( 'float64', 3, 3, 0, 'row-major'); +console.log( ndarray2array( x ) ); + +x = eye( 'complex64', 3, 3, 0, 'row-major'); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js new file mode 100644 index 000000000000..ab8e4ffcec5e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Create a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* @module @stdlib/ndarray/base/eye +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var eye = require( '@stdlib/ndarray/base/eye' ); +* +* var x = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = getShape( x ); +* // returns [ 3, 3 ] +* +* var dt = String( getDType( x ) ); +* // returns 'float64' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js new file mode 100644 index 000000000000..efbe4e6bbb48 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); +var ctorComplex = require( '@stdlib/complex/ctors' ); +var max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); + + +// FUNCTIONS // + +/** +* Default buffer setter function. +* +* @private +* @param {ArrayBufferLike} buf - array buffer +* @param {Number} idx - array index +* @param {Number|ComplexLike} v - value +*/ +function setter( buf, idx, v ) { + buf[ idx ] = v; +} + + +// MAIN // + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* @param {*} dtype - output array data type +* @param {Number} rows - output array number of rows +* @param {Number} cols - output array number of columns +* @param {Number} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param {string} order - memory layout (either row-major or column-major) +* @returns {ndarray} ndarray +* +* @example +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = getShape( x ); +* // returns [ 3, 3 ] +* +* var dt = String( getDType( x ) ); +* // returns 'float64' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ +function eye( dtype, rows, cols, k, order ) { + var ctor; + var tmp; + var len; + var buf; + var set; + var sr; + var sc; + var ix; + var dx; + var i; + var v; + var r; + var c; + var x; + + x = zeros( dtype, [ rows, cols ], order ); + + if ( isComplexDataType( x.dtype ) ) { + ctor = ctorComplex( x.dtype ); + v = new ctor( 1.0, 0.0 ); + } else { + v = 1.0; + } + + // TODO: Use better approach instead of allocating a new object + tmp = ndarray2object( x ); + if ( tmp.accessorProtocol === true ) { + set = tmp.accessors[1]; + } else { + set = setter; + } + + if ( k < 0 ) { + r = -k; + c = 0; + } else { + r = 0; + c = k; + } + len = max( 0, min( rows - r, cols - c ) ); + + sr = x.strides[ 0 ]; + sc = x.strides[ 1 ]; + ix = x.offset + (r * sr) + (c * sc); // offset + (row * row_stride) + (col * col_stride) + dx = sr + sc; + + buf = x.data; + for ( i = 0; i < len; i++ ) { + set( buf, ix, v ); + ix += dx; + } + + return x; +} + +module.exports = eye; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/package.json b/lib/node_modules/@stdlib/ndarray/base/eye/package.json new file mode 100644 index 000000000000..8ad9acbb51ee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/package.json @@ -0,0 +1,60 @@ +{ + "name": "@stdlib/ndarray/base/eye", + "version": "0.0.0", + "description": "Create a two dimensional array with ones on the kth diagonal and zeros elsewhere.", + "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": { + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "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", + "stdtypes", + "types", + "base", + "data", + "structure", + "ndarray", + "matrix", + "identity", + "diag" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js new file mode 100644 index 000000000000..4738977eba5e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 eye = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof eye, 'function', 'main export is a function' ); + t.end(); +}); From 3554f06a3aed560d9955dcc9257014c4d4dd6f2a Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Sun, 22 Mar 2026 23:10:16 +0200 Subject: [PATCH 2/7] refactor: remove useless ndarray to object conversion --- .../@stdlib/ndarray/base/eye/lib/main.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js index efbe4e6bbb48..9a84474d3926 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js @@ -20,9 +20,10 @@ // MODULES // -var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); +var accessorSetter = require( '@stdlib/array/base/accessor-setter' ); var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); -var ctorComplex = require( '@stdlib/complex/ctors' ); +var ctors = require( '@stdlib/complex/ctors' ); var max = require( '@stdlib/math/base/special/max' ); var min = require( '@stdlib/math/base/special/min' ); var zeros = require( '@stdlib/ndarray/base/zeros' ); @@ -73,7 +74,6 @@ function setter( buf, idx, v ) { */ function eye( dtype, rows, cols, k, order ) { var ctor; - var tmp; var len; var buf; var set; @@ -87,23 +87,6 @@ function eye( dtype, rows, cols, k, order ) { var c; var x; - x = zeros( dtype, [ rows, cols ], order ); - - if ( isComplexDataType( x.dtype ) ) { - ctor = ctorComplex( x.dtype ); - v = new ctor( 1.0, 0.0 ); - } else { - v = 1.0; - } - - // TODO: Use better approach instead of allocating a new object - tmp = ndarray2object( x ); - if ( tmp.accessorProtocol === true ) { - set = tmp.accessors[1]; - } else { - set = setter; - } - if ( k < 0 ) { r = -k; c = 0; @@ -111,14 +94,29 @@ function eye( dtype, rows, cols, k, order ) { r = 0; c = k; } - len = max( 0, min( rows - r, cols - c ) ); + + x = zeros( dtype, [ rows, cols ], order ); sr = x.strides[ 0 ]; sc = x.strides[ 1 ]; ix = x.offset + (r * sr) + (c * sc); // offset + (row * row_stride) + (col * col_stride) dx = sr + sc; + if ( isAccessorArray( x.data ) ) { + set = accessorSetter( dtype ); + } else { + set = setter; + } buf = x.data; + len = max( 0, min( rows - r, cols - c ) ); + + if ( isComplexDataType( dtype ) ) { + ctor = ctors( dtype ); + v = new ctor( 1.0, 0.0 ); + } else { + v = 1.0; + } + for ( i = 0; i < len; i++ ) { set( buf, ix, v ); ix += dx; From ab7bc6290888d6f39b24815177f5fa781c02d2f8 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 23 Mar 2026 01:15:45 +0200 Subject: [PATCH 3/7] feat: add tests and update main and readme accordingly --- .../@stdlib/ndarray/base/eye/README.md | 3 + .../@stdlib/ndarray/base/eye/lib/main.js | 20 +- .../@stdlib/ndarray/base/eye/test/test.js | 607 ++++++++++++++++++ 3 files changed, 627 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/README.md b/lib/node_modules/@stdlib/ndarray/base/eye/README.md index f443c79a73da..6292aec9367c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/eye/README.md @@ -80,6 +80,9 @@ The function accepts the following arguments: ## Notes +- If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero + +- If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js index 9a84474d3926..06681ded5303 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js @@ -23,9 +23,12 @@ var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); var accessorSetter = require( '@stdlib/array/base/accessor-setter' ); var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); +var isInteger = require( '@stdlib/assert/is-integer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); var ctors = require( '@stdlib/complex/ctors' ); var max = require( '@stdlib/math/base/special/max' ); var min = require( '@stdlib/math/base/special/min' ); +var format = require( '@stdlib/string/format' ); var zeros = require( '@stdlib/ndarray/base/zeros' ); @@ -50,10 +53,13 @@ function setter( buf, idx, v ) { * Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. * * @param {*} dtype - output array data type -* @param {Number} rows - output array number of rows -* @param {Number} cols - output array number of columns -* @param {Number} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param {NonNegativeInteger} rows - output array number of rows +* @param {NonNegativeInteger} cols - output array number of columns +* @param {IntegerNumber} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal * @param {string} order - memory layout (either row-major or column-major) +* @throws {TypeError} first argument must be a recognized data type +* @throws {TypeError} fourth argument must be an integer +* @throws {TypeError} second and third arguments must be non-negative integers * @returns {ndarray} ndarray * * @example @@ -87,6 +93,14 @@ function eye( dtype, rows, cols, k, order ) { var c; var x; + if ( !isInteger( k ) ) { + throw new TypeError( format('invalid arguments. Diagonal index must be an integer. Value: %s.', k) ); + } + + if ( !isNonNegativeInteger( rows ) || !isNonNegativeInteger( cols ) ) { + throw new TypeError( format('invalid arguments. Rows and columns must be non-negative integers. Value: %s, %s.', rows, cols) ); + } + if ( k < 0 ) { r = -k; c = 0; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js index 4738977eba5e..e3b73b33d9e1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js @@ -21,6 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); var eye = require( './../lib' ); @@ -31,3 +36,605 @@ tape( 'main export is a function', function test( t ) { t.strictEqual( typeof eye, 'function', 'main export is a function' ); t.end(); }); + +tape( 'the function throws an error if provided an invalid data type as the first argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + eye( value, 2, 2, 0, 'row-major' ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid diagonal index as the fourth argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + eye( 'float64', 2, 2, value, 'row-major' ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid rows or columns as the second or third argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + -3.14, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + eye( 'float64', value, value, 0, 'row-major' ); + }; + } +}); + +tape( 'the function returns a zero-filled array when provided zero rows and columns', function test( t ) { + var out; + + out = eye( 'float64', 0, 0, 1, 'row-major' ); + + t.strictEqual( out.dtype, 'float64', 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 0 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array when provided zero rows and columns (accessors)', function test( t ) { + var out; + + out = eye( 'complex128', 0, 0, 1, 'row-major' ); + + t.strictEqual( out.dtype, 'complex128', 'returns expected value' ); + t.deepEqual( out.shape, [ 0, 0 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), new Complex128Array( 0 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array when provided k greater than columns', function test( t ) { + var out; + + out = eye( 'float64', 3, 6, 7, 'row-major' ); + + t.strictEqual( out.dtype, 'float64', 'returns expected value' ); + t.deepEqual( out.shape, [ 3, 6 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 18 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array when provided k less than negative rows', function test( t ) { + var out; + + out = eye( 'float64', 3, 6, -4, 'row-major' ); + + t.strictEqual( out.dtype, 'float64', 'returns expected value' ); + t.deepEqual( out.shape, [ 3, 6 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 18 ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square identity matrix (row-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 2, 2, 0, 'row-major' ); + + expected = new Float64Array([ + 1.0, + 0.0, + 0.0, + 1.0 + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square identity matrix (row-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, 0, 'row-major' ); + + expected = new Complex128Array([ + 1.0, + 0.0, // 1 + 0i + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0 // 1 + 0i + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square identity matrix (column-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 3, 3, 0, 'column-major' ); + + expected = new Float64Array([ + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0 + ]); + + t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square identity matrix (column-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, 0, 'column-major' ); + + expected = new Complex128Array([ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a positive diagonal offset (row-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 3, 3, 1, 'row-major' ); + + expected = new Float64Array([ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a positive diagonal offset (row-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, 1, 'row-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0, // 1 + 0i + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0 // 0 + 0i + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a positive diagonal offset (column-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 3, 3, 1, 'column-major' ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a positive diagonal offset (column-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, 1, 'column-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a negative diagonal offset (row-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 3, 3, -1, 'row-major' ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a negative diagonal offset (row-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, -1, 'row-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0, // 1 + 0i + 0.0, + 0.0 // 0 + 0i + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a negative diagonal offset (column-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 3, 3, -1, 'column-major' ); + + expected = new Float64Array([ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a square matrix with ones on a positive diagonal offset (column-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 2, -1, 'column-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a positive diagonal offset (row-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 2, 3, 1, 'row-major' ); + + expected = new Float64Array([ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a positive diagonal offset (row-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 3, 1, 'row-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 1 + 0i + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0 // 1 + 0i + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a positive diagonal offset (column-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 2, 3, 1, 'column-major' ); + + expected = new Float64Array([ + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 1.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a positive diagonal offset (column-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 3, 1, 'column-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a negative diagonal offset (row-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 2, 3, -1, 'row-major' ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a negative diagonal offset (row-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 3, -1, 'row-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0, // 0 + 0i + 1.0, + 0.0, // 1 + 0i + 0.0, + 0.0, // 0 + 0i + 0.0, + 0.0 // 1 + 0i + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a negative diagonal offset (column-major)', function test( t ) { + var expected; + var out; + + out = eye( 'float64', 2, 3, -1, 'column-major' ); + + expected = new Float64Array([ + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a rectangular matrix with ones on a negative diagonal offset (column-major, accessors)', function test( t ) { + var expected; + var out; + + out = eye( 'complex128', 2, 3, -1, 'column-major' ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + + t.end(); +}); From 7e38ef18b4821176ecff9975765937dfb9461982 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 23 Mar 2026 01:42:27 +0200 Subject: [PATCH 4/7] docs: create docs dir --- .../@stdlib/ndarray/base/eye/README.md | 1 - .../@stdlib/ndarray/base/eye/docs/repl.txt | 44 ++ .../ndarray/base/eye/docs/types/index.d.ts | 445 ++++++++++++++++++ .../ndarray/base/eye/docs/types/test.ts | 120 +++++ .../@stdlib/ndarray/base/eye/package.json | 1 + 5 files changed, 610 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/README.md b/lib/node_modules/@stdlib/ndarray/base/eye/README.md index 6292aec9367c..36e795ba5e98 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/eye/README.md @@ -81,7 +81,6 @@ The function accepts the following arguments: ## Notes - If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero - - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt new file mode 100644 index 000000000000..5a9e24195c9d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( dtype, rows, cols, k, order ) + Creates a two-dimensional array with ones on the kth diagonal and zeros + elsewhere. + + If the provided data type is complex, the function returns an ndarray + whose kth diagonal is filled with complex numbers whose real component + equals one and imaginary component equals zero. + + Parameters + ---------- + dtype: string|DataType + Underlying data type. + + rows: NonNegativeInteger + Number of rows. + + cols: NonNegativeInteger + Number of columns. + + k: integer + Diagonal index. Positive refers to upper diagonal, and negative refers + to lower diagonal. + + order: string + Memory layout (either row-major or column-major). + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var arr = {{alias}}( 'float64', 2, 2, 0, 'row-major' ) + + > var sh = {{alias:@stdlib/ndarray/shape}}( arr ) + [ 2, 2 ] + > var data = {{alias:@stdlib/ndarray/to-array}}( arr ) + [ [ 1, 0 ], [ 0, 1 ] ] + -------- + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts new file mode 100644 index 000000000000..bd512a348e11 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts @@ -0,0 +1,445 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 { Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray, genericndarray, DataType } from '@stdlib/types/ndarray'; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'float64' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ +declare function eye( dtype: 'float64', rows: number, cols: number, k: number, order: Order ): float64ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'float32', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'float32' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ +declare function eye( dtype: 'float32', rows: number, cols: number, k: number, order: Order ): float32ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'complex128', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'complex128' +* +* var v = x.get( 0, 0 ).re; +* // returns 1.0 +*/ +declare function eye( dtype: 'complex128', rows: number, cols: number, k: number, order: Order ): complex128ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'complex64', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'complex64' +* +* var v = x.get( 0, 0 ).re; +* // returns 1.0 +*/ +declare function eye( dtype: 'complex64', rows: number, cols: number, k: number, order: Order ): complex64ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'int32', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'int32' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'int32', rows: number, cols: number, k: number, order: Order ): int32ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'int16', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'int16' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'int16', rows: number, cols: number, k: number, order: Order ): int16ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'int8', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'int8' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'int8', rows: number, cols: number, k: number, order: Order ): int8ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'uint32', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'uint32' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'uint32', rows: number, cols: number, k: number, order: Order ): uint32ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'uint16', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'uint16' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'uint16', rows: number, cols: number, k: number, order: Order ): uint16ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'uint8', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'uint8' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'uint8', rows: number, cols: number, k: number, order: Order ): uint8ndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'uint8c', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'uint8c' +* +* var v = x.get( 0, 0 ); +* // returns 1 +*/ +declare function eye( dtype: 'uint8c', rows: number, cols: number, k: number, order: Order ): uint8cndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'bool', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'bool' +* +* var v = x.get( 0, 0 ); +* // returns true +*/ +declare function eye( dtype: 'bool', rows: number, cols: number, k: number, order: Order ): boolndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'generic', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'generic' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ +declare function eye( dtype: 'generic', rows: number, cols: number, k: number, order: Order ): genericndarray; + +/** +* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* +* ## Notes +* +* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero +* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* +* @param dtype - underlying data type +* @param rows - number of rows +* @param cols - number of columns +* @param k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns output two-dimensional array +* +* @example +* var x = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 3 ] +* +* var dt = x.dtype; +* // returns 'float64' +* +* var v = x.get( 0, 0 ); +* // returns 1.0 +*/ +declare function eye( dtype: DataType, rows: number, cols: number, k: number, order: Order ): typedndarray; + +export = eye; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts new file mode 100644 index 000000000000..2a71709e3582 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts @@ -0,0 +1,120 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 eye = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + eye( 'float64', 2, 2, 0, 'row-major' ); // $ExpectType float64ndarray + eye( 'float32', 2, 2, 0, 'row-major' ); // $ExpectType float32ndarray + eye( 'complex128', 2, 2, 0, 'row-major' ); // $ExpectType complex128ndarray + eye( 'complex64', 2, 2, 0, 'row-major' ); // $ExpectType complex64ndarray + eye( 'int32', 2, 2, 0, 'row-major' ); // $ExpectType int32ndarray + eye( 'int16', 2, 2, 0, 'row-major' ); // $ExpectType int16ndarray + eye( 'int8', 2, 2, 0, 'row-major' ); // $ExpectType int8ndarray + eye( 'uint32', 2, 2, 0, 'row-major' ); // $ExpectType uint32ndarray + eye( 'uint16', 2, 2, 0, 'row-major' ); // $ExpectType uint16ndarray + eye( 'uint8', 2, 2, 0, 'row-major' ); // $ExpectType uint8ndarray + eye( 'uint8c', 2, 2, 0, 'row-major' ); // $ExpectType uint8cndarray + eye( 'bool', 2, 2, 0, 'row-major' ); // $ExpectType boolndarray + eye( 'generic', 2, 2, 0, 'row-major' ); // $ExpectType genericndarray + + eye( 'float64', 2, 2, 0, 'column-major' ); // $ExpectType float64ndarray + eye( 'float32', 2, 2, 0, 'column-major' ); // $ExpectType float32ndarray + eye( 'complex128', 2, 2, 0, 'column-major' ); // $ExpectType complex128ndarray + eye( 'complex64', 2, 2, 0, 'column-major' ); // $ExpectType complex64ndarray + eye( 'int32', 2, 2, 0, 'column-major' ); // $ExpectType int32ndarray + eye( 'int16', 2, 2, 0, 'column-major' ); // $ExpectType int16ndarray + eye( 'int8', 2, 2, 0, 'column-major' ); // $ExpectType int8ndarray + eye( 'uint32', 2, 2, 0, 'column-major' ); // $ExpectType uint32ndarray + eye( 'uint16', 2, 2, 0, 'column-major' ); // $ExpectType uint16ndarray + eye( 'uint8', 2, 2, 0, 'column-major' ); // $ExpectType uint8ndarray + eye( 'uint8c', 2, 2, 0, 'column-major' ); // $ExpectType uint8cndarray + eye( 'bool', 2, 2, 0, 'column-major' ); // $ExpectType boolndarray + eye( 'generic', 2, 2, 0, 'column-major' ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is an unrecognized/unsupported data type... +{ + eye( '10', 2, 2, 0, 'row-major' ); // $ExpectError + eye( 10, 2, 2, 0, 'row-major' ); // $ExpectError + eye( false, 2, 2, 0, 'row-major' ); // $ExpectError + eye( true, 2, 2, 0, 'row-major' ); // $ExpectError + eye( null, 2, 2, 0, 'row-major' ); // $ExpectError + eye( [], 2, 2, 0, 'row-major' ); // $ExpectError + eye( {}, 2, 2, 0, 'row-major' ); // $ExpectError + eye( ( x: number ): number => x, 2, 2, 0, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid row for the second argument... +{ + eye( 'float32', '5', 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', false, 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', true, 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', null, 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', undefined, 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', [ '5' ], 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', {}, 2, 0, 'row-major' ); // $ExpectError + eye( 'float32', ( x: number ): number => x, 2, 0, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid column for the third argument... +{ + eye( 'float32', 2, '5', 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, false, 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, true, 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, null, 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, undefined, 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, [ '5' ], 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, {}, 0, 'row-major' ); // $ExpectError + eye( 'float32', 2, ( x: number ): number => x, 0, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid k for the fourth argument... +{ + eye( 'float32', 2 , 2, '5', 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, false, 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, true, 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, null, 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, undefined, 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, [ '5' ], 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, {}, 'row-major' ); // $ExpectError + eye( 'float32', 2 , 2, ( x: number ): number => x, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid order for the fifth argument... +{ + eye( 'float32', 2 , 2, 0, '5' ); // $ExpectError + eye( 'float32', 2 , 2, 0, false ); // $ExpectError + eye( 'float32', 2 , 2, 0, true ); // $ExpectError + eye( 'float32', 2 , 2, 0, null ); // $ExpectError + eye( 'float32', 2 , 2, 0, undefined ); // $ExpectError + eye( 'float32', 2 , 2, 0, [ '5' ] ); // $ExpectError + eye( 'float32', 2 , 2, 0, {} ); // $ExpectError + eye( 'float32', 2 , 2, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + eye( 'float64' ); // $ExpectError + eye( 'float64', 2 , 2 ); // $ExpectError + eye( 'float64', 2 , 2, 0, 'row-major', 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/package.json b/lib/node_modules/@stdlib/ndarray/base/eye/package.json index 8ad9acbb51ee..f5cd547be515 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/eye/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "doc": "./docs", "example": "./examples", "lib": "./lib", "test": "./test" From bdfbecb4de768b94f3bd4e0d8488a4ab2fa7f7d1 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 23 Mar 2026 02:59:58 +0200 Subject: [PATCH 5/7] feat: add benchmarks --- .../@stdlib/ndarray/base/eye/README.md | 2 +- .../ndarray/base/eye/benchmark/benchmark.js | 264 ++++++++++++++++++ .../base/eye/benchmark/benchmark.size.bool.js | 94 +++++++ .../benchmark/benchmark.size.complex128.js | 94 +++++++ .../eye/benchmark/benchmark.size.complex64.js | 94 +++++++ .../eye/benchmark/benchmark.size.float64.js | 94 +++++++ .../eye/benchmark/benchmark.size.generic.js | 94 +++++++ .../eye/benchmark/benchmark.size.int16.js | 94 +++++++ .../eye/benchmark/benchmark.size.int32.js | 94 +++++++ .../base/eye/benchmark/benchmark.size.int8.js | 94 +++++++ .../eye/benchmark/benchmark.size.uint16.js | 94 +++++++ .../eye/benchmark/benchmark.size.uint32.js | 94 +++++++ .../eye/benchmark/benchmark.size.uint8.js | 94 +++++++ .../eye/benchmark/benchmark.size.uint8c.js | 94 +++++++ .../eye/benchmark/benchmkar.size.float32.js | 94 +++++++ .../ndarray/base/eye/docs/types/index.d.ts | 28 +- .../ndarray/base/eye/docs/types/test.ts | 3 +- .../@stdlib/ndarray/base/eye/package.json | 1 + .../@stdlib/ndarray/base/eye/test/test.js | 48 ++-- 19 files changed, 1528 insertions(+), 40 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.bool.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex128.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex64.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.float64.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.generic.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int16.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int32.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int8.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint16.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint32.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8c.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmkar.size.float32.js diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/README.md b/lib/node_modules/@stdlib/ndarray/base/eye/README.md index 36e795ba5e98..a1c0ac8b3846 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/eye/README.md @@ -81,7 +81,7 @@ The function accepts the following arguments: ## Notes - If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -- If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +- If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.js new file mode 100644 index 000000000000..d338adbdafbe --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.js @@ -0,0 +1,264 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'float64', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'float32', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'complex128', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'complex64', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=int32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int32', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=uint32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint32', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=int16', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int16', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=uint16', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint16', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=int8', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int8', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=uint8', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint8', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=uint8c', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint8c', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'bool', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'generic', 0, 0, 0, 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.bool.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.bool.js new file mode 100644 index 000000000000..0b02a54e9569 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.bool.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'bool', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=bool,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex128.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex128.js new file mode 100644 index 000000000000..d63043b15e78 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex128.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'complex128', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=complex128,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex64.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex64.js new file mode 100644 index 000000000000..c98aca90ae8c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.complex64.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'complex64', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=complex64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.float64.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.float64.js new file mode 100644 index 000000000000..69b02e500a9a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.float64.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'float64', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=float64,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.generic.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.generic.js new file mode 100644 index 000000000000..aecbb7cef427 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.generic.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'generic', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=generic,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int16.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int16.js new file mode 100644 index 000000000000..c723ddbcb8f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int16.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int16', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=int16,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int32.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int32.js new file mode 100644 index 000000000000..3e2b7c8ab996 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int32.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int32', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=int32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int8.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int8.js new file mode 100644 index 000000000000..6bcab14734be --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.int8.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'int8', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=int8,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint16.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint16.js new file mode 100644 index 000000000000..fd87f11a7e21 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint16.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint16', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=uint16,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint32.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint32.js new file mode 100644 index 000000000000..129e26eb380c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint32.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint32', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=uint32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8.js new file mode 100644 index 000000000000..187c1c87d8ad --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint8', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=uint8,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8c.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8c.js new file mode 100644 index 000000000000..bf10208dfd84 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmark.size.uint8c.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'uint8c', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=uint8c,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmkar.size.float32.js b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmkar.size.float32.js new file mode 100644 index 000000000000..84c11308ed09 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/eye/benchmark/benchmkar.size.float32.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var eye = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = eye( 'float32', len, len, 0, 'row-major' ); + if ( arr.length !== pow( len, 2 ) ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=float32,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts index bd512a348e11..c3f3ce04fcc5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts @@ -28,7 +28,7 @@ import { Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int1 * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -58,7 +58,7 @@ declare function eye( dtype: 'float64', rows: number, cols: number, k: number, o * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -88,7 +88,7 @@ declare function eye( dtype: 'float32', rows: number, cols: number, k: number, o * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -118,7 +118,7 @@ declare function eye( dtype: 'complex128', rows: number, cols: number, k: number * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -148,7 +148,7 @@ declare function eye( dtype: 'complex64', rows: number, cols: number, k: number, * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -178,7 +178,7 @@ declare function eye( dtype: 'int32', rows: number, cols: number, k: number, ord * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -208,7 +208,7 @@ declare function eye( dtype: 'int16', rows: number, cols: number, k: number, ord * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -238,7 +238,7 @@ declare function eye( dtype: 'int8', rows: number, cols: number, k: number, orde * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -268,7 +268,7 @@ declare function eye( dtype: 'uint32', rows: number, cols: number, k: number, or * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -298,7 +298,7 @@ declare function eye( dtype: 'uint16', rows: number, cols: number, k: number, or * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -328,7 +328,7 @@ declare function eye( dtype: 'uint8', rows: number, cols: number, k: number, ord * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -358,7 +358,7 @@ declare function eye( dtype: 'uint8c', rows: number, cols: number, k: number, or * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -388,7 +388,7 @@ declare function eye( dtype: 'bool', rows: number, cols: number, k: number, orde * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows @@ -418,7 +418,7 @@ declare function eye( dtype: 'generic', rows: number, cols: number, k: number, o * ## Notes * * - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than number of negative rows, the function returns an array filled with zeros +* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros * * @param dtype - underlying data type * @param rows - number of rows diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts index 2a71709e3582..cddc1e0cfb0d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -116,5 +116,6 @@ import eye = require( './index' ); { eye( 'float64' ); // $ExpectError eye( 'float64', 2 , 2 ); // $ExpectError + eye( 'float64', 2 , 2, 0 ); // $ExpectError eye( 'float64', 2 , 2, 0, 'row-major', 1 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/package.json b/lib/node_modules/@stdlib/ndarray/base/eye/package.json index f5cd547be515..0c15d46c03a7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/eye/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib", diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js index e3b73b33d9e1..a9fc3dc7fbcc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js @@ -197,13 +197,13 @@ tape( 'the function returns a square identity matrix (row-major, accessors)', fu expected = new Complex128Array([ 1.0, - 0.0, // 1 + 0i 0.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 0 + 0i + 0.0, + 0.0, + 0.0, 1.0, - 0.0 // 1 + 0i + 0.0 ]); t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); @@ -291,13 +291,13 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off expected = new Complex128Array([ 0.0, - 0.0, // 0 + 0i + 0.0, 1.0, - 0.0, // 1 + 0i 0.0, - 0.0, // 0 + 0i 0.0, - 0.0 // 0 + 0i + 0.0, + 0.0, + 0.0 ]); t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); @@ -385,13 +385,13 @@ tape( 'the function returns a square matrix with ones on a negative diagonal off expected = new Complex128Array([ 0.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 0 + 0i + 0.0, + 0.0, 1.0, - 0.0, // 1 + 0i 0.0, - 0.0 // 0 + 0i + 0.0, + 0.0 ]); t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); @@ -476,17 +476,17 @@ tape( 'the function returns a rectangular matrix with ones on a positive diagona expected = new Complex128Array([ 0.0, - 0.0, // 0 + 0i + 0.0, 1.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 1 + 0i 0.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 0 + 0i + 0.0, + 0.0, + 0.0, + 0.0, 1.0, - 0.0 // 1 + 0i + 0.0 ]); t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); @@ -572,17 +572,17 @@ tape( 'the function returns a rectangular matrix with ones on a negative diagona expected = new Complex128Array([ 0.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 0 + 0i 0.0, - 0.0, // 0 + 0i + 0.0, + 0.0, + 0.0, 1.0, - 0.0, // 1 + 0i 0.0, - 0.0, // 0 + 0i 0.0, - 0.0 // 1 + 0i + 0.0, + 0.0, + 0.0 ]); t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); From d5eb83349840f2c12d5251d64fcad322b910d792 Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Mon, 23 Mar 2026 06:45:08 +0200 Subject: [PATCH 6/7] docs: update examples --- .../@stdlib/ndarray/base/eye/docs/types/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts index c3f3ce04fcc5..7401dc23102a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts @@ -107,8 +107,8 @@ declare function eye( dtype: 'float32', rows: number, cols: number, k: number, o * var dt = x.dtype; * // returns 'complex128' * -* var v = x.get( 0, 0 ).re; -* // returns 1.0 +* var v = x.get( 0, 0 ); +* // returns [ 1.0, 0.0 ] */ declare function eye( dtype: 'complex128', rows: number, cols: number, k: number, order: Order ): complex128ndarray; @@ -137,8 +137,8 @@ declare function eye( dtype: 'complex128', rows: number, cols: number, k: number * var dt = x.dtype; * // returns 'complex64' * -* var v = x.get( 0, 0 ).re; -* // returns 1.0 +* var v = x.get( 0, 0 ); +* // returns [ 1.0, 0.0 ] */ declare function eye( dtype: 'complex64', rows: number, cols: number, k: number, order: Order ): complex64ndarray; From 1edd03fbffeb483839d2c705b6e52df43331a69c Mon Sep 17 00:00:00 2001 From: LoayAhmed304 Date: Tue, 24 Mar 2026 06:53:37 +0200 Subject: [PATCH 7/7] chore: clean-up --- .../@stdlib/ndarray/base/eye/README.md | 27 +- .../@stdlib/ndarray/base/eye/docs/repl.txt | 17 +- .../ndarray/base/eye/docs/types/index.d.ts | 314 +++++++----------- .../@stdlib/ndarray/base/eye/lib/index.js | 13 +- .../@stdlib/ndarray/base/eye/lib/main.js | 39 +-- .../@stdlib/ndarray/base/eye/package.json | 2 +- .../@stdlib/ndarray/base/eye/test/test.js | 79 +++-- 7 files changed, 224 insertions(+), 267 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/README.md b/lib/node_modules/@stdlib/ndarray/base/eye/README.md index a1c0ac8b3846..59c82b14eecb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/eye/README.md @@ -20,7 +20,7 @@ limitations under the License. # eye -> Create a two-dimensional array with ones on the kth diagonal and zeros elsewhere +> Create a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere @@ -42,23 +42,20 @@ var eye = require( '@stdlib/ndarray/base/eye' ); #### eye( dtype, rows, cols, k, order ) -Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. ```javascript var getShape = require( '@stdlib/ndarray/shape' ); var getDType = require( '@stdlib/ndarray/dtype' ); -var x = eye( 'float64', 3, 3, 0, 'row-major'); -// returns +var arr = eye( 'float64', 3, 3, 0, 'row-major'); +// returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] -var sh = getShape( x ); +var sh = getShape( arr ); // returns [ 3, 3 ] -var dt = String( getDType( x ) ); +var dt = String( getDType( arr ) ); // returns 'float64' - -var v = x.get( 0, 0 ); -// returns 1.0 ``` The function accepts the following arguments: @@ -80,8 +77,8 @@ The function accepts the following arguments: ## Notes -- If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -- If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +- If the provided [data type][@stdlib/ndarray/dtypes] is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero. +- If `k` is greater than the number of columns or less than the number of negative rows, the function returns an ndarray filled with zeros. @@ -99,11 +96,11 @@ The function accepts the following arguments: var eye = require( '@stdlib/ndarray/base/eye' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var x = eye( 'float64', 3, 3, 1, 'row-major'); -console.log( ndarray2array( x ) ); +var arr = eye( 'float64', 3, 3, 1, 'row-major'); +console.log( ndarray2array( arr ) ); -x = eye( 'complex64', 3, 3, 1, 'row-major'); -console.log( ndarray2array( x ) ); +arr = eye( 'complex64', 3, 3, 1, 'row-major'); +console.log( ndarray2array( arr ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt index 5a9e24195c9d..cd246221cd35 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( dtype, rows, cols, k, order ) - Creates a two-dimensional array with ones on the kth diagonal and zeros + Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. If the provided data type is complex, the function returns an ndarray @@ -12,10 +12,10 @@ dtype: string|DataType Underlying data type. - rows: NonNegativeInteger + rows: integer Number of rows. - cols: NonNegativeInteger + cols: integer Number of columns. k: integer @@ -32,13 +32,12 @@ Examples -------- - > var arr = {{alias}}( 'float64', 2, 2, 0, 'row-major' ) - + > var arr = {{alias}}( 'float64', 3, 3, 0, 'row-major' ) + [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] > var sh = {{alias:@stdlib/ndarray/shape}}( arr ) - [ 2, 2 ] - > var data = {{alias:@stdlib/ndarray/to-array}}( arr ) - [ [ 1, 0 ], [ 0, 1 ] ] - -------- + [ 3, 3 ] + > var dt = String( {{alias:@stdlib/ndarray/dtype}}( arr ) ) + 'float64' See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts index 7401dc23102a..e7483bdaa02d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/eye/docs/types/index.d.ts @@ -20,15 +20,10 @@ /// -import { Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray, genericndarray, DataType } from '@stdlib/types/ndarray'; +import { Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, complex128ndarray, complex64ndarray, genericndarray, DataType, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, BooleanDataType, GenericDataType } from '@stdlib/types/ndarray'; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -38,27 +33,22 @@ import { Order, typedndarray, float64ndarray, float32ndarray, int32ndarray, int1 * @returns output two-dimensional array * * @example -* var x = eye( 'float64', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'float64' -* -* var v = x.get( 0, 0 ); -* // returns 1.0 */ -declare function eye( dtype: 'float64', rows: number, cols: number, k: number, order: Order ): float64ndarray; +declare function eye( dtype: Float64DataType, rows: number, cols: number, k: number, order: Order ): float64ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -68,27 +58,26 @@ declare function eye( dtype: 'float64', rows: number, cols: number, k: number, o * @returns output two-dimensional array * * @example -* var x = eye( 'float32', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; +* var arr = eye( 'float32', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] +* +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'float32' -* -* var v = x.get( 0, 0 ); -* // returns 1.0 */ -declare function eye( dtype: 'float32', rows: number, cols: number, k: number, order: Order ): float32ndarray; +declare function eye( dtype: Float32DataType, rows: number, cols: number, k: number, order: Order ): float32ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * ## Notes * -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* - The function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero * * @param dtype - underlying data type * @param rows - number of rows @@ -98,27 +87,29 @@ declare function eye( dtype: 'float32', rows: number, cols: number, k: number, o * @returns output two-dimensional array * * @example -* var x = eye( 'complex128', 3, 3, 0, 'row-major'); +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'complex128', 3, 3, 0, 'row-major'); * // returns * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'complex128' * -* var v = x.get( 0, 0 ); +* var v = arr.get( 0, 0 ); * // returns [ 1.0, 0.0 ] */ -declare function eye( dtype: 'complex128', rows: number, cols: number, k: number, order: Order ): complex128ndarray; +declare function eye( dtype: Complex128DataType, rows: number, cols: number, k: number, order: Order ): complex128ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * ## Notes * -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* - The function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero * * @param dtype - underlying data type * @param rows - number of rows @@ -128,27 +119,25 @@ declare function eye( dtype: 'complex128', rows: number, cols: number, k: number * @returns output two-dimensional array * * @example -* var x = eye( 'complex64', 3, 3, 0, 'row-major'); +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'complex64', 3, 3, 0, 'row-major'); * // returns * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'complex64' * -* var v = x.get( 0, 0 ); +* var v = arr.get( 0, 0 ); * // returns [ 1.0, 0.0 ] */ -declare function eye( dtype: 'complex64', rows: number, cols: number, k: number, order: Order ): complex64ndarray; +declare function eye( dtype: Complex64DataType, rows: number, cols: number, k: number, order: Order ): complex64ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -158,27 +147,22 @@ declare function eye( dtype: 'complex64', rows: number, cols: number, k: number, * @returns output two-dimensional array * * @example -* var x = eye( 'int32', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'int32', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'int32' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'int32', rows: number, cols: number, k: number, order: Order ): int32ndarray; +declare function eye( dtype: Int32DataType, rows: number, cols: number, k: number, order: Order ): int32ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -188,27 +172,22 @@ declare function eye( dtype: 'int32', rows: number, cols: number, k: number, ord * @returns output two-dimensional array * * @example -* var x = eye( 'int16', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; +* var arr = eye( 'int16', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] +* +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'int16' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'int16', rows: number, cols: number, k: number, order: Order ): int16ndarray; +declare function eye( dtype: Int16DataType, rows: number, cols: number, k: number, order: Order ): int16ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -218,27 +197,22 @@ declare function eye( dtype: 'int16', rows: number, cols: number, k: number, ord * @returns output two-dimensional array * * @example -* var x = eye( 'int8', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'int8', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'int8' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'int8', rows: number, cols: number, k: number, order: Order ): int8ndarray; +declare function eye( dtype: Int8DataType, rows: number, cols: number, k: number, order: Order ): int8ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -248,27 +222,22 @@ declare function eye( dtype: 'int8', rows: number, cols: number, k: number, orde * @returns output two-dimensional array * * @example -* var x = eye( 'uint32', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; +* var arr = eye( 'uint32', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] +* +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'uint32' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'uint32', rows: number, cols: number, k: number, order: Order ): uint32ndarray; +declare function eye( dtype: Uint32DataType, rows: number, cols: number, k: number, order: Order ): uint32ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -278,27 +247,22 @@ declare function eye( dtype: 'uint32', rows: number, cols: number, k: number, or * @returns output two-dimensional array * * @example -* var x = eye( 'uint16', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'uint16', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'uint16' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'uint16', rows: number, cols: number, k: number, order: Order ): uint16ndarray; +declare function eye( dtype: Uint16DataType, rows: number, cols: number, k: number, order: Order ): uint16ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -308,27 +272,22 @@ declare function eye( dtype: 'uint16', rows: number, cols: number, k: number, or * @returns output two-dimensional array * * @example -* var x = eye( 'uint8', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; +* var arr = eye( 'uint8', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] +* +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'uint8' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'uint8', rows: number, cols: number, k: number, order: Order ): uint8ndarray; +declare function eye( dtype: Uint8DataType, rows: number, cols: number, k: number, order: Order ): uint8ndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -338,27 +297,22 @@ declare function eye( dtype: 'uint8', rows: number, cols: number, k: number, ord * @returns output two-dimensional array * * @example -* var x = eye( 'uint8c', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'uint8c', 3, 3, 0, 'row-major'); +* // returns [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'uint8c' -* -* var v = x.get( 0, 0 ); -* // returns 1 */ -declare function eye( dtype: 'uint8c', rows: number, cols: number, k: number, order: Order ): uint8cndarray; +declare function eye( dtype: Uint8cDataType, rows: number, cols: number, k: number, order: Order ): uint8cndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -368,27 +322,22 @@ declare function eye( dtype: 'uint8c', rows: number, cols: number, k: number, or * @returns output two-dimensional array * * @example -* var x = eye( 'bool', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; +* var arr = eye( 'bool', 3, 3, 0, 'row-major'); +* // returns [ [ true, false, false ], [ false, true, false ], [ false, false, true ] ] +* +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'bool' -* -* var v = x.get( 0, 0 ); -* // returns true */ -declare function eye( dtype: 'bool', rows: number, cols: number, k: number, order: Order ): boolndarray; +declare function eye( dtype: BooleanDataType, rows: number, cols: number, k: number, order: Order ): boolndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -398,27 +347,22 @@ declare function eye( dtype: 'bool', rows: number, cols: number, k: number, orde * @returns output two-dimensional array * * @example -* var x = eye( 'generic', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = eye( 'generic', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] * -* var sh = x.shape; +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = x.dtype; +* var dt = String( getDType( arr ) ); * // returns 'generic' -* -* var v = x.get( 0, 0 ); -* // returns 1.0 */ -declare function eye( dtype: 'generic', rows: number, cols: number, k: number, order: Order ): genericndarray; +declare function eye( dtype: GenericDataType, rows: number, cols: number, k: number, order: Order ): genericndarray; /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. -* -* ## Notes -* -* - If the provided data type is complex, the function returns an ndarray whose kth diagonal is filled with complex numbers whose real component equals one and imaginary component equals zero -* - If `k` is greater than the number of columns or less than the number of negative rows, the function returns an array filled with zeros +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param dtype - underlying data type * @param rows - number of rows @@ -428,17 +372,17 @@ declare function eye( dtype: 'generic', rows: number, cols: number, k: number, o * @returns output two-dimensional array * * @example -* var x = eye( 'float64', 3, 3, 0, 'row-major'); -* // returns +* var getShape = require( '@stdlib/ndarray/shape' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); * -* var sh = x.shape; -* // returns [ 3, 3 ] +* var arr = eye( 'float32', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] * -* var dt = x.dtype; -* // returns 'float64' +* var sh = getShape( arr ); +* // returns [ 3, 3 ] * -* var v = x.get( 0, 0 ); -* // returns 1.0 +* var dt = String( getDType( arr ) ); +* // returns 'float32' */ declare function eye( dtype: DataType, rows: number, cols: number, k: number, order: Order ): typedndarray; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js index ab8e4ffcec5e..1e38d0945394 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Create a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* Create a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @module @stdlib/ndarray/base/eye * @@ -28,17 +28,14 @@ * var getDType = require( '@stdlib/ndarray/dtype' ); * var eye = require( '@stdlib/ndarray/base/eye' ); * -* var x = eye( 'float64', 3, 3, 0, 'row-major'); -* // returns +* var arr = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] * -* var sh = getShape( x ); +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = String( getDType( x ) ); +* var dt = String( getDType( arr ) ); * // returns 'float64' -* -* var v = x.get( 0, 0 ); -* // returns 1.0 */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js index 06681ded5303..f6884b131fa3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/lib/main.js @@ -50,7 +50,7 @@ function setter( buf, idx, v ) { // MAIN // /** -* Creates a two-dimensional array with ones on the kth diagonal and zeros elsewhere. +* Returns a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere. * * @param {*} dtype - output array data type * @param {NonNegativeInteger} rows - output array number of rows @@ -58,28 +58,26 @@ function setter( buf, idx, v ) { * @param {IntegerNumber} k - diagonal index. positive refers to upper diagonal, and negative refers to lower diagonal * @param {string} order - memory layout (either row-major or column-major) * @throws {TypeError} first argument must be a recognized data type -* @throws {TypeError} fourth argument must be an integer * @throws {TypeError} second and third arguments must be non-negative integers +* @throws {TypeError} fourth argument must be an integer * @returns {ndarray} ndarray * * @example * var getShape = require( '@stdlib/ndarray/shape' ); * var getDType = require( '@stdlib/ndarray/dtype' ); * -* var x = eye( 'float64', 3, 3, 0, 'row-major'); -* // returns +* var arr = eye( 'float64', 3, 3, 0, 'row-major'); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] * -* var sh = getShape( x ); +* var sh = getShape( arr ); * // returns [ 3, 3 ] * -* var dt = String( getDType( x ) ); +* var dt = String( getDType( arr ) ); * // returns 'float64' -* -* var v = x.get( 0, 0 ); -* // returns 1.0 */ function eye( dtype, rows, cols, k, order ) { var ctor; + var out; var len; var buf; var set; @@ -91,14 +89,13 @@ function eye( dtype, rows, cols, k, order ) { var v; var r; var c; - var x; - if ( !isInteger( k ) ) { - throw new TypeError( format('invalid arguments. Diagonal index must be an integer. Value: %s.', k) ); + if ( !isNonNegativeInteger( rows ) || !isNonNegativeInteger( cols ) ) { + throw new TypeError( format('invalid arguments. Second and third arguments must be non-negative integers. Rows: %s, Columns: %s.', rows, cols) ); } - if ( !isNonNegativeInteger( rows ) || !isNonNegativeInteger( cols ) ) { - throw new TypeError( format('invalid arguments. Rows and columns must be non-negative integers. Value: %s, %s.', rows, cols) ); + if ( !isInteger( k ) ) { + throw new TypeError( format('invalid arguments. The fourth argument must be an integer. Diagonal index: %s.', k) ); } if ( k < 0 ) { @@ -109,19 +106,19 @@ function eye( dtype, rows, cols, k, order ) { c = k; } - x = zeros( dtype, [ rows, cols ], order ); + out = zeros( dtype, [ rows, cols ], order ); - sr = x.strides[ 0 ]; - sc = x.strides[ 1 ]; - ix = x.offset + (r * sr) + (c * sc); // offset + (row * row_stride) + (col * col_stride) + sr = out.strides[ 0 ]; + sc = out.strides[ 1 ]; + ix = out.offset + (r * sr) + (c * sc); // offset + (row * row_stride) + (col * col_stride) dx = sr + sc; - if ( isAccessorArray( x.data ) ) { + if ( isAccessorArray( out.data ) ) { set = accessorSetter( dtype ); } else { set = setter; } - buf = x.data; + buf = out.data; len = max( 0, min( rows - r, cols - c ) ); if ( isComplexDataType( dtype ) ) { @@ -136,7 +133,7 @@ function eye( dtype, rows, cols, k, order ) { ix += dx; } - return x; + return out; } module.exports = eye; diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/package.json b/lib/node_modules/@stdlib/ndarray/base/eye/package.json index 0c15d46c03a7..351279385201 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/eye/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/eye", "version": "0.0.0", - "description": "Create a two dimensional array with ones on the kth diagonal and zeros elsewhere.", + "description": "Create a two-dimensional ndarray with ones on the kth diagonal and zeros elsewhere.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js index a9fc3dc7fbcc..ce343ae028b3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/eye/test/test.js @@ -25,7 +25,9 @@ var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Float64Array = require( '@stdlib/array/float64' ); +var getShape = require( '@stdlib/ndarray/shape' ); var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); var eye = require( './../lib' ); @@ -123,12 +125,13 @@ tape( 'the function throws an error if provided an invalid rows or columns as th } }); -tape( 'the function returns a zero-filled array when provided zero rows and columns', function test( t ) { +tape( 'the function returns a zero-filled ndarray when provided zero rows and columns', function test( t ) { var out; out = eye( 'float64', 0, 0, 1, 'row-major' ); - t.strictEqual( out.dtype, 'float64', 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 0, 0 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 0 ) ), true, 'returns expected value' ); t.end(); @@ -139,8 +142,8 @@ tape( 'the function returns an empty array when provided zero rows and columns ( out = eye( 'complex128', 0, 0, 1, 'row-major' ); - t.strictEqual( out.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( out.shape, [ 0, 0 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 0, 0 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), new Complex128Array( 0 ) ), true, 'returns expected value' ); t.end(); @@ -151,8 +154,8 @@ tape( 'the function returns a zero-filled array when provided k greater than col out = eye( 'float64', 3, 6, 7, 'row-major' ); - t.strictEqual( out.dtype, 'float64', 'returns expected value' ); - t.deepEqual( out.shape, [ 3, 6 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 6 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 18 ) ), true, 'returns expected value' ); t.end(); @@ -163,8 +166,8 @@ tape( 'the function returns a zero-filled array when provided k less than negati out = eye( 'float64', 3, 6, -4, 'row-major' ); - t.strictEqual( out.dtype, 'float64', 'returns expected value' ); - t.deepEqual( out.shape, [ 3, 6 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 6 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), new Float64Array( 18 ) ), true, 'returns expected value' ); t.end(); @@ -183,7 +186,8 @@ tape( 'the function returns a square identity matrix (row-major)', function test 1.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -206,7 +210,8 @@ tape( 'the function returns a square identity matrix (row-major, accessors)', fu 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -230,7 +235,8 @@ tape( 'the function returns a square identity matrix (column-major)', function t 1.0 ]); - t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -253,7 +259,8 @@ tape( 'the function returns a square identity matrix (column-major, accessors)', 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -277,7 +284,8 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -300,7 +308,8 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -324,7 +333,8 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -347,7 +357,8 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -371,7 +382,8 @@ tape( 'the function returns a square matrix with ones on a negative diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -394,7 +406,8 @@ tape( 'the function returns a square matrix with ones on a negative diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -418,7 +431,8 @@ tape( 'the function returns a square matrix with ones on a negative diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 3, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -441,7 +455,8 @@ tape( 'the function returns a square matrix with ones on a positive diagonal off 0.0 ]); - t.deepEqual( out.shape, [ 2, 2 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -462,7 +477,8 @@ tape( 'the function returns a rectangular matrix with ones on a positive diagona 1.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -489,7 +505,8 @@ tape( 'the function returns a rectangular matrix with ones on a positive diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -510,7 +527,8 @@ tape( 'the function returns a rectangular matrix with ones on a positive diagona 1.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -537,7 +555,8 @@ tape( 'the function returns a rectangular matrix with ones on a positive diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -558,7 +577,8 @@ tape( 'the function returns a rectangular matrix with ones on a negative diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -585,7 +605,8 @@ tape( 'the function returns a rectangular matrix with ones on a negative diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -606,7 +627,8 @@ tape( 'the function returns a rectangular matrix with ones on a negative diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameFloat64Array( getData( out ), expected ), true, 'returns expected value' ); t.end(); @@ -633,7 +655,8 @@ tape( 'the function returns a rectangular matrix with ones on a negative diagona 0.0 ]); - t.deepEqual( out.shape, [ 2, 3 ], 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( out ), [ 2, 3 ], 'returns expected value' ); t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); t.end();