From 8f8b69878f9cd4b4b6456530b2372af8ff314f3d Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 19 Mar 2026 00:32:17 +0500 Subject: [PATCH] feat: add ndarray/base/assign-scalar --- 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 --- --- .../ndarray/base/assign-scalar/README.md | 173 +++ .../benchmark.10d_blocked_columnmajor.js | 145 ++ .../benchmark.10d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.10d_columnmajor.js | 145 ++ .../benchmark/benchmark.10d_rowmajor.js | 145 ++ .../benchmark/benchmark.11d_columnmajor.js | 145 ++ .../benchmark/benchmark.11d_rowmajor.js | 145 ++ .../benchmark/benchmark.1d_columnmajor.js | 134 ++ .../benchmark/benchmark.1d_rowmajor.js | 134 ++ .../benchmark.2d_blocked_columnmajor.js | 146 ++ .../benchmark.2d_blocked_rowmajor.js | 146 ++ .../benchmark/benchmark.2d_columnmajor.js | 146 ++ .../benchmark/benchmark.2d_rowmajor.js | 146 ++ .../benchmark.2d_rowmajor_accessors.js | 174 +++ ...benchmark.2d_rowmajor_accessors_complex.js | 182 +++ .../benchmark.3d_blocked_columnmajor.js | 146 ++ .../benchmark.3d_blocked_rowmajor.js | 146 ++ .../benchmark/benchmark.3d_columnmajor.js | 146 ++ .../benchmark/benchmark.3d_rowmajor.js | 146 ++ .../benchmark.4d_blocked_columnmajor.js | 145 ++ .../benchmark.4d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.4d_columnmajor.js | 145 ++ .../benchmark/benchmark.4d_rowmajor.js | 145 ++ .../benchmark.5d_blocked_columnmajor.js | 145 ++ .../benchmark.5d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.5d_columnmajor.js | 145 ++ .../benchmark/benchmark.5d_rowmajor.js | 145 ++ .../benchmark.6d_blocked_columnmajor.js | 145 ++ .../benchmark.6d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.6d_columnmajor.js | 145 ++ .../benchmark/benchmark.6d_rowmajor.js | 145 ++ .../benchmark.7d_blocked_columnmajor.js | 145 ++ .../benchmark.7d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.7d_columnmajor.js | 145 ++ .../benchmark/benchmark.7d_rowmajor.js | 145 ++ .../benchmark.8d_blocked_columnmajor.js | 145 ++ .../benchmark.8d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.8d_columnmajor.js | 145 ++ .../benchmark/benchmark.8d_rowmajor.js | 145 ++ .../benchmark.9d_blocked_columnmajor.js | 145 ++ .../benchmark.9d_blocked_rowmajor.js | 145 ++ .../benchmark/benchmark.9d_columnmajor.js | 145 ++ .../benchmark/benchmark.9d_rowmajor.js | 145 ++ .../ndarray/base/assign-scalar/docs/repl.txt | 62 + .../base/assign-scalar/docs/types/index.d.ts | 67 + .../base/assign-scalar/docs/types/test.ts | 56 + .../base/assign-scalar/examples/index.js | 42 + .../ndarray/base/assign-scalar/lib/0d.js | 92 ++ .../base/assign-scalar/lib/0d_accessors.js | 113 ++ .../ndarray/base/assign-scalar/lib/10d.js | 221 +++ .../base/assign-scalar/lib/10d_accessors.js | 248 ++++ .../base/assign-scalar/lib/10d_blocked.js | 325 +++++ .../lib/10d_blocked_accessors.js | 352 +++++ .../ndarray/base/assign-scalar/lib/1d.js | 118 ++ .../base/assign-scalar/lib/1d_accessors.js | 145 ++ .../ndarray/base/assign-scalar/lib/2d.js | 139 ++ .../base/assign-scalar/lib/2d_accessors.js | 166 +++ .../base/assign-scalar/lib/2d_blocked.js | 171 +++ .../assign-scalar/lib/2d_blocked_accessors.js | 198 +++ .../ndarray/base/assign-scalar/lib/3d.js | 149 ++ .../base/assign-scalar/lib/3d_accessors.js | 176 +++ .../base/assign-scalar/lib/3d_blocked.js | 192 +++ .../assign-scalar/lib/3d_blocked_accessors.js | 219 +++ .../ndarray/base/assign-scalar/lib/4d.js | 159 +++ .../base/assign-scalar/lib/4d_accessors.js | 186 +++ .../base/assign-scalar/lib/4d_blocked.js | 211 +++ .../assign-scalar/lib/4d_blocked_accessors.js | 238 ++++ .../ndarray/base/assign-scalar/lib/5d.js | 169 +++ .../base/assign-scalar/lib/5d_accessors.js | 196 +++ .../base/assign-scalar/lib/5d_blocked.js | 230 +++ .../assign-scalar/lib/5d_blocked_accessors.js | 257 ++++ .../ndarray/base/assign-scalar/lib/6d.js | 181 +++ .../base/assign-scalar/lib/6d_accessors.js | 208 +++ .../base/assign-scalar/lib/6d_blocked.js | 249 ++++ .../assign-scalar/lib/6d_blocked_accessors.js | 276 ++++ .../ndarray/base/assign-scalar/lib/7d.js | 191 +++ .../base/assign-scalar/lib/7d_accessors.js | 218 +++ .../base/assign-scalar/lib/7d_blocked.js | 268 ++++ .../assign-scalar/lib/7d_blocked_accessors.js | 295 ++++ .../ndarray/base/assign-scalar/lib/8d.js | 201 +++ .../base/assign-scalar/lib/8d_accessors.js | 228 +++ .../base/assign-scalar/lib/8d_blocked.js | 287 ++++ .../assign-scalar/lib/8d_blocked_accessors.js | 314 ++++ .../ndarray/base/assign-scalar/lib/9d.js | 211 +++ .../base/assign-scalar/lib/9d_accessors.js | 238 ++++ .../base/assign-scalar/lib/9d_blocked.js | 306 ++++ .../assign-scalar/lib/9d_blocked_accessors.js | 333 +++++ .../ndarray/base/assign-scalar/lib/index.js | 72 + .../ndarray/base/assign-scalar/lib/main.js | 339 +++++ .../ndarray/base/assign-scalar/lib/nd.js | 139 ++ .../base/assign-scalar/lib/nd_accessors.js | 166 +++ .../ndarray/base/assign-scalar/package.json | 62 + .../base/assign-scalar/test/test.0d.js | 79 + .../base/assign-scalar/test/test.1d.js | 126 ++ .../base/assign-scalar/test/test.2d.js | 1133 +++++++++++++++ .../base/assign-scalar/test/test.3d.js | 1269 +++++++++++++++++ .../ndarray/base/assign-scalar/test/test.js | 33 + 97 files changed, 18634 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors_complex.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_columnmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_rowmajor.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd_accessors.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/README.md b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/README.md new file mode 100644 index 000000000000..295998b725f6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/README.md @@ -0,0 +1,173 @@ + + +# assignScalar + +> Assign a scalar value to every element of an output [ndarray][@stdlib/ndarray/base/ctor]. + +
+ +
+ + + +
+ +## Usage + +```javascript +var assignScalar = require( '@stdlib/ndarray/base/assign-scalar' ); +``` + +#### assignScalar( arrays ) + +Assigns a scalar value to every element of an output [ndarray][@stdlib/ndarray/base/ctor]. + + + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Float64Array = require( '@stdlib/array/float64' ); + +// Create a zero-dimensional ndarray containing the scalar value: +var x = scalar2ndarray( 5.0, { + 'dtype': 'float64' +}); + +// Create a data buffer: +var ybuf = new Float64Array( 6 ); + +// Define the shape of the output array: +var shape = [ 3, 1, 2 ]; + +// Define the array strides: +var sy = [ 2, 2, 1 ]; + +// Define the index offset: +var oy = 0; + +// Create the output ndarray-like object: +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': sy, + 'offset': oy, + 'order': 'row-major' +}; + +// Assign the scalar value: +assignScalar( [ x, y ] ); + +console.log( y.data ); +// => [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing a zero-dimensional input [ndarray][@stdlib/ndarray/base/ctor] and an output [ndarray][@stdlib/ndarray/base/ctor]. + +Each provided [ndarray][@stdlib/ndarray/base/ctor] should be an object with the following properties: + +- **dtype**: data type. +- **data**: data buffer. +- **shape**: dimensions. +- **strides**: stride lengths. +- **offset**: index offset. +- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). + +
+ + + +
+ +## Notes + +- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance. + +
+ + + +
+ +## Examples + + + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var filledarray = require( '@stdlib/array/filled' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var assignScalar = require( '@stdlib/ndarray/base/assign-scalar' ); + +var x = scalar2ndarray( 10.0, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); + +var y = { + 'dtype': 'generic', + 'data': filledarray( 0, 10, 'generic' ), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +assignScalar( [ x, y ] ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_columnmajor.js new file mode 100644 index 000000000000..9c228cef9659 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_rowmajor.js new file mode 100644 index 000000000000..3b77bae66878 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/10d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_columnmajor.js new file mode 100644 index 000000000000..8e43383c4eea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_rowmajor.js new file mode 100644 index 000000000000..bda8225eb29c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.10d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/10d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/10.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 9 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_columnmajor.js new file mode 100644 index 000000000000..55a07c367ce8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/11.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 10 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_rowmajor.js new file mode 100644 index 000000000000..9c38dd55c81e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.11d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/nd.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/11.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 10 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_columnmajor.js new file mode 100644 index 000000000000..d742352f7bf1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_columnmajor.js @@ -0,0 +1,134 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( [ x, y ] ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_rowmajor.js new file mode 100644 index 000000000000..8d6671e3accd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.1d_rowmajor.js @@ -0,0 +1,134 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( [ x, y ] ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_columnmajor.js new file mode 100644 index 000000000000..5f5f109ba9c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_columnmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_rowmajor.js new file mode 100644 index 000000000000..9f322e61c151 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_blocked_rowmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_columnmajor.js new file mode 100644 index 000000000000..c15dae8b042d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_columnmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor.js new file mode 100644 index 000000000000..534a975fe112 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors.js new file mode 100644 index 000000000000..70b175a97a62 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors.js @@ -0,0 +1,174 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Returns an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @returns {*} element +*/ +function get( buf, idx ) { + return buf[ idx ]; +} + +/** +* Sets an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @param {*} value - value to set +*/ +function set( buf, idx, value ) { + buf[ idx ] = value; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors_complex.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors_complex.js new file mode 100644 index 000000000000..543a880b726d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.2d_rowmajor_accessors_complex.js @@ -0,0 +1,182 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var ctors = require( '@stdlib/array/typed-complex-ctors' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/2d_accessors.js' ); + + +// VARIABLES // + +var types = [ 'complex64' ]; +var order = 'row-major'; +var abtype = { + 'complex64': 'float32', + 'complex128': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @returns {*} element +*/ +function get( buf, idx ) { + return buf.get( idx ); +} + +/** +* Sets an array data buffer element. +* +* @private +* @param {Collection} buf - data buffer +* @param {NonNegativeInteger} idx - element index +* @param {*} value - value to set +*/ +function set( buf, idx, value ) { + buf.set( value, idx ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var xbuf; + var ybuf; + var x; + var y; + + xbuf = filledarray( 10.0, 2, abtype[ xtype ] ); + ybuf = filledarray( 0.0, len*2, abtype[ ytype ] ); + x = { + 'dtype': xtype, + 'data': new ( ctors( xtype ) )( xbuf.buffer ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + y = { + 'dtype': ytype, + 'data': new ( ctors( ytype ) )( ybuf.buffer ), + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order, + 'accessorProtocol': true, + 'accessors': [ get, set ] + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( ybuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( ybuf[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 5; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::accessors:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_columnmajor.js new file mode 100644 index 000000000000..47843d6e9dfb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_columnmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_rowmajor.js new file mode 100644 index 000000000000..78a862ea7f8a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_blocked_rowmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/3d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_columnmajor.js new file mode 100644 index 000000000000..da98b577d065 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_columnmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_rowmajor.js new file mode 100644 index 000000000000..5d3895066ade --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.3d_rowmajor.js @@ -0,0 +1,146 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/3d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( cbrt( len ) ); + sh = [ len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_columnmajor.js new file mode 100644 index 000000000000..2c451d6c3c29 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_rowmajor.js new file mode 100644 index 000000000000..7d9e1414f931 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/4d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_columnmajor.js new file mode 100644 index 000000000000..a20b9237d5ab --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_rowmajor.js new file mode 100644 index 000000000000..139186e2fb8d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.4d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/4d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/4.0 ) ); + sh = [ len, len, len, len ]; + len *= len * len * len; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_columnmajor.js new file mode 100644 index 000000000000..e2bc2b67d417 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_rowmajor.js new file mode 100644 index 000000000000..245bd03b5ab7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/5d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_columnmajor.js new file mode 100644 index 000000000000..72eb50dc31eb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_rowmajor.js new file mode 100644 index 000000000000..e9930c2b6c91 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.5d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/5d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/5.0 ) ); + sh = [ len, len, len, len, len ]; + len *= pow( len, 4 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_columnmajor.js new file mode 100644 index 000000000000..fe15cb8f2344 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_rowmajor.js new file mode 100644 index 000000000000..b9634cdda249 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/6d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_columnmajor.js new file mode 100644 index 000000000000..d033f6e17738 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_rowmajor.js new file mode 100644 index 000000000000..75089b10fb9b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.6d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/6d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/6.0 ) ); + sh = [ len, len, len, len, len, len ]; + len *= pow( len, 5 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_columnmajor.js new file mode 100644 index 000000000000..6698447da16c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_rowmajor.js new file mode 100644 index 000000000000..43b1b64a9ac8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/7d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_columnmajor.js new file mode 100644 index 000000000000..f8f436a00a43 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_rowmajor.js new file mode 100644 index 000000000000..c0d030f03862 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.7d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/7d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/7.0 ) ); + sh = [ len, len, len, len, len, len, len ]; + len *= pow( len, 6 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_columnmajor.js new file mode 100644 index 000000000000..23b43dda0d1b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_rowmajor.js new file mode 100644 index 000000000000..0d01971bb9e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/8d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_columnmajor.js new file mode 100644 index 000000000000..b47fc11fb084 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_rowmajor.js new file mode 100644 index 000000000000..62acf986a619 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.8d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/8d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/8.0 ) ); + sh = [ len, len, len, len, len, len, len, len ]; + len *= pow( len, 7 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_columnmajor.js new file mode 100644 index 000000000000..2d805c5d63f1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_rowmajor.js new file mode 100644 index 000000000000..5f669af6ac67 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_blocked_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/9d_blocked.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s::blocked:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_columnmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_columnmajor.js new file mode 100644 index 000000000000..970f547d70d4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_columnmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'column-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_rowmajor.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_rowmajor.js new file mode 100644 index 000000000000..601a4321f97d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/benchmark/benchmark.9d_rowmajor.js @@ -0,0 +1,145 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assignScalar = require( './../lib/9d.js' ); + + +// VARIABLES // + +var types = [ 'float64' ]; +var order = 'row-major'; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype ) { + var x; + var y; + + y = filledarray( 0.0, len, ytype ); + x = { + 'dtype': xtype, + 'data': [ 10.0 ], + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': order + }; + y = { + 'dtype': ytype, + 'data': y, + 'shape': shape, + 'strides': shape2strides( shape, order ), + 'offset': 0, + 'order': order + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + assignScalar( x, y ); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var sh; + var t1; + var t2; + var f; + var i; + var j; + + min = 1; // 10^min + max = 6; // 10^max + + for ( j = 0; j < types.length; j++ ) { + t1 = types[ j ]; + t2 = types[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + + len = floor( pow( len, 1.0/9.0 ) ); + sh = [ len, len, len, len, len, len, len, len, len ]; + len *= pow( len, 8 ); + f = createBenchmark( len, sh, t1, t2 ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,yorder=%s,xtype=%s,ytype=%s', pkg, sh.length, len, sh.join( ',' ), order, order, t1, t2 ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/repl.txt new file mode 100644 index 000000000000..dcc976bea72e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/repl.txt @@ -0,0 +1,62 @@ + +{{alias}}( arrays ) + Assigns a scalar value to every element of an output ndarray. + + Each provided "ndarray" should be an object with the following properties: + + - dtype: data type. + - data: data buffer. + - shape: dimensions. + - strides: stride lengths. + - offset: index offset. + - order: specifies whether an ndarray is row-major (C-style) or + column-major (Fortran-style). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a zero-dimensional input ndarray and one + output ndarray. + + Examples + -------- + // Define ndarray data and meta data... + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 5.0 ] ); + > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); + > var dtype = 'float64'; + > var shape = [ 2, 2 ]; + > var sy = [ 2, 1 ]; + > var oy = 0; + > var order = 'row-major'; + + // Using ndarrays... + > var x = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, { 'dtype': dtype } ); + > var y = {{alias:@stdlib/ndarray/ctor}}( dtype, ybuf, shape, sy, oy, order ); + > {{alias}}( [ x, y ] ); + > y.data + [ 5.0, 5.0, 5.0, 5.0 ] + + // Using minimal ndarray-like objects... + > x = { + ... 'dtype': dtype, + ... 'data': xbuf, + ... 'shape': [], + ... 'strides': [ 0 ], + ... 'offset': 0, + ... 'order': order + ... }; + > y = { + ... 'dtype': dtype, + ... 'data': ybuf, + ... 'shape': shape, + ... 'strides': sy, + ... 'offset': oy, + ... 'order': order + ... }; + > {{alias}}( [ x, y ] ); + > y.data + [ 5.0, 5.0, 5.0, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/index.d.ts new file mode 100644 index 000000000000..1c2e2ead1c68 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/index.d.ts @@ -0,0 +1,67 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Assigns a scalar value to every element of an output ndarray. +* +* @param arrays - array-like object containing a zero-dimensional input ndarray and one output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a zero-dimensional ndarray containing the scalar value: +* var x = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* // Create a data buffer: +* var ybuf = new Float64Array( 4 ); +* +* // Define the shape of the output array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sy = [ 2, 1 ]; +* +* // Define the index offset: +* var oy = 0; +* +* // Create the output ndarray: +* var y = ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); +* +* // Assign the scalar value: +* assignScalar( [ x, y ] ); +* +* console.log( y.data ); +* // => [ 5.0, 5.0, 5.0, 5.0 ] +*/ +declare function assignScalar( arrays: ArrayLike ): void; + + +// EXPORTS // + +export = assignScalar; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/test.ts new file mode 100644 index 000000000000..7e4286217ec9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import assignScalar = require( './index' ); + + +// TESTS // + +// The function returns `undefined`... +{ + const x = scalar2ndarray( 5.0, { 'dtype': 'float64' } ); + const y = zeros( [ 2, 2 ] ); + const arrays = [ x, y ]; + + assignScalar( arrays ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects... +{ + assignScalar( '5' ); // $ExpectError + assignScalar( 5 ); // $ExpectError + assignScalar( true ); // $ExpectError + assignScalar( false ); // $ExpectError + assignScalar( null ); // $ExpectError + assignScalar( undefined ); // $ExpectError + assignScalar( {} ); // $ExpectError + assignScalar( [ 1 ] ); // $ExpectError + assignScalar( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = scalar2ndarray( 5.0, { 'dtype': 'float64' } ); + const y = zeros( [ 2, 2 ] ); + const arrays = [ x, y ]; + + assignScalar(); // $ExpectError + assignScalar( arrays, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/examples/index.js new file mode 100644 index 000000000000..64cfe873ba7a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var filledarray = require( '@stdlib/array/filled' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var assignScalar = require( './../lib' ); + +var x = scalar2ndarray( 10.0, { + 'dtype': 'generic' +}); +console.log( x.data ); + +var y = { + 'dtype': 'generic', + 'data': filledarray( 0.0, 10, 'generic' ), + 'shape': [ 5, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); + +assignScalar( [ x, y ] ); +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d.js new file mode 100644 index 000000000000..3a29b924a8ef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d.js @@ -0,0 +1,92 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a zero-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 1 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign0d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0 ] +*/ +function assign0d( x, y ) { + y.data[ y.offset ] = x.data[ x.offset ]; +} + + +// EXPORTS // + +module.exports = assign0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d_accessors.js new file mode 100644 index 000000000000..b2fc5b680a24 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/0d_accessors.js @@ -0,0 +1,113 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a zero-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 3.0, 4.0 ] ); +* var ybuf = new Complex64Array( 1 ); +* +* // Define the shape of the input and output arrays: +* var shape = []; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 0 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign0d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 3.0 +* +* var im = imagf( v ); +* // returns 4.0 +*/ +function assign0d( x, y ) { + y.accessors[ 1 ]( y.data, y.offset, x.accessors[ 0 ]( x.data, x.offset ) ); +} + + +// EXPORTS // + +module.exports = assign0d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d.js new file mode 100644 index 000000000000..a405b0543d3b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d.js @@ -0,0 +1,221 @@ +/** +* @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 max-depth, max-statements */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a ten-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign10d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign10d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dy0 = sy[ 9 ]; + dy1 = sy[ 8 ] - ( S0*sy[9] ); + dy2 = sy[ 7 ] - ( S1*sy[8] ); + dy3 = sy[ 6 ] - ( S2*sy[7] ); + dy4 = sy[ 5 ] - ( S3*sy[6] ); + dy5 = sy[ 4 ] - ( S4*sy[5] ); + dy6 = sy[ 3 ] - ( S5*sy[4] ); + dy7 = sy[ 2 ] - ( S6*sy[3] ); + dy8 = sy[ 1 ] - ( S7*sy[2] ); + dy9 = sy[ 0 ] - ( S8*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dy9 = sy[ 9 ] - ( S8*sy[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < S9; i9++ ) { + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + iy += dy9; + } +} + + +// EXPORTS // + +module.exports = assign10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_accessors.js new file mode 100644 index 000000000000..08c0b2b8fd23 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_accessors.js @@ -0,0 +1,248 @@ +/** +* @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 max-depth, max-statements */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a ten-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign10d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign10d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 9 ]; + S1 = sh[ 8 ]; + S2 = sh[ 7 ]; + S3 = sh[ 6 ]; + S4 = sh[ 5 ]; + S5 = sh[ 4 ]; + S6 = sh[ 3 ]; + S7 = sh[ 2 ]; + S8 = sh[ 1 ]; + S9 = sh[ 0 ]; + dy0 = sy[ 9 ]; + dy1 = sy[ 8 ] - ( S0*sy[9] ); + dy2 = sy[ 7 ] - ( S1*sy[8] ); + dy3 = sy[ 6 ] - ( S2*sy[7] ); + dy4 = sy[ 5 ] - ( S3*sy[6] ); + dy5 = sy[ 4 ] - ( S4*sy[5] ); + dy6 = sy[ 3 ] - ( S5*sy[4] ); + dy7 = sy[ 2 ] - ( S6*sy[3] ); + dy8 = sy[ 1 ] - ( S7*sy[2] ); + dy9 = sy[ 0 ] - ( S8*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + S9 = sh[ 9 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + dy9 = sy[ 9 ] - ( S8*sy[8] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < S9; i9++ ) { + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + iy += dy9; + } +} + + +// EXPORTS // + +module.exports = assign10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked.js new file mode 100644 index 000000000000..762cf1dbf04b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked.js @@ -0,0 +1,325 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a ten-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign10d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign10d( x, y ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var j9; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + oy9 = oy + ( j9*sy[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dy9 = sy[9] - ( s8*sy[8] ); + oy8 = oy9 + ( j8*sy[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dy8 = sy[8] - ( s7*sy[7] ); + oy7 = oy8 + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + iy += dy9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked_accessors.js new file mode 100644 index 000000000000..1b756ff47051 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/10d_blocked_accessors.js @@ -0,0 +1,352 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a ten-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign10d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign10d( x, y ) { // eslint-disable-line max-statements, max-lines-per-function + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var dy9; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var oy9; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var s9; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var j9; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j9 = sh[9]; j9 > 0; ) { + if ( j9 < bsize ) { + s9 = j9; + j9 = 0; + } else { + s9 = bsize; + j9 -= bsize; + } + oy9 = oy + ( j9*sy[9] ); + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + dy9 = sy[9] - ( s8*sy[8] ); + oy8 = oy9 + ( j8*sy[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dy8 = sy[8] - ( s7*sy[7] ); + oy7 = oy8 + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i9 = 0; i9 < s9; i9++ ) { + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + iy += dy9; + } + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign10d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d.js new file mode 100644 index 000000000000..8666835c8591 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d.js @@ -0,0 +1,118 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a one-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 6 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign1d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign1d( x, y ) { + var xbuf; + var ybuf; + var dy0; + var S0; + var ix; + var iy; + var i0; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S0 = y.shape[ 0 ]; + dy0 = y.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } +} + + +// EXPORTS // + +module.exports = assign1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d_accessors.js new file mode 100644 index 000000000000..f67844523203 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/1d_accessors.js @@ -0,0 +1,145 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a one-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 1.0, 2.0 ] ); +* var ybuf = new Complex64Array( 4 ); +* +* // Define the shape of the output array: +* var shape = [ 4 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign1d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign1d( x, y ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var S0; + var ix; + var iy; + var i0; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables: dimensions and loop offset (pointer) increments... + S0 = y.shape[ 0 ]; + dy0 = y.strides[ 0 ]; + + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[ 0 ]; + set = y.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } +} + + +// EXPORTS // + +module.exports = assign1d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d.js new file mode 100644 index 000000000000..585e58d51713 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d.js @@ -0,0 +1,139 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a two-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign2d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign2d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var sh; + var S0; + var S1; + var sy; + var ix; + var iy; + var i0; + var i1; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } +} + + +// EXPORTS // + +module.exports = assign2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_accessors.js new file mode 100644 index 000000000000..e9fed639a1f6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_accessors.js @@ -0,0 +1,166 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a two-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 1.0, 2.0 ] ); +* var ybuf = new Complex64Array( 4 ); +* +* // Define the shape of the output array: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign2d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign2d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var sh; + var S0; + var S1; + var sy; + var ix; + var iy; + var i0; + var i1; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 1 ]; + S1 = sh[ 0 ]; + dy0 = sy[ 1 ]; + dy1 = sy[ 0 ] - ( S0*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[ 0 ]; + set = y.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } +} + + +// EXPORTS // + +module.exports = assign2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked.js new file mode 100644 index 000000000000..3b27f5fe1e71 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked.js @@ -0,0 +1,171 @@ +/** +* @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 loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a two-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign2d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign2d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var oy1; + var sh; + var s0; + var s1; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + oy1 = oy + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked_accessors.js new file mode 100644 index 000000000000..3d80d5ef0049 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/2d_blocked_accessors.js @@ -0,0 +1,198 @@ +/** +* @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 loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a two-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +* var ybuf = new Complex64Array( 4 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sy = [ 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Copy elements: +* blockedassign2d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 1.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign2d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var oy1; + var sh; + var s0; + var s1; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var j0; + var j1; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + oy1 = oy + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign2d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d.js new file mode 100644 index 000000000000..50b64e00e4e6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d.js @@ -0,0 +1,149 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a three-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign3d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign3d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var sh; + var S0; + var S1; + var S2; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } +} + + +// EXPORTS // + +module.exports = assign3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_accessors.js new file mode 100644 index 000000000000..1157a487bb92 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_accessors.js @@ -0,0 +1,176 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a three-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign3d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign3d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var sh; + var S0; + var S1; + var S2; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 2 ]; + S1 = sh[ 1 ]; + S2 = sh[ 0 ]; + dy0 = sy[ 2 ]; + dy1 = sy[ 1 ] - ( S0*sy[2] ); + dy2 = sy[ 0 ] - ( S1*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[ 0 ]; + set = y.accessors[ 1 ]; + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } +} + + +// EXPORTS // + +module.exports = assign3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked.js new file mode 100644 index 000000000000..04eda54aa149 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked.js @@ -0,0 +1,192 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a three-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign3d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign3d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var oy1; + var oy2; + var sh; + var s0; + var s1; + var s2; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + oy2 = oy + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked_accessors.js new file mode 100644 index 000000000000..9d5dccc1579a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/3d_blocked_accessors.js @@ -0,0 +1,219 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a three-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Copy elements: +* blockedassign3d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign3d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var oy1; + var oy2; + var sh; + var s0; + var s1; + var s2; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + oy2 = oy + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign3d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d.js new file mode 100644 index 000000000000..60f14a631a8f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d.js @@ -0,0 +1,159 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a four-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign4d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign4d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } +} + + +// EXPORTS // + +module.exports = assign4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_accessors.js new file mode 100644 index 000000000000..07d7a2e04bb6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_accessors.js @@ -0,0 +1,186 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a four-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign4d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign4d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var sh; + var S0; + var S1; + var S2; + var S3; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 3 ]; + S1 = sh[ 2 ]; + S2 = sh[ 1 ]; + S3 = sh[ 0 ]; + dy0 = sy[ 3 ]; + dy1 = sy[ 2 ] - ( S0*sy[3] ); + dy2 = sy[ 1 ] - ( S1*sy[2] ); + dy3 = sy[ 0 ] - ( S2*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } +} + + +// EXPORTS // + +module.exports = assign4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked.js new file mode 100644 index 000000000000..3c68e156e078 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked.js @@ -0,0 +1,211 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a four-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign4d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign4d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var oy1; + var oy2; + var oy3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + oy3 = oy + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked_accessors.js new file mode 100644 index 000000000000..3d47475350b0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/4d_blocked_accessors.js @@ -0,0 +1,238 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a four-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign4d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign4d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var oy1; + var oy2; + var oy3; + var sh; + var s0; + var s1; + var s2; + var s3; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var j0; + var j1; + var j2; + var j3; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + oy3 = oy + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign4d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d.js new file mode 100644 index 000000000000..bf3e34d0c396 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d.js @@ -0,0 +1,169 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a five-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign5d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign5d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dy0 = sy[ 4 ]; + dy1 = sy[ 3 ] - ( S0*sy[4] ); + dy2 = sy[ 2 ] - ( S1*sy[3] ); + dy3 = sy[ 1 ] - ( S2*sy[2] ); + dy4 = sy[ 0 ] - ( S3*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } +} + + +// EXPORTS // + +module.exports = assign5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_accessors.js new file mode 100644 index 000000000000..4b1efd900875 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_accessors.js @@ -0,0 +1,196 @@ +/** +* @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'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a five-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign5d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign5d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + dy0 = sy[ 4 ]; + dy1 = sy[ 3 ] - ( S0*sy[4] ); + dy2 = sy[ 2 ] - ( S1*sy[3] ); + dy3 = sy[ 1 ] - ( S2*sy[2] ); + dy4 = sy[ 0 ] - ( S3*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } +} + + +// EXPORTS // + +module.exports = assign5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked.js new file mode 100644 index 000000000000..62e81c45e202 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked.js @@ -0,0 +1,230 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a five-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign5d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign5d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var oy1; + var oy2; + var oy3; + var oy4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + oy4 = oy + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked_accessors.js new file mode 100644 index 000000000000..21d382e217ce --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/5d_blocked_accessors.js @@ -0,0 +1,257 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a five-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign5d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign5d( x, y ) { + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var oy1; + var oy2; + var oy3; + var oy4; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + oy4 = oy + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign5d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d.js new file mode 100644 index 000000000000..eda1a19e3ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d.js @@ -0,0 +1,181 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a six-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign6d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign6d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dy0 = sy[ 5 ]; + dy1 = sy[ 4 ] - ( S0*sy[5] ); + dy2 = sy[ 3 ] - ( S1*sy[4] ); + dy3 = sy[ 2 ] - ( S2*sy[3] ); + dy4 = sy[ 1 ] - ( S3*sy[2] ); + dy5 = sy[ 0 ] - ( S4*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } +} + + +// EXPORTS // + +module.exports = assign6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_accessors.js new file mode 100644 index 000000000000..f48ba877f20e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_accessors.js @@ -0,0 +1,208 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a six-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign6d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign6d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 5 ]; + S1 = sh[ 4 ]; + S2 = sh[ 3 ]; + S3 = sh[ 2 ]; + S4 = sh[ 1 ]; + S5 = sh[ 0 ]; + dy0 = sy[ 5 ]; + dy1 = sy[ 4 ] - ( S0*sy[5] ); + dy2 = sy[ 3 ] - ( S1*sy[4] ); + dy3 = sy[ 2 ] - ( S2*sy[3] ); + dy4 = sy[ 1 ] - ( S3*sy[2] ); + dy5 = sy[ 0 ] - ( S4*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } +} + + +// EXPORTS // + +module.exports = assign6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked.js new file mode 100644 index 000000000000..0739fcfa224a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked.js @@ -0,0 +1,249 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a six-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign6d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign6d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + oy5 = oy + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked_accessors.js new file mode 100644 index 000000000000..25b6c5d1e4af --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/6d_blocked_accessors.js @@ -0,0 +1,276 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a six-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign6d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign6d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + oy5 = oy + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign6d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d.js new file mode 100644 index 000000000000..ca7c41e086f0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d.js @@ -0,0 +1,191 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a seven-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign7d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign7d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dy0 = sy[ 6 ]; + dy1 = sy[ 5 ] - ( S0*sy[6] ); + dy2 = sy[ 4 ] - ( S1*sy[5] ); + dy3 = sy[ 3 ] - ( S2*sy[4] ); + dy4 = sy[ 2 ] - ( S3*sy[3] ); + dy5 = sy[ 1 ] - ( S4*sy[2] ); + dy6 = sy[ 0 ] - ( S5*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } +} + + +// EXPORTS // + +module.exports = assign7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_accessors.js new file mode 100644 index 000000000000..c1c3d622e389 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_accessors.js @@ -0,0 +1,218 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a seven-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign7d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign7d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 6 ]; + S1 = sh[ 5 ]; + S2 = sh[ 4 ]; + S3 = sh[ 3 ]; + S4 = sh[ 2 ]; + S5 = sh[ 1 ]; + S6 = sh[ 0 ]; + dy0 = sy[ 6 ]; + dy1 = sy[ 5 ] - ( S0*sy[6] ); + dy2 = sy[ 4 ] - ( S1*sy[5] ); + dy3 = sy[ 3 ] - ( S2*sy[4] ); + dy4 = sy[ 2 ] - ( S3*sy[3] ); + dy5 = sy[ 1 ] - ( S4*sy[2] ); + dy6 = sy[ 0 ] - ( S5*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } +} + + +// EXPORTS // + +module.exports = assign7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked.js new file mode 100644 index 000000000000..d11393f446c5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked.js @@ -0,0 +1,268 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a seven-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign7d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign7d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + oy6 = oy + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked_accessors.js new file mode 100644 index 000000000000..c4be0e7c4b57 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/7d_blocked_accessors.js @@ -0,0 +1,295 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a seven-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign7d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign7d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + oy6 = oy + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign7d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d.js new file mode 100644 index 000000000000..314e414f5629 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d.js @@ -0,0 +1,201 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of an eight-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign8d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign8d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dy0 = sy[ 7 ]; + dy1 = sy[ 6 ] - ( S0*sy[7] ); + dy2 = sy[ 5 ] - ( S1*sy[6] ); + dy3 = sy[ 4 ] - ( S2*sy[5] ); + dy4 = sy[ 3 ] - ( S3*sy[4] ); + dy5 = sy[ 2 ] - ( S4*sy[3] ); + dy6 = sy[ 1 ] - ( S5*sy[2] ); + dy7 = sy[ 0 ] - ( S6*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } +} + + +// EXPORTS // + +module.exports = assign8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_accessors.js new file mode 100644 index 000000000000..e7ed9e51ee23 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_accessors.js @@ -0,0 +1,228 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of an eight-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign8d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign8d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 7 ]; + S1 = sh[ 6 ]; + S2 = sh[ 5 ]; + S3 = sh[ 4 ]; + S4 = sh[ 3 ]; + S5 = sh[ 2 ]; + S6 = sh[ 1 ]; + S7 = sh[ 0 ]; + dy0 = sy[ 7 ]; + dy1 = sy[ 6 ] - ( S0*sy[7] ); + dy2 = sy[ 5 ] - ( S1*sy[6] ); + dy3 = sy[ 4 ] - ( S2*sy[5] ); + dy4 = sy[ 3 ] - ( S3*sy[4] ); + dy5 = sy[ 2 ] - ( S4*sy[3] ); + dy6 = sy[ 1 ] - ( S5*sy[2] ); + dy7 = sy[ 0 ] - ( S6*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } +} + + +// EXPORTS // + +module.exports = assign8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked.js new file mode 100644 index 000000000000..6d2d3bf1b3c6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked.js @@ -0,0 +1,287 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns elements in an eight-dimensional input ndarray to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign8d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign8d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + oy7 = oy + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked_accessors.js new file mode 100644 index 000000000000..c2bba1ed2e8c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/8d_blocked_accessors.js @@ -0,0 +1,314 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns elements in an eight-dimensional input ndarray to elements in an equivalently shaped output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign8d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign8d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + oy7 = oy + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign8d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d.js new file mode 100644 index 000000000000..0d88a5e89c1f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d.js @@ -0,0 +1,211 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a nine-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assign9d( x, y, true ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assign9d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dy0 = sy[ 8 ]; + dy1 = sy[ 7 ] - ( S0*sy[8] ); + dy2 = sy[ 6 ] - ( S1*sy[7] ); + dy3 = sy[ 5 ] - ( S2*sy[6] ); + dy4 = sy[ 4 ] - ( S3*sy[5] ); + dy5 = sy[ 3 ] - ( S4*sy[4] ); + dy6 = sy[ 2 ] - ( S5*sy[3] ); + dy7 = sy[ 1 ] - ( S6*sy[2] ); + dy8 = sy[ 0 ] - ( S7*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } +} + + +// EXPORTS // + +module.exports = assign9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_accessors.js new file mode 100644 index 000000000000..94eee11942b5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_accessors.js @@ -0,0 +1,238 @@ +/** +* @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 max-depth */ + +'use strict'; + +// MAIN // + +/** +* Assigns a scalar value to every element of a nine-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @param {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assign9d( x, y, true ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assign9d( x, y, isRowMajor ) { + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var sh; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + + // Note on variable naming convention: S#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sh = y.shape; + sy = y.strides; + if ( isRowMajor ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = sh[ 8 ]; + S1 = sh[ 7 ]; + S2 = sh[ 6 ]; + S3 = sh[ 5 ]; + S4 = sh[ 4 ]; + S5 = sh[ 3 ]; + S6 = sh[ 2 ]; + S7 = sh[ 1 ]; + S8 = sh[ 0 ]; + dy0 = sy[ 8 ]; + dy1 = sy[ 7 ] - ( S0*sy[8] ); + dy2 = sy[ 6 ] - ( S1*sy[7] ); + dy3 = sy[ 5 ] - ( S2*sy[6] ); + dy4 = sy[ 4 ] - ( S3*sy[5] ); + dy5 = sy[ 3 ] - ( S4*sy[4] ); + dy6 = sy[ 2 ] - ( S5*sy[3] ); + dy7 = sy[ 1 ] - ( S6*sy[2] ); + dy8 = sy[ 0 ] - ( S7*sy[1] ); + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = sh[ 0 ]; + S1 = sh[ 1 ]; + S2 = sh[ 2 ]; + S3 = sh[ 3 ]; + S4 = sh[ 4 ]; + S5 = sh[ 5 ]; + S6 = sh[ 6 ]; + S7 = sh[ 7 ]; + S8 = sh[ 8 ]; + dy0 = sy[ 0 ]; + dy1 = sy[ 1 ] - ( S0*sy[0] ); + dy2 = sy[ 2 ] - ( S1*sy[1] ); + dy3 = sy[ 3 ] - ( S2*sy[2] ); + dy4 = sy[ 4 ] - ( S3*sy[3] ); + dy5 = sy[ 5 ] - ( S4*sy[4] ); + dy6 = sy[ 6 ] - ( S5*sy[5] ); + dy7 = sy[ 7 ] - ( S6*sy[6] ); + dy8 = sy[ 8 ] - ( S7*sy[7] ); + } + // Set the pointers to the first indexed elements in the respective ndarrays... + ix = x.offset; + iy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } +} + + +// EXPORTS // + +module.exports = assign9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked.js new file mode 100644 index 000000000000..aceb1c13cb79 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked.js @@ -0,0 +1,306 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a nine-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* blockedassign9d( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function blockedassign9d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + oy8 = oy + ( j8*sy[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dy8 = sy[8] - ( s7*sy[7] ); + oy7 = oy8 + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + ybuf[ iy ] = xbuf[ ix ]; + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked_accessors.js new file mode 100644 index 000000000000..18dac3d2b884 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/9d_blocked_accessors.js @@ -0,0 +1,333 @@ +/** +* @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 max-depth, max-len */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); + + +// MAIN // + +/** +* Assigns a scalar value to every element of a nine-dimensional output ndarray via loop blocking. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 1, 1, 1, 1, 1, 1, 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 2, 2, 2, 2, 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* blockedassign9d( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function blockedassign9d( x, y ) { // eslint-disable-line max-statements + var bsize; + var xbuf; + var ybuf; + var get; + var set; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dy5; + var dy6; + var dy7; + var dy8; + var oy1; + var oy2; + var oy3; + var oy4; + var oy5; + var oy6; + var oy7; + var oy8; + var sh; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var s8; + var sy; + var oy; + var ix; + var iy; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var j0; + var j1; + var j2; + var j3; + var j4; + var j5; + var j6; + var j7; + var j8; + var o; + + // Note on variable naming convention: s#, dy#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + // Resolve the loop interchange order: + o = loopOrder( y.shape, y.strides ); + sh = o.sh; + sy = o.sx; + + // Determine the block size: + bsize = blockSize( y.dtype ); + + // Cache the indices of the first indexed elements in the respective ndarrays... + ix = x.offset; + oy = y.offset; + + // Cache references to the input and output ndarray buffers... + xbuf = x.data; + ybuf = y.data; + + // Cache the offset increment for the innermost loop... + dy0 = sy[0]; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over blocks... + for ( j8 = sh[8]; j8 > 0; ) { + if ( j8 < bsize ) { + s8 = j8; + j8 = 0; + } else { + s8 = bsize; + j8 -= bsize; + } + oy8 = oy + ( j8*sy[8] ); + for ( j7 = sh[7]; j7 > 0; ) { + if ( j7 < bsize ) { + s7 = j7; + j7 = 0; + } else { + s7 = bsize; + j7 -= bsize; + } + dy8 = sy[8] - ( s7*sy[7] ); + oy7 = oy8 + ( j7*sy[7] ); + for ( j6 = sh[6]; j6 > 0; ) { + if ( j6 < bsize ) { + s6 = j6; + j6 = 0; + } else { + s6 = bsize; + j6 -= bsize; + } + dy7 = sy[7] - ( s6*sy[6] ); + oy6 = oy7 + ( j6*sy[6] ); + for ( j5 = sh[5]; j5 > 0; ) { + if ( j5 < bsize ) { + s5 = j5; + j5 = 0; + } else { + s5 = bsize; + j5 -= bsize; + } + dy6 = sy[6] - ( s5*sy[5] ); + oy5 = oy6 + ( j5*sy[5] ); + for ( j4 = sh[4]; j4 > 0; ) { + if ( j4 < bsize ) { + s4 = j4; + j4 = 0; + } else { + s4 = bsize; + j4 -= bsize; + } + dy5 = sy[5] - ( s4*sy[4] ); + oy4 = oy5 + ( j4*sy[4] ); + for ( j3 = sh[3]; j3 > 0; ) { + if ( j3 < bsize ) { + s3 = j3; + j3 = 0; + } else { + s3 = bsize; + j3 -= bsize; + } + dy4 = sy[4] - ( s3*sy[3] ); + oy3 = oy4 + ( j3*sy[3] ); + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + dy3 = sy[3] - ( s2*sy[2] ); + oy2 = oy3 + ( j2*sy[2] ); + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + dy2 = sy[2] - ( s1*sy[1] ); + oy1 = oy2 + ( j1*sy[1] ); + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute the index offset for the first output ndarray element in the current block... + iy = oy1 + ( j0*sy[0] ); + + // Compute the loop offset increment... + dy1 = sy[1] - ( s0*sy[0] ); + + // Iterate over the ndarray dimensions... + for ( i8 = 0; i8 < s8; i8++ ) { + for ( i7 = 0; i7 < s7; i7++ ) { + for ( i6 = 0; i6 < s6; i6++ ) { + for ( i5 = 0; i5 < s5; i5++ ) { + for ( i4 = 0; i4 < s4; i4++ ) { + for ( i3 = 0; i3 < s3; i3++ ) { + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + set( ybuf, iy, get( xbuf, ix ) ); + iy += dy0; + } + iy += dy1; + } + iy += dy2; + } + iy += dy3; + } + iy += dy4; + } + iy += dy5; + } + iy += dy6; + } + iy += dy7; + } + iy += dy8; + } + } + } + } + } + } + } + } + } + } +} + + +// EXPORTS // + +module.exports = blockedassign9d; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/index.js new file mode 100644 index 000000000000..120b69a865b0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/index.js @@ -0,0 +1,72 @@ +/** +* @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'; + +/** +* Assign a scalar value to every element of an output ndarray. +* +* @module @stdlib/ndarray/base/assign-scalar +* +* @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* var assignScalar = require( '@stdlib/ndarray/base/assign-scalar' ); +* +* // Create a zero-dimensional ndarray containing the scalar value: +* var x = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* // Create a data buffer: +* var ybuf = new Float64Array( 12 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sy = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var oy = 1; +* +* // Create the output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign the scalar value: +* assignScalar( [ x, y ] ); +* +* console.log( y.data ); +* // => [ 0.0, 5.0, 5.0, 0.0, 0.0, 5.0, 5.0, 0.0, 0.0, 5.0, 5.0, 0.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/main.js new file mode 100644 index 000000000000..9c4ba0ca16f9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/main.js @@ -0,0 +1,339 @@ +/** +* @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 isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' ); +var isRealDataType = require( '@stdlib/ndarray/base/assert/is-real-data-type' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var castReturn = require( '@stdlib/complex/base/cast-return' ); +var complexCtors = require( '@stdlib/complex/ctors' ); +var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ); +var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); +var blockedaccessorassign2d = require( './2d_blocked_accessors.js' ); +var blockedaccessorassign3d = require( './3d_blocked_accessors.js' ); +var blockedaccessorassign4d = require( './4d_blocked_accessors.js' ); +var blockedaccessorassign5d = require( './5d_blocked_accessors.js' ); +var blockedaccessorassign6d = require( './6d_blocked_accessors.js' ); +var blockedaccessorassign7d = require( './7d_blocked_accessors.js' ); +var blockedaccessorassign8d = require( './8d_blocked_accessors.js' ); +var blockedaccessorassign9d = require( './9d_blocked_accessors.js' ); +var blockedaccessorassign10d = require( './10d_blocked_accessors.js' ); +var blockedassign2d = require( './2d_blocked.js' ); +var blockedassign3d = require( './3d_blocked.js' ); +var blockedassign4d = require( './4d_blocked.js' ); +var blockedassign5d = require( './5d_blocked.js' ); +var blockedassign6d = require( './6d_blocked.js' ); +var blockedassign7d = require( './7d_blocked.js' ); +var blockedassign8d = require( './8d_blocked.js' ); +var blockedassign9d = require( './9d_blocked.js' ); +var blockedassign10d = require( './10d_blocked.js' ); +var accessorassign0d = require( './0d_accessors.js' ); +var accessorassign1d = require( './1d_accessors.js' ); +var accessorassign2d = require( './2d_accessors.js' ); +var accessorassign3d = require( './3d_accessors.js' ); +var accessorassign4d = require( './4d_accessors.js' ); +var accessorassign5d = require( './5d_accessors.js' ); +var accessorassign6d = require( './6d_accessors.js' ); +var accessorassign7d = require( './7d_accessors.js' ); +var accessorassign8d = require( './8d_accessors.js' ); +var accessorassign9d = require( './9d_accessors.js' ); +var accessorassign10d = require( './10d_accessors.js' ); +var accessorassignnd = require( './nd_accessors.js' ); +var assign0d = require( './0d.js' ); +var assign1d = require( './1d.js' ); +var assign2d = require( './2d.js' ); +var assign3d = require( './3d.js' ); +var assign4d = require( './4d.js' ); +var assign5d = require( './5d.js' ); +var assign6d = require( './6d.js' ); +var assign7d = require( './7d.js' ); +var assign8d = require( './8d.js' ); +var assign9d = require( './9d.js' ); +var assign10d = require( './10d.js' ); +var assignnd = require( './nd.js' ); + + +// VARIABLES // + +var ASSIGN = [ + assign0d, + assign1d, + assign2d, + assign3d, + assign4d, + assign5d, + assign6d, + assign7d, + assign8d, + assign9d, + assign10d +]; +var ACCESSOR_ASSIGN = [ + accessorassign0d, + accessorassign1d, + accessorassign2d, + accessorassign3d, + accessorassign4d, + accessorassign5d, + accessorassign6d, + accessorassign7d, + accessorassign8d, + accessorassign9d, + accessorassign10d +]; +var BLOCKED_ASSIGN = [ + blockedassign2d, // 0 + blockedassign3d, + blockedassign4d, + blockedassign5d, + blockedassign6d, + blockedassign7d, + blockedassign8d, + blockedassign9d, + blockedassign10d // 8 +]; +var BLOCKED_ACCESSOR_ASSIGN = [ + blockedaccessorassign2d, // 0 + blockedaccessorassign3d, + blockedaccessorassign4d, + blockedaccessorassign5d, + blockedaccessorassign6d, + blockedaccessorassign7d, + blockedaccessorassign8d, + blockedaccessorassign9d, + blockedaccessorassign10d // 8 +]; +var MAX_DIMS = ASSIGN.length - 1; + + +// FUNCTIONS // + +/** +* Converts a boolean ndarray to an 8-bit unsigned integer ndarray. +* +* ## Notes +* +* - The function mutates the input ndarray object. +* +* @private +* @param {Object} x - input ndarray object +* @returns {Object} output ndarray object +*/ +function boolean2uint8( x ) { + x.data = reinterpretBoolean( x.data, 0 ); + x.accessorProtocol = false; + return x; +} + + +// MAIN // + +/** +* Assigns a scalar value to every element of an output ndarray. +* +* ## Notes +* +* - Each provided ndarray should be an object with the following properties: +* +* - **dtype**: data type. +* - **data**: data buffer. +* - **shape**: dimensions. +* - **strides**: stride lengths. +* - **offset**: index offset. +* - **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). +* +* @param {ArrayLikeObject} arrays - array-like object containing a zero-dimensional ndarray containing the scalar value and one output ndarray +* @returns {void} +* +* @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a zero-dimensional ndarray containing the scalar value: +* var x = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* // Create a data buffer: +* var ybuf = new Float64Array( 12 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sy = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var oy = 1; +* +* // Create the output ndarray-like object: +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign the scalar value: +* assignScalar( [ x, y ] ); +* +* console.log( y.data ); +* // => [ 0.0, 5.0, 5.0, 0.0, 0.0, 5.0, 5.0, 0.0, 0.0, 5.0, 5.0, 0.0 ] +*/ +function assignScalar( arrays ) { + var ndims; + var ymmv; + var shy; + var ioy; + var len; + var sy; + var oy; + var ns; + var x; + var y; + var d; + var i; + + // Unpack the ndarrays and standardize ndarray meta data: + x = ndarray2object( arrays[ 0 ] ); + y = ndarray2object( arrays[ 1 ] ); + + // Check for known array types which can be reinterpreted for better iteration performance... + if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) ) { + x = boolean2uint8( x ); + y = boolean2uint8( y ); + } + // Determine whether we are casting a real data type to a complex data type and we need to use a specialized accessor... + else if ( isRealDataType( x.dtype ) && isComplexDataType( y.dtype ) ) { + x.accessorProtocol = true; + x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( String( y.dtype ) ) ); // eslint-disable-line max-len + } + shy = y.shape; + ndims = shy.length; + + // Determine whether we can avoid iteration altogether... + if ( ndims === 0 ) { + if ( x.accessorProtocol || y.accessorProtocol ) { + return ACCESSOR_ASSIGN[ ndims ]( x, y ); + } + return ASSIGN[ ndims ]( x, y ); + } + // Compute the number of elements and the number of singleton dimensions... + len = 1; // number of elements + ns = 0; // number of singleton dimensions + for ( i = 0; i < ndims; i++ ) { + d = shy[ i ]; + + // Note that, if one of the dimensions is `0`, the length will be `0`... + len *= d; + + // Check whether the current dimension is a singleton dimension... + if ( d === 1 ) { + ns += 1; + } + } + // Check whether we were provided an empty ndarray... + if ( len === 0 ) { + return; + } + // Determine whether the ndarray is one-dimensional and thus readily translates to a one-dimensional strided array... + if ( ndims === 1 ) { + if ( x.accessorProtocol || y.accessorProtocol ) { + return ACCESSOR_ASSIGN[ ndims ]( x, y ); + } + return ASSIGN[ ndims ]( x, y ); + } + sy = y.strides; + + // Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can treat the ndarray as being equivalent to a one-dimensional strided array... + if ( ns === ndims-1 ) { + // Get the index of the non-singleton dimension... + for ( i = 0; i < ndims; i++ ) { + if ( shy[ i ] !== 1 ) { + break; + } + } + y.shape = [ shy[i] ]; + y.strides = [ sy[i] ]; + if ( x.accessorProtocol || y.accessorProtocol ) { + return ACCESSOR_ASSIGN[ 1 ]( x, y ); + } + return ASSIGN[ 1 ]( x, y ); + } + ioy = iterationOrder( sy ); // +/-1 + + // Determine whether we can avoid blocked iteration... + if ( ioy !== 0 ) { + // Determine the minimum and maximum linear indices which are accessible by the array view: + ymmv = minmaxViewBufferIndex( shy, sy, y.offset ); + + // Determine whether we can ignore shape (and strides) and treat the ndarray as a linear one-dimensional strided array... + if ( len === ( ymmv[1]-ymmv[0]+1 ) ) { + // Note: the above is equivalent to @stdlib/ndarray/base/assert/is-contiguous, but in-lined so we can retain computed values... + if ( ioy === 1 ) { + oy = ymmv[ 0 ]; + } else { + oy = ymmv[ 1 ]; + } + y.shape = [ len ]; + y.strides = [ ioy ]; + y.offset = oy; + if ( x.accessorProtocol || y.accessorProtocol ) { + return ACCESSOR_ASSIGN[ 1 ]( x, y ); + } + return ASSIGN[ 1 ]( x, y ); + } + // The ndarray is non-contiguous, so we cannot directly use one-dimensional array functionality... + + // Determine whether we can use simple nested loops... + if ( ndims <= MAX_DIMS ) { + // So long as iteration always moves in the same direction (i.e., no mixed sign strides), we can leverage cache-optimal (i.e., normal) nested loops without resorting to blocked iteration... + if ( x.accessorProtocol || y.accessorProtocol ) { + return ACCESSOR_ASSIGN[ ndims ]( x, y ); + } + return ASSIGN[ ndims ]( x, y ); + } + // Fall-through to blocked iteration... + } + // At this point, we're either dealing with a non-contiguous n-dimensional array or a high dimensional n-dimensional array, so our only hope is that we can still perform blocked iteration... + + // Determine whether we can perform blocked iteration... + if ( ndims <= MAX_DIMS ) { + if ( x.accessorProtocol || y.accessorProtocol ) { + return BLOCKED_ACCESSOR_ASSIGN[ ndims-2 ]( x, y ); + } + return BLOCKED_ASSIGN[ ndims-2 ]( x, y ); + } + // Fall-through to linear view iteration without regard for how data is stored in memory (i.e., take the slow path)... + if ( x.accessorProtocol || y.accessorProtocol ) { + return accessorassignnd( x, y ); + } + assignnd( x, y ); +} + + +// EXPORTS // + +module.exports = assignScalar; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd.js new file mode 100644 index 000000000000..3fabf1e87357 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd.js @@ -0,0 +1,139 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Assigns a scalar value to every element of an n-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether \`x\` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether \`y\` is row-major (C-style) or column-major (Fortran-style) +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 2.0 ] ); +* var ybuf = new Float64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* +* // Assign scalar: +* assignnd( x, y ); +* +* console.log( y.data ); +* // => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +*/ +function assignnd( x, y ) { + var xbuf; + var ybuf; + var ordy; + var len; + var shy; + var sy; + var oy; + var ix; + var iy; + var i; + + shy = y.shape; + + // Compute the total number of elements over which to iterate: + len = numel( shy ); + + // Cache references to the input and output ndarray data buffers: + xbuf = x.data; + ybuf = y.data; + + // Cache references to the respective stride arrays: + sy = y.strides; + + // Cache the index of the first indexed element in the input ndarray: + ix = x.offset; + + // Cache the index of the first indexed element in the output ndarray: + oy = y.offset; + + // Cache the output array order: + ordy = y.order; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + iy = vind2bind( shy, sy, oy, ordy, i, MODE ); + ybuf[ iy ] = xbuf[ ix ]; + } +} + + +// EXPORTS // + +module.exports = assignnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd_accessors.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd_accessors.js new file mode 100644 index 000000000000..2b20d02725d4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/lib/nd_accessors.js @@ -0,0 +1,166 @@ +/** +* @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 numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Assigns a scalar value to every element of an n-dimensional output ndarray. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether \`x\` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} x.accessors - data buffer accessors +* @param {Object} y - object containing output ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether \`y\` is row-major (C-style) or column-major (Fortran-style) +* @param {Array} y.accessors - data buffer accessors +* @returns {void} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* // Create data buffers: +* var xbuf = new Complex64Array( [ 2.0, 2.0 ] ); +* var ybuf = new Complex64Array( 6 ); +* +* // Define the shape of the output array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 0 ]; +* var sy = [ 2, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* +* // Define getters and setters: +* function getter( buf, idx ) { +* return buf.get( idx ); +* } +* +* function setter( buf, idx, value ) { +* buf.set( value, idx ); +* } +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'complex64', +* 'data': xbuf, +* 'shape': [], +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* var y = { +* 'dtype': 'complex64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major', +* 'accessors': [ getter, setter ] +* }; +* +* // Assign scalar: +* assignnd( x, y ); +* +* var v = y.data.get( 0 ); +* +* var re = realf( v ); +* // returns 2.0 +* +* var im = imagf( v ); +* // returns 2.0 +*/ +function assignnd( x, y ) { + var xbuf; + var ybuf; + var ordy; + var len; + var get; + var set; + var shy; + var sy; + var oy; + var ix; + var iy; + var i; + + shy = y.shape; + + // Compute the total number of elements over which to iterate: + len = numel( shy ); + + // Cache references to the input and output ndarray data buffers: + xbuf = x.data; + ybuf = y.data; + + // Cache references to the respective stride arrays: + sy = y.strides; + + // Cache the index of the first indexed element in the input ndarray: + ix = x.offset; + + // Cache the index of the first indexed element in the output ndarray: + oy = y.offset; + + // Cache the output array order: + ordy = y.order; + + // Cache accessors: + get = x.accessors[0]; + set = y.accessors[1]; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + iy = vind2bind( shy, sy, oy, ordy, i, MODE ); + set( ybuf, iy, get( xbuf, ix ) ); + } +} + + +// EXPORTS // + +module.exports = assignnd; diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/package.json b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/package.json new file mode 100644 index 000000000000..ef820a963163 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/ndarray/base/assign-scalar", + "version": "0.0.0", + "description": "Assign a scalar value to every element of an output 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", + "base", + "strided", + "array", + "ndarray", + "assign", + "scalar", + "copy" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.0d.js new file mode 100644 index 000000000000..32e82d1e2fc6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.0d.js @@ -0,0 +1,79 @@ +/** +* @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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var assignScalar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assignScalar, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function assigns a scalar value to each element of a 0-dimensional output ndarray', function test( t ) { + var expected; + var v; + var y; + + y = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( [ 10.0 ] ); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each element of a 0-dimensional output ndarray (accessors)', function test( t ) { + var expected; + var v; + var y; + + y = scalar2ndarray( new Complex128( 0.0, 0.0 ), { + 'dtype': 'complex128' + }); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': 'complex128' + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( [ 10.0, 10.0 ] ); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.1d.js new file mode 100644 index 000000000000..ce3f230e63ff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.1d.js @@ -0,0 +1,126 @@ +/** +* @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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var assignScalar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assignScalar, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 1-dimensional output ndarray', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 1-dimensional output ndarray (empty array)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 8, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 1-dimensional output ndarray (accessors)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'complex128', zeros( 6, 'complex128' ), [ 4 ], [ 1 ], 1, 'row-major' ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': 'complex128' + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.2d.js new file mode 100644 index 000000000000..1771aeeae7ff --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.2d.js @@ -0,0 +1,1133 @@ +/** +* @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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var dfill = require( '@stdlib/blas/ext/base/dfill' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var assignScalar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assignScalar, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, empty)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'row-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 1 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 1 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 4, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, empty)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 1, 1 ], 0, 'column-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -1, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2 ]; + st = [ 2, -bsize*4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 2-dimensional output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.3d.js new file mode 100644 index 000000000000..67111e4b9903 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.3d.js @@ -0,0 +1,1269 @@ +/** +* @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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var dfill = require( '@stdlib/blas/ext/base/dfill' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var assignScalar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assignScalar, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, empty)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'row-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = [ -4, -2, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 3, 2, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -3, -2, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -4, -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 2 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 1, bsize*2, 2 ]; + st = [ -bsize*8, -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 2 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 1, 2, bsize*2 ]; + st = [ bsize*8, bsize*4, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 2 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, -10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = [ -4, -2, -1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 3, 2, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -3, -2, 1 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -4, -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 2 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 1, bsize*2, 2 ]; + st = [ -bsize*8, -4, 2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 2 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 1, 2, bsize*2 ]; + st = [ bsize*8, bsize*4, -2 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 2 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, empty)', function test( t ) { + var expected; + var v; + var y; + + y = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0 ], [ 1, 1, 1 ], 0, 'column-major' ); + + v = scalar2ndarray( 10.0, { + 'dtype': 'float64' + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = [ -1, -2, -4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, 2, 3 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, 3 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.0, + 10.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2 ]; + st = [ -2, bsize*4, bsize*4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ 2, -4, -bsize*8 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ 2, -4, -4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( 10.0, { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Float64Array( y.length*2 ); + dfill( y.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, -10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = [ -1, -2, -4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ 1, 2, 3 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = [ -1, -2, 3 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 2, 1 ]; + st = [ 2, -bsize*4, -bsize*8 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1 ]; + st = [ -2, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function assigns a scalar value to each indexed element of a 3-dimensional output ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var v; + var y; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2 ]; + st = [ 2, -4, 4 ]; + o = strides2offset( sh, st ); + + y = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + v = scalar2ndarray( new Complex128( 10.0, 10.0 ), { + 'dtype': dt + }); + assignScalar( [ v, y ] ); + + expected = new Complex128Array( y.length*2 ); + gfill( y.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.js b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.js new file mode 100644 index 000000000000..b7a624eb4aa1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/assign-scalar/test/test.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var assignScalar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assignScalar, 'function', 'main export is a function' ); + t.end(); +});