From e1e1e8fcf7e03c125960dde32a472ddaf11724fe Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 25 Jan 2026 22:43:26 +0500 Subject: [PATCH 1/3] feat: add ndarray/base/broadcast-scalar-like --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../base/broadcast-scalar-like/README.md | 139 +++ .../benchmark/benchmark.js | 324 +++++++ .../base/broadcast-scalar-like/docs/repl.txt | 46 + .../docs/types/index.d.ts | 125 +++ .../broadcast-scalar-like/docs/types/test.ts | 58 ++ .../broadcast-scalar-like/examples/index.js | 36 + .../base/broadcast-scalar-like/lib/index.js | 48 + .../base/broadcast-scalar-like/lib/main.js | 91 ++ .../base/broadcast-scalar-like/package.json | 64 ++ .../base/broadcast-scalar-like/test/test.js | 863 ++++++++++++++++++ 10 files changed, 1794 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md new file mode 100644 index 000000000000..af11552f362f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md @@ -0,0 +1,139 @@ + + +# broadcastScalarLike + +> Broadcast a scalar value to an [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/base/ctor]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var broadcastScalarLike = require( '@stdlib/ndarray/base/broadcast-scalar-like' ); +``` + +#### broadcastScalarLike( x, value ) + +Broadcasts a scalar `value` to an [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/base/ctor]. + +```javascript +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var getDType = require( '@stdlib/ndarray/dtype' ); + +var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); +// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + +var y = broadcastScalarLike( x, 1.0 ); +// returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] + +var dt = getDType( y ); +// returns 'float32' +``` + +
+ + + + + +
+ +## Notes + +- Along with data type, shape, and order, the function infers the "class" of the returned [ndarray][@stdlib/ndarray/base/ctor] from the provided [ndarray][@stdlib/ndarray/base/ctor]. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor]. +- If `value` is a number and [`dtype`][@stdlib/ndarray/dtypes] is a complex [data type][@stdlib/ndarray/dtypes], the function returns an [ndarray][@stdlib/ndarray/base/ctor] containing a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero. +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a view on an [ndarray][@stdlib/ndarray/base/ctor] data buffer containing a single element. The view is **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned [ndarray][@stdlib/ndarray/base/ctor], copy the [ndarray][@stdlib/ndarray/base/ctor] **before** performing operations which may mutate elements. +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to broadcast a scalar value as an [ndarray][@stdlib/ndarray/base/ctor] within internal implementations and to do so with minimal overhead. + +
+ + + + + +
+ +## Examples + + + +```javascript +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var empty = require( '@stdlib/ndarray/base/empty' ); +var broadcastScalarLike = require( '@stdlib/ndarray/base/broadcast-scalar-like' ); + +// Get a list of data types: +var dt = dtypes(); + +// Generate broadcasted arrays... +var x; +var y; +var i; +for ( i = 0; i < dt.length; i++ ) { + x = empty( dt[ i ], [ 2, 2 ], 'row-major' ); + y = broadcastScalarLike( x, i ); + console.log( y.get( 0, 0 ) ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js new file mode 100644 index 000000000000..13f4fe7de262 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js @@ -0,0 +1,324 @@ +/** +* @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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var broadcastScalarLike = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::base:dtype=float64', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=float32', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'float32', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=complex128', pkg ), function benchmark( b ) { + var x; + var y; + var v; + var i; + + x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + v = new Complex128( 1.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, v ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=complex64', pkg ), function benchmark( b ) { + var x; + var y; + var v; + var i; + + x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); + v = new Complex64( 1.0, 2.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, v ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=int32', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'int32', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=uint32', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'uint32', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=int16', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'int16', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=uint16', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'uint16', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=int8', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'int8', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=uint8', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'uint8', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=uint8c', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'uint8c', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=generic', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, i ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:dtype=bool', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = zeros( 'bool', [ 2, 2 ], 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = broadcastScalarLike( x, ( i%2 ) === 0 ); + if ( numel( y.shape ) !== 4 ) { + b.fail( 'should have expected number of elements' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt new file mode 100644 index 000000000000..02d2acbd06e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( x, value ) + Broadcasts a scalar value to an ndarray having the same shape and data type + as a provided input ndarray. + + Along with data type, shape, and order, the function infers the "class" of + the returned ndarray from the provided ndarray. For example, if provided a + "base" ndarray, the function returns a base ndarray. If provided a non-base + ndarray, the function returns a non-base ndarray. + + If `value` is a number and a provided ndarray has a complex number data + type, the function returns an ndarray containing a complex number whose real + component equals the provided scalar value and whose imaginary component is + zero. + + The returned ndarray is a view on a single-element buffer. The returned + ndarray is not contiguous. As more than one element of a returned ndarray + refers to the same memory location, writing to the returned ndarray may + affect multiple elements. If you need to write to the returned ndarray, copy + the ndarray before performing operations which may mutate elements. + + Parameters + ---------- + x: ndarray + Input array. + + value: any + Scalar value. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/base/zeros}}( 'float64', [ 2, 2 ], 'row-major' ) + [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + > var y = {{alias}}( x, 1.0 ) + [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] + > var dt = {{alias:@stdlib/ndarray/dtype}}( y ) + 'float64' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts new file mode 100644 index 000000000000..27d1ec3a09b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts @@ -0,0 +1,125 @@ +/* +* @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 { typedndarray, genericndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { ComplexLike } from '@stdlib/types/complex'; + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* ## Notes +* +* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. +* +* @param x - input array +* @param value - scalar value +* @returns output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); +* // returns [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +* +* var dt = getDType( y ); +* // returns 'complex128' +*/ +declare function broadcastScalarLike( x: complex128ndarray, value: ComplexLike | number ): complex128ndarray; + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* ## Notes +* +* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. +* +* @param x - input array +* @param value - scalar value +* @returns output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); +* // returns [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] +* +* var dt = getDType( y ); +* // returns 'complex64' +*/ +declare function broadcastScalarLike( x: complex64ndarray, value: ComplexLike | number ): complex64ndarray; + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @param value - scalar value +* @returns output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = zeros( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] +* +* var dt = getDType( y ); +* // returns 'generic' +*/ +declare function broadcastScalarLike( x: genericndarray, value: T ): genericndarray; + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @param x - input array +* @param value - scalar value +* @returns output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = zeros( 'float64', [ 2, 2 ], 'row-major' ); +* // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] +* +* var dt = getDType( y ); +* // returns 'float64' +*/ +declare function broadcastScalarLike( x: typedndarray, value: T ): typedndarray; + + +// EXPORTS // + +export = broadcastScalarLike; diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts new file mode 100644 index 000000000000..09986b85de9c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts @@ -0,0 +1,58 @@ +/* +* @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. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import broadcastScalarLike = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + broadcastScalarLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'float32', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'complex128', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType complex128ndarray + broadcastScalarLike( zeros( 'complex64', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType complex64ndarray + broadcastScalarLike( zeros( 'int32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'int16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'int8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'uint32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'uint16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'uint8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'uint8c', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'generic', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + broadcastScalarLike( '5', 1.0 ); // $ExpectError + broadcastScalarLike( 5, 1.0 ); // $ExpectError + broadcastScalarLike( true, 1.0 ); // $ExpectError + broadcastScalarLike( false, 1.0 ); // $ExpectError + broadcastScalarLike( null, 1.0 ); // $ExpectError + broadcastScalarLike( [], 1.0 ); // $ExpectError + broadcastScalarLike( {}, 1.0 ); // $ExpectError + broadcastScalarLike( ( x: number ): number => x, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + broadcastScalarLike(); // $ExpectError + broadcastScalarLike( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + broadcastScalarLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1.0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/examples/index.js new file mode 100644 index 000000000000..e4143f74d357 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var empty = require( '@stdlib/ndarray/base/empty' ); +var broadcastScalarLike = require( './../lib' ); + +// Get a list of data types: +var dt = dtypes( 'integer_and_generic' ); + +// Generate broadcasted arrays... +var x; +var y; +var i; +for ( i = 0; i < dt.length; i++ ) { + x = empty( dt[ i ], [ 2, 2 ], 'row-major' ); + y = broadcastScalarLike( x, i ); + console.log( y.get( 0, 0 ) ); +} diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js new file mode 100644 index 000000000000..fd8a9b2bfd75 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js @@ -0,0 +1,48 @@ +/** +* @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'; + +/** +* Broadcast a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @module @stdlib/ndarray/base/broadcast-scalar-like +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var broadcastScalarLike = require( '@stdlib/ndarray/base/broadcast-scalar-like' ); +* +* var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] +* +* var dt = getDType( y ); +* // returns 'float32' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js new file mode 100644 index 000000000000..6e8c714ef3d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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. +*/ + +/* eslint-disable stdlib/jsdoc-doctest */ + +'use strict'; + +// MODULES // + +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); +var isComplexDataType = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); +var accessorSetter = require( '@stdlib/array/base/accessor-setter' ); +var setter = require( '@stdlib/array/base/setter' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var emptyArray = require( '@stdlib/array/empty' ); +var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); + + +// MAIN // + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @param {ndarray} x - input array +* @param {*} value - scalar value +* @throws {TypeError} first argument must have a recognized data type +* @returns {ndarray} ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/base/zeros' ); +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); +* // returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] +* +* var y = broadcastScalarLike( x, 1.0 ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] +* +* var dt = getDType( y ); +* // returns 'float32' +*/ +function broadcastScalarLike( x, value ) { + var buf; + var set; + var sh; + var dt; + var N; + + dt = getDType( x ); + if ( dt === 'binary' ) { + buf = allocUnsafe( 1 ); + } else { + buf = emptyArray( 1, dt ); + } + if ( isComplexDataType( dt ) && isNumber( value ) ) { + value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components + } + if ( isAccessorArray( buf ) ) { + set = accessorSetter( dt ); + } else { + set = setter( dt ); + } + set( buf, 0, value ); + sh = getShape( x, false ); + N = sh.length || 1; + return new x.constructor( dt, buf, sh, zeros( N ), 0, getOrder( x ) ); +} + + +// EXPORTS // + +module.exports = broadcastScalarLike; diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/package.json b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/package.json new file mode 100644 index 000000000000..1dca8716b075 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/broadcast-scalar-like", + "version": "0.0.0", + "description": "Broadcast a scalar value to an ndarray having the same shape and data type as a provided input ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "data", + "structure", + "ndarray", + "scalar", + "broadcast", + "wrap", + "convert" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js new file mode 100644 index 000000000000..3bead01fd36e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js @@ -0,0 +1,863 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Buffer = require( '@stdlib/buffer/ctor' ); +var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); +var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var base = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var empty = require( '@stdlib/ndarray/base/empty' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var broadcastScalarLike = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof broadcastScalarLike, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument having an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + [], + {}, + function noop() {}, + { + 'data': true + }, + { + 'shape': [ 1, 2, 3 ], + 'order': 'row-major', + 'dtype': 'foo_bar_beep_boop' + } + ]; + + 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() { + broadcastScalarLike( value, 1.0 ); + }; + } +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=float64)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + expected = new Float64Array( [ 1.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=float64)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Float64Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'float64', + 'order': 'column-major' + }); + + expected = new Float64Array( [ 1.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=float32)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'float32', [ 3, 3 ], 'column-major' ); + + expected = new Float32Array( [ 1.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 3 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 9, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=float32)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Float32Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'float32', + 'order': 'row-major' + }); + + expected = new Float32Array( [ 1.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=int32)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'int32', [ 2, 1 ], 'row-major' ); + + expected = new Int32Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=int32)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Int32Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'int32', + 'order': 'column-major' + }); + + expected = new Int32Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=int16)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'int16', [ 1, 2 ], 'column-major' ); + + expected = new Int16Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 1, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=int16)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Int16Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'int16', + 'order': 'row-major' + }); + + expected = new Int16Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=int8)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'int8', [ 3, 3, 3 ], 'row-major' ); + + expected = new Int8Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 27, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=int8)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Int8Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'int8', + 'order': 'column-major' + }); + + expected = new Int8Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'int8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=uint32)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'uint32', [ 1, 2, 3 ], 'column-major' ); + + expected = new Uint32Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 1, 2, 3 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 6, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint32)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Uint32Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint32', + 'order': 'row-major' + }); + + expected = new Uint32Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint32', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=uint16)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'uint16', [ 3, 2, 1 ], 'row-major' ); + + expected = new Uint16Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 6, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint16)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Uint16Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint16', + 'order': 'column-major' + }); + + expected = new Uint16Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=uint8)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); + + expected = new Uint8Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint8)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Uint8Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint8', + 'order': 'row-major' + }); + + expected = new Uint8Array( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint8', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=uint8c)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'uint8c', [ 2, 0, 2 ], 'row-major' ); + + expected = new Uint8ClampedArray( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint8c', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint8c)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Uint8ClampedArray( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'uint8c', + 'order': 'row-major' + }); + + expected = new Uint8ClampedArray( [ 1 ] ); + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'uint8c', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=complex128, complex)', function test( t ) { + var expected; + var arr; + var x; + var v; + + x = zeros( 'complex128', [ 1 ], 'column-major' ); + + expected = new Float64Array( [ 1.0, 2.0 ] ); + + v = new Complex128( 1.0, 2.0 ); + arr = broadcastScalarLike( x, v ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 1 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex128, complex)', function test( t ) { + var expected; + var arr; + var x; + var v; + + x = array( new Complex128Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex128', + 'order': 'row-major' + }); + + expected = new Float64Array( [ 1.0, 2.0 ] ); + + v = new Complex128( 1.0, 2.0 ); + arr = broadcastScalarLike( x, v ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=complex128, real)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + + expected = new Float64Array( [ 1.0, 0.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex128, real)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Complex128Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex128', + 'order': 'column-major' + }); + + expected = new Float64Array( [ 1.0, 0.0 ] ); + + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=complex64, complex)', function test( t ) { + var expected; + var arr; + var x; + var v; + + x = zeros( 'complex64', [ 3, 3 ], 'column-major' ); + + expected = new Float32Array( [ 1.0, 2.0 ] ); + + v = new Complex64( 1.0, 2.0 ); + arr = broadcastScalarLike( x, v ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 3 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 9, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex64, complex)', function test( t ) { + var expected; + var arr; + var x; + var v; + + x = array( new Complex64Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex64', + 'order': 'row-major' + }); + + expected = new Float32Array( [ 1.0, 2.0 ] ); + + v = new Complex64( 1.0, 2.0 ); + arr = broadcastScalarLike( x, v ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=complex64, real)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'complex64', [ 4, 4 ], 'row-major' ); + + expected = new Float32Array( [ 1.0, 0.0 ] ); + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 4, 4 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 16, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex64, real)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new Complex64Array( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'complex64', + 'order': 'column-major' + }); + + expected = new Float32Array( [ 1.0, 0.0 ] ); + + arr = broadcastScalarLike( x, 1.0 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); + t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=generic)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'generic', [ 0, 2, 0 ], 'column-major' ); + + expected = [ 1 ]; + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 0, 2, 0 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=generic)', function test( t ) { + var expected; + var arr; + var x; + + x = array( [ 1, 2, 3, 4 ], { + 'shape': [ 2, 2 ], + 'dtype': 'generic', + 'order': 'row-major' + }); + + expected = [ 1 ]; + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=generic, ndims=0)', function test( t ) { + var expected; + var arr; + var x; + + x = zeros( 'generic', [], 'column-major' ); + + expected = [ 1 ]; + arr = broadcastScalarLike( x, 1 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=bool)', function test( t ) { + var expected; + var arr; + var x; + + x = empty( 'bool', [ 2, 2 ], 'row-major' ); + + expected = new Uint8Array( [ 1 ] ); + arr = broadcastScalarLike( x, true ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); + t.deepEqual( reinterpretBoolean( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=bool)', function test( t ) { + var expected; + var arr; + var x; + + x = array( new BooleanArray( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'bool', + 'order': 'column-major' + }); + + expected = new Uint8Array( [ 1 ] ); + arr = broadcastScalarLike( x, true ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); + t.deepEqual( reinterpretBoolean( getData( arr ), 0 ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (base, dtype=binary)', function test( t ) { + var arr; + var x; + + x = zeros( 'binary', [ 2, 2 ], 'row-major' ); + arr = broadcastScalarLike( x, 127 ); + + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'binary', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a broadcasted ndarray (non-base, dtype=binary)', function test( t ) { + var arr; + var x; + + x = array( allocUnsafe( 4 ), { + 'shape': [ 2, 2 ], + 'dtype': 'binary', + 'order': 'column-major' + }); + + arr = broadcastScalarLike( x, true ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( getDType( arr ), 'binary', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + t.strictEqual( numel( getShape( arr ) ), 4, 'returns expected value' ); + + t.end(); +}); From bc8707d17c886e9cfb41ef8381e28117e3bf01dc Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 25 Jan 2026 22:53:34 +0500 Subject: [PATCH 2/3] docs: apply suggestion from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/ndarray/base/broadcast-scalar-like/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md index af11552f362f..77ba6979579d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md @@ -91,7 +91,7 @@ var empty = require( '@stdlib/ndarray/base/empty' ); var broadcastScalarLike = require( '@stdlib/ndarray/base/broadcast-scalar-like' ); // Get a list of data types: -var dt = dtypes(); +var dt = dtypes( 'integer_and_generic' ); // Generate broadcasted arrays... var x; From e3c7ff87e408fa67e05102db2b0c9a02df77010d Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 25 Jan 2026 22:54:10 -0800 Subject: [PATCH 3/3] chore: clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../base/broadcast-scalar-like/README.md | 7 +- .../benchmark/benchmark.js | 55 ++++++++-------- .../base/broadcast-scalar-like/docs/repl.txt | 2 - .../docs/types/index.d.ts | 38 ++--------- .../broadcast-scalar-like/docs/types/test.ts | 18 ++--- .../base/broadcast-scalar-like/lib/index.js | 2 +- .../base/broadcast-scalar-like/lib/main.js | 26 ++++---- .../base/broadcast-scalar-like/test/test.js | 66 +++++++++---------- 8 files changed, 91 insertions(+), 123 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md index 77ba6979579d..bdf9ca7b6018 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/README.md @@ -42,7 +42,7 @@ var broadcastScalarLike = require( '@stdlib/ndarray/base/broadcast-scalar-like' #### broadcastScalarLike( x, value ) -Broadcasts a scalar `value` to an [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/base/ctor]. +Broadcasts a scalar value to an [ndarray][@stdlib/ndarray/base/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/base/ctor]. ```javascript var zeros = require( '@stdlib/ndarray/base/zeros' ); @@ -54,7 +54,7 @@ var x = zeros( 'float32', [ 2, 2 ], 'row-major' ); var y = broadcastScalarLike( x, 1.0 ); // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] -var dt = getDType( y ); +var dt = String( getDType( y ) ); // returns 'float32' ``` @@ -69,9 +69,8 @@ var dt = getDType( y ); ## Notes - Along with data type, shape, and order, the function infers the "class" of the returned [ndarray][@stdlib/ndarray/base/ctor] from the provided [ndarray][@stdlib/ndarray/base/ctor]. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor]. -- If `value` is a number and [`dtype`][@stdlib/ndarray/dtypes] is a complex [data type][@stdlib/ndarray/dtypes], the function returns an [ndarray][@stdlib/ndarray/base/ctor] containing a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero. +- If `value` is a number and the [data type][@stdlib/ndarray/dtypes] of the input ndarray is a complex [data type][@stdlib/ndarray/dtypes], the function returns an [ndarray][@stdlib/ndarray/base/ctor] containing a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero. - The returned [ndarray][@stdlib/ndarray/base/ctor] is a view on an [ndarray][@stdlib/ndarray/base/ctor] data buffer containing a single element. The view is **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned [ndarray][@stdlib/ndarray/base/ctor], copy the [ndarray][@stdlib/ndarray/base/ctor] **before** performing operations which may mutate elements. -- The returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to broadcast a scalar value as an [ndarray][@stdlib/ndarray/base/ctor] within internal implementations and to do so with minimal overhead. diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js index 13f4fe7de262..8c9d75a21057 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/benchmark/benchmark.js @@ -24,8 +24,7 @@ var bench = require( '@stdlib/bench' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var zeros = require( '@stdlib/ndarray/base/zeros' ); -var numel = require( '@stdlib/ndarray/base/numel' ); +var empty = require( '@stdlib/ndarray/base/empty' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var broadcastScalarLike = require( './../lib' ); @@ -38,12 +37,12 @@ bench( format( '%s::base:dtype=float64', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + x = empty( 'float64', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -60,12 +59,12 @@ bench( format( '%s::base:dtype=float32', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'float32', [ 2, 2 ], 'row-major' ); + x = empty( 'float32', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -83,13 +82,13 @@ bench( format( '%s::base:dtype=complex128', pkg ), function benchmark( b ) { var v; var i; - x = zeros( 'complex128', [ 2, 2 ], 'row-major' ); + x = empty( 'complex128', [ 2, 2 ], 'row-major' ); v = new Complex128( 1.0, 2.0 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, v ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -107,13 +106,13 @@ bench( format( '%s::base:dtype=complex64', pkg ), function benchmark( b ) { var v; var i; - x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); + x = empty( 'complex64', [ 2, 2 ], 'row-major' ); v = new Complex64( 1.0, 2.0 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, v ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -130,12 +129,12 @@ bench( format( '%s::base:dtype=int32', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'int32', [ 2, 2 ], 'row-major' ); + x = empty( 'int32', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -152,12 +151,12 @@ bench( format( '%s::base:dtype=uint32', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'uint32', [ 2, 2 ], 'row-major' ); + x = empty( 'uint32', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -174,12 +173,12 @@ bench( format( '%s::base:dtype=int16', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'int16', [ 2, 2 ], 'row-major' ); + x = empty( 'int16', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -196,12 +195,12 @@ bench( format( '%s::base:dtype=uint16', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'uint16', [ 2, 2 ], 'row-major' ); + x = empty( 'uint16', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -218,12 +217,12 @@ bench( format( '%s::base:dtype=int8', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'int8', [ 2, 2 ], 'row-major' ); + x = empty( 'int8', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -240,12 +239,12 @@ bench( format( '%s::base:dtype=uint8', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'uint8', [ 2, 2 ], 'row-major' ); + x = empty( 'uint8', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -262,12 +261,12 @@ bench( format( '%s::base:dtype=uint8c', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'uint8c', [ 2, 2 ], 'row-major' ); + x = empty( 'uint8c', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -284,12 +283,12 @@ bench( format( '%s::base:dtype=generic', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + x = empty( 'generic', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, i ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } @@ -306,12 +305,12 @@ bench( format( '%s::base:dtype=bool', pkg ), function benchmark( b ) { var y; var i; - x = zeros( 'bool', [ 2, 2 ], 'row-major' ); + x = empty( 'bool', [ 2, 2 ], 'row-major' ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = broadcastScalarLike( x, ( i%2 ) === 0 ); - if ( numel( y.shape ) !== 4 ) { + if ( y.length !== 4 ) { b.fail( 'should have expected number of elements' ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt index 02d2acbd06e0..6a4dd9ea936a 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/repl.txt @@ -38,8 +38,6 @@ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] > var y = {{alias}}( x, 1.0 ) [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] - > var dt = {{alias:@stdlib/ndarray/dtype}}( y ) - 'float64' See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts index 27d1ec3a09b2..2e58dd31b2a1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { typedndarray, genericndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { typedndarray, genericndarray, complexndarray } from '@stdlib/types/ndarray'; import { ComplexLike } from '@stdlib/types/complex'; /** @@ -44,36 +44,10 @@ import { ComplexLike } from '@stdlib/types/complex'; * var y = broadcastScalarLike( x, 1.0 ); * // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] * -* var dt = getDType( y ); +* var dt = String( getDType( y ) ); * // returns 'complex128' */ -declare function broadcastScalarLike( x: complex128ndarray, value: ComplexLike | number ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param x - input array -* @param value - scalar value -* @returns output ndarray -* -* @example -* var zeros = require( '@stdlib/ndarray/base/zeros' ); -* var getDType = require( '@stdlib/ndarray/dtype' ); -* -* var x = zeros( 'complex64', [ 2, 2 ], 'row-major' ); -* // returns [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] -* -* var y = broadcastScalarLike( x, 1.0 ); -* // returns [ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ] -* -* var dt = getDType( y ); -* // returns 'complex64' -*/ -declare function broadcastScalarLike( x: complex64ndarray, value: ComplexLike | number ): complex64ndarray; +declare function broadcastScalarLike( x: T, value: ComplexLike | number ): T; /** * Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. @@ -92,7 +66,7 @@ declare function broadcastScalarLike( x: complex64ndarray, value: ComplexLike | * var y = broadcastScalarLike( x, 1.0 ); * // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] * -* var dt = getDType( y ); +* var dt = String( getDType( y ) ); * // returns 'generic' */ declare function broadcastScalarLike( x: genericndarray, value: T ): genericndarray; @@ -114,10 +88,10 @@ declare function broadcastScalarLike( x: genericndarray, value: * var y = broadcastScalarLike( x, 1.0 ); * // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] * -* var dt = getDType( y ); +* var dt = String( getDType( y ) ); * // returns 'float64' */ -declare function broadcastScalarLike( x: typedndarray, value: T ): typedndarray; +declare function broadcastScalarLike = typedndarray>( x: U, value: T ): U; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts index 09986b85de9c..c5c3fa4faa24 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/docs/types/test.ts @@ -24,17 +24,17 @@ import broadcastScalarLike = require( './index' ); // The function returns an ndarray... { - broadcastScalarLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'float32', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType float64ndarray + broadcastScalarLike( zeros( 'float32', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType float32ndarray broadcastScalarLike( zeros( 'complex128', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType complex128ndarray broadcastScalarLike( zeros( 'complex64', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType complex64ndarray - broadcastScalarLike( zeros( 'int32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'int16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'int8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'uint32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'uint16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'uint8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray - broadcastScalarLike( zeros( 'uint8c', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType typedndarray + broadcastScalarLike( zeros( 'int32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType int32ndarray + broadcastScalarLike( zeros( 'int16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType int16ndarray + broadcastScalarLike( zeros( 'int8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType int8ndarray + broadcastScalarLike( zeros( 'uint32', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType uint32ndarray + broadcastScalarLike( zeros( 'uint16', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType uint16ndarray + broadcastScalarLike( zeros( 'uint8', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType uint8ndarray + broadcastScalarLike( zeros( 'uint8c', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectType uint8cndarray broadcastScalarLike( zeros( 'generic', [ 2, 2 ], 'row-major' ), 1.0 ); // $ExpectType genericndarray } diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js index fd8a9b2bfd75..10d3810cbffc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/index.js @@ -34,7 +34,7 @@ * var y = broadcastScalarLike( x, 1.0 ); * // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] * -* var dt = getDType( y ); +* var dt = String( getDType( y ) ); * // returns 'float32' */ diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js index 6e8c714ef3d9..e36c39e5f899 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/lib/main.js @@ -16,23 +16,22 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest */ - 'use strict'; // MODULES // +var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); -var isComplexDataType = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); var accessorSetter = require( '@stdlib/array/base/accessor-setter' ); var setter = require( '@stdlib/array/base/setter' ); -var zeros = require( '@stdlib/array/base/zeros' ); +var azeros = require( '@stdlib/array/base/zeros' ); var getDType = require( '@stdlib/ndarray/base/dtype' ); var getShape = require( '@stdlib/ndarray/base/shape' ); var getOrder = require( '@stdlib/ndarray/base/order' ); -var emptyArray = require( '@stdlib/array/empty' ); -var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); +var buffer = require( '@stdlib/ndarray/base/buffer' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var format = require( '@stdlib/string/format' ); // MAIN // @@ -55,7 +54,7 @@ var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); * var y = broadcastScalarLike( x, 1.0 ); * // returns [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ] * -* var dt = getDType( y ); +* var dt = String( getDType( y ) ); * // returns 'float32' */ function broadcastScalarLike( x, value ) { @@ -65,11 +64,10 @@ function broadcastScalarLike( x, value ) { var dt; var N; - dt = getDType( x ); - if ( dt === 'binary' ) { - buf = allocUnsafe( 1 ); - } else { - buf = emptyArray( 1, dt ); + dt = resolveStr( getDType( x ) ); + buf = buffer( dt, 1 ); + if ( buf === null ) { + throw new TypeError( format( 'invalid argument. First argument must have a recognized data type. Value: `%s`.', dt ) ); } if ( isComplexDataType( dt ) && isNumber( value ) ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components @@ -80,9 +78,9 @@ function broadcastScalarLike( x, value ) { set = setter( dt ); } set( buf, 0, value ); - sh = getShape( x, false ); + sh = getShape( x, true ); N = sh.length || 1; - return new x.constructor( dt, buf, sh, zeros( N ), 0, getOrder( x ) ); + return new x.constructor( dt, buf, sh, azeros( N ), 0, getOrder( x ) ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js index 3bead01fd36e..d111e1b4e268 100644 --- a/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/broadcast-scalar-like/test/test.js @@ -109,7 +109,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=float64)', functi arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'float64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -134,7 +134,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=float64)', fu arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'float64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Float64Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -155,7 +155,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=float32)', functi arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'float32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -180,7 +180,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=float32)', fu arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'float32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Float32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -201,7 +201,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=int32)', function arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 1 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -226,7 +226,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=int32)', func arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -247,7 +247,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=int16)', function arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int16', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int16', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 1, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -272,7 +272,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=int16)', func arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int16', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int16', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int16Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -293,7 +293,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=int8)', function arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int8', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int8', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -318,7 +318,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=int8)', funct arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'int8', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'int8', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Int8Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -339,7 +339,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=uint32)', functio arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 1, 2, 3 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -364,7 +364,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint32)', fun arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint32', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint32', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint32Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -385,7 +385,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=uint16)', functio arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint16', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint16', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2, 1 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -410,7 +410,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint16)', fun arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint16', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint16', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint16Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -431,7 +431,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=uint8)', function arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint8', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -456,7 +456,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint8)', func arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint8', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint8Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -477,7 +477,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=uint8c)', functio arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint8c', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8c', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -502,7 +502,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=uint8c)', fun arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'uint8c', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'uint8c', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Uint8ClampedArray ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -526,7 +526,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=complex128, compl arr = broadcastScalarLike( x, v ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 1 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -554,7 +554,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex128, c arr = broadcastScalarLike( x, v ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -575,7 +575,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=complex128, real) arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -601,7 +601,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex128, r arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex128', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex128', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex128Array ), true, 'returns expected value' ); t.deepEqual( reinterpret128( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -625,7 +625,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=complex64, comple arr = broadcastScalarLike( x, v ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 3 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -653,7 +653,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex64, co arr = broadcastScalarLike( x, v ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -674,7 +674,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=complex64, real)' arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 4, 4 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -700,7 +700,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=complex64, re arr = broadcastScalarLike( x, 1.0 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'complex64', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'complex64', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Complex64Array ), true, 'returns expected value' ); t.deepEqual( reinterpret64( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -721,7 +721,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=generic)', functi arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 0, 2, 0 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -746,7 +746,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=generic)', fu arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -767,7 +767,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=generic, ndims=0) arr = broadcastScalarLike( x, 1 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( arr ), [], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); t.deepEqual( getData( arr ), expected, 'returns expected value' ); @@ -788,7 +788,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=bool)', function arr = broadcastScalarLike( x, true ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'bool', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'bool', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); t.deepEqual( reinterpretBoolean( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -813,7 +813,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=bool)', funct arr = broadcastScalarLike( x, true ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'bool', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'bool', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), BooleanArray ), true, 'returns expected value' ); t.deepEqual( reinterpretBoolean( getData( arr ), 0 ), expected, 'returns expected value' ); @@ -831,7 +831,7 @@ tape( 'the function returns a broadcasted ndarray (base, dtype=binary)', functio arr = broadcastScalarLike( x, 127 ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'binary', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'binary', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); @@ -853,7 +853,7 @@ tape( 'the function returns a broadcasted ndarray (non-base, dtype=binary)', fun arr = broadcastScalarLike( x, true ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); - t.strictEqual( getDType( arr ), 'binary', 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'binary', 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( instanceOf( getData( arr ), Buffer ), true, 'returns expected value' ); t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' );