From 20b1a7ebc7ee63b966e727f8df65564120d26770 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 28 Mar 2026 19:29:26 +0500 Subject: [PATCH 01/13] feat: add blas/ext/circshift --- 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 --- --- .../@stdlib/blas/ext/circshift/README.md | 156 +++ .../blas/ext/circshift/benchmark/benchmark.js | 106 ++ .../@stdlib/blas/ext/circshift/docs/repl.txt | 49 + .../blas/ext/circshift/docs/types/index.d.ts | 85 ++ .../blas/ext/circshift/docs/types/test.ts | 123 ++ .../blas/ext/circshift/examples/index.js | 41 + .../@stdlib/blas/ext/circshift/lib/base.js | 105 ++ .../@stdlib/blas/ext/circshift/lib/index.js | 59 + .../@stdlib/blas/ext/circshift/lib/main.js | 133 ++ .../@stdlib/blas/ext/circshift/package.json | 66 + .../@stdlib/blas/ext/circshift/test/test.js | 1223 +++++++++++++++++ 11 files changed, 2146 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/circshift/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/README.md b/lib/node_modules/@stdlib/blas/ext/circshift/README.md new file mode 100644 index 000000000000..cffb7d8df1b4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/README.md @@ -0,0 +1,156 @@ + + +# circshift + +> Circularly shift the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions by a specified number of positions. + +
+ +## Usage + +```javascript +var circshift = require( '@stdlib/blas/ext/circshift' ); +``` + +#### circshift( x, k\[, options] ) + +Circularly shifts the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions by a specified number of positions. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +var y = circshift( x, 2 ); +// returns + +var arr = ndarray2array( y ); +// returns [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + +var bool = ( x === y ); +// returns true +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **k**: number of positions to shift. May be either a numeric scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] for `k` must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] for `k` must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +By default, the function circularly shifts all elements. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var v = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var y = circshift( x, 1, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +``` + +
+ + + +
+ +## Notes + +- The input [ndarray][@stdlib/ndarray/ctor] is shifted **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**). +- A positive `k` shifts elements to the right (toward higher indices). A negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input [ndarray][@stdlib/ndarray/ctor] is left unchanged. +- The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the circular shift. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var circshift = require( '@stdlib/blas/ext/circshift' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -20, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +circshift( x, 2, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/circshift/benchmark/benchmark.js new file mode 100644 index 000000000000..625873c26f56 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var circshift = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = circshift( x, ( i%len ) + 1 ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( 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 f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt new file mode 100644 index 000000000000..e05e93812e76 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( x, k[, options] ) + Circularly shifts the elements of an input ndarray along one or more + ndarray dimensions by a specified number of positions. + + A positive `k` shifts elements to the right (toward higher indices). A + negative `k` shifts elements to the left (toward lower indices). If `k` is + zero, the input ndarray is left unchanged. + + The function circularly shifts an input ndarray in-place and thus mutates + an input ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + k: ndarray|number + Number of positions to shift. May be either a scalar value or an + ndarray having an integer data type. If provided an ndarray, the value + must have a shape which is broadcast compatible with the complement of + the shape defined by `options.dims`. For example, given the input shape + `[2, 3, 4]` and `options.dims=[0]`, an ndarray for `k` must have a + shape which is broadcast compatible with the shape `[3, 4]`. Similarly, + when performing the operation over all elements in a provided input + ndarray, an ndarray for `k` must be a zero-dimensional ndarray. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Input array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = {{alias}}( x, 2 ); + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts new file mode 100644 index 000000000000..b2f1a9df5d09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts @@ -0,0 +1,85 @@ +/* +* @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 { typedndarray, integerndarray } from '@stdlib/types/ndarray'; + +/** +* Number of positions to shift. +*/ +type K = integerndarray | number; + + +/** +* Interface defining options. +*/ +interface Options { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +*/ +type Circshift = ( x: typedndarray, k: K, options?: Options ) => typedndarray; + +/** +* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* +* ## Notes +* +* - The input ndarray is shifted **in-place** (i.e., the input ndarray is **mutated**). +* - A positive `k` shifts elements to the right (toward higher indices). A negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input ndarray is left unchanged. +* +* @param x - input ndarray +* @param k - number of positions to shift +* @param options - function options +* @returns output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 3, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); +* +* var y = circshift( x, 2 ); +* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 3, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); +* +* var y = circshift( x, -1 ); +* // returns [ [ [ 2.0, 3.0 ] ], [ [ 4.0, 5.0 ] ], [ [ 6.0, 1.0 ] ] ] +*/ +declare const circshift: Circshift; + + +// EXPORTS // + +export = circshift; diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts new file mode 100644 index 000000000000..940941b2311e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts @@ -0,0 +1,123 @@ +/* +* @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 space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import circshift = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + circshift( x, 2 ); // $ExpectType typedndarray + circshift( x, 2, {} ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + circshift( '5', 2 ); // $ExpectError + circshift( 5, 2 ); // $ExpectError + circshift( true, 2 ); // $ExpectError + circshift( false, 2 ); // $ExpectError + circshift( null, 2 ); // $ExpectError + circshift( void 0, 2 ); // $ExpectError + circshift( {}, 2 ); // $ExpectError + circshift( ( x: number ): number => x, 2 ); // $ExpectError + + circshift( '5', 2, {} ); // $ExpectError + circshift( 5, 2, {} ); // $ExpectError + circshift( true, 2, {} ); // $ExpectError + circshift( false, 2, {} ); // $ExpectError + circshift( null, 2, {} ); // $ExpectError + circshift( void 0, 2, {} ); // $ExpectError + circshift( {}, 2, {} ); // $ExpectError + circshift( ( x: number ): number => x, 2, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `k` argument which is not an ndarray or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + circshift( x, true ); // $ExpectError + circshift( x, false ); // $ExpectError + circshift( x, '5' ); // $ExpectError + circshift( x, null ); // $ExpectError + circshift( x, void 0 ); // $ExpectError + circshift( x, [] ); // $ExpectError + circshift( x, {} ); // $ExpectError + circshift( x, ( x: number ): number => x ); // $ExpectError + + circshift( x, true, {} ); // $ExpectError + circshift( x, false, {} ); // $ExpectError + circshift( x, '5', {} ); // $ExpectError + circshift( x, null, {} ); // $ExpectError + circshift( x, void 0, {} ); // $ExpectError + circshift( x, [], {} ); // $ExpectError + circshift( x, {}, {} ); // $ExpectError + circshift( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + circshift( x, 2, '5' ); // $ExpectError + circshift( x, 2, true ); // $ExpectError + circshift( x, 2, false ); // $ExpectError + circshift( x, 2, null ); // $ExpectError + circshift( x, 2, [] ); // $ExpectError + circshift( x, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + circshift( x, 2, { 'dims': '5' } ); // $ExpectError + circshift( x, 2, { 'dims': 5 } ); // $ExpectError + circshift( x, 2, { 'dims': true } ); // $ExpectError + circshift( x, 2, { 'dims': false } ); // $ExpectError + circshift( x, 2, { 'dims': null } ); // $ExpectError + circshift( x, 2, { 'dims': {} } ); // $ExpectError + circshift( x, 2, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + circshift(); // $ExpectError + circshift( x ); // $ExpectError + circshift( x, 2, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js b/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js new file mode 100644 index 000000000000..60c5cabac8ea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var circshift = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -20, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +circshift( x, 2, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js new file mode 100644 index 000000000000..f56c3bdeeb84 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -0,0 +1,105 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gcircshift = require( '@stdlib/blas/ext/base/ndarray/gcircshift' ); +var dcircshift = require( '@stdlib/blas/ext/base/ndarray/dcircshift' ); +var scircshift = require( '@stdlib/blas/ext/base/ndarray/scircshift' ); +var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'integer' ); // k ndarray +var odtypes = dtypes( 'all' ); +var table = { + 'types': [ + 'float64', // input/output + 'float32' // input/output + ], + 'fcns': [ + dcircshift, + scircshift + ], + 'default': gcircshift +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* +* @private +* @name circshift +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} k - ndarray containing the number of positions to shift +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create an ndarray containing the number of positions to shift: +* var k = scalar2ndarray( 2, { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = circshift( x, k ); +* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +*/ +var circshift = factory( table, [ idtypes0, idtypes1 ], odtypes, options ); + + +// EXPORTS // + +module.exports = circshift; diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js new file mode 100644 index 000000000000..d108ff5e154c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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'; + +/** +* Circularly shift the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* +* @module @stdlib/blas/ext/circshift +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var circshift = require( '@stdlib/blas/ext/circshift' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = circshift( x, 2 ); +* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js new file mode 100644 index 000000000000..98cfffad6ab1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -0,0 +1,133 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); + + +// MAIN // + +/** +* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number)} k - number of positions to shift +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = circshift( x, 2 ); +* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +*/ +function circshift( x, k ) { + var nargs; + var opts; + var ord; + var sh; + var o; + + nargs = arguments.length; + ord = getOrder( x ); + + o = k; + + // Case: circshift( x, k ) + if ( nargs === 2 ) { + // Case: circshift( x, k_scalar ) + if ( isNumber( o ) ) { + return base( x, broadcastScalar( o, DEFAULT_DTYPE, [], ord ) ); + } + // Case: circshift( x, k_ndarray ) + if ( isndarrayLike( o ) ) { + // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... + return base( x, o ); + } + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', o ) ); + } + // Case: circshift( x, k, opts ) + opts = arguments[ 2 ]; + + // Case: circshift( x, k_scalar, opts ) + if ( isNumber( o ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + o = broadcastScalar( o, DEFAULT_DTYPE, sh, getOrder( x ) ); + } + // Case: circshift( x, k_ndarray, opts ) + else if ( isndarrayLike( o ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `o` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `o` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + o = maybeBroadcastArray( o, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', o ) ); + } + return base( x, o, opts ); +} + + +// EXPORTS // + +module.exports = circshift; diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/package.json b/lib/node_modules/@stdlib/blas/ext/circshift/package.json new file mode 100644 index 000000000000..c9aaccebb48f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/circshift", + "version": "0.0.0", + "description": "Circularly shift the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "circular", + "shift", + "circshift", + "rotate", + "roll", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js b/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js new file mode 100644 index 000000000000..3384068c57fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js @@ -0,0 +1,1223 @@ +/** +* @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 Int32Array = require( '@stdlib/array/int32' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var circshift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof circshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( value, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (ndarray k)', function test( t ) { + var values; + var k; + var i; + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( value, k ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( value, 2, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (ndarray k, options)', function test( t ) { + var values; + var k; + var i; + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( value, k, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or a numeric scalar', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or a numeric scalar (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (scalar k)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (ndarray k)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, scalar2ndarray( 2, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (ndarray k)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, scalar2ndarray( 2, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (ndarray k)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, scalar2ndarray( 2, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (ndarray k)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, scalar2ndarray( 2, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (ndarray k)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'int32' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + circshift( x, scalar2ndarray( 2, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function circularly shifts elements in an input ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 1 ); + expected = [ 4.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in an input ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 1 ); + expected = [ 4.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in an input ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 1, { + 'dims': [ 0, 1 ] + }); + expected = [ 4.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in an input ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 1, { + 'dims': [ 0, 1 ] + }); + expected = [ 4.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in an input ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 2, { + 'dims': [] + }); + expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in an input ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 2, { + 'dims': [] + }); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 1, { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 1, { + 'dims': [ 1 ] + }); + expected = [ [ 2.0, 1.0 ], [ 4.0, 3.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 1, { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 1, { + 'dims': [ 1 ] + }); + expected = [ [ 3.0, 1.0 ], [ 4.0, 2.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 2 ); + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, -1 ); + expected = [ 2.0, 3.0, 4.0, 1.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 2, {} ); + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 0, {} ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'int32' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( 2, opts ) ); + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( -1, opts ) ); + expected = [ 2.0, 3.0, 4.0, 1.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( 0, opts ) ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'int32' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( 2, opts ), {} ); + expected = [ 3.0, 4.0, 1.0, 2.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( -1, opts ), {} ); + expected = [ 2.0, 3.0, 4.0, 1.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( 0, opts ), {} ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, 1, { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, -1, { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, 0, { + 'dims': [ 0 ] + }); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (0d ndarray, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'int32' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = circshift( x, scalar2ndarray( 1, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, scalar2ndarray( -1, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = circshift( x, scalar2ndarray( 0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `k` argument (ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var kbuf; + var opts; + var x; + var k; + + opts = { + 'dtype': 'int32' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + kbuf = new Int32Array( [ 1, -1 ] ); + k = new ndarray( opts.dtype, kbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = circshift( x, k, { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + kbuf = new Int32Array( [ 0, 1 ] ); + k = new ndarray( opts.dtype, kbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = circshift( x, k, { + 'dims': [ 1 ] + }); + expected = [ [ 1.0, 2.0, 3.0 ], [ 6.0, 4.0, 5.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function circularly shifts elements in a 1d ndarray', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + actual = circshift( x, 2 ); + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + actual = circshift( x, -2 ); + expected = [ 3.0, 4.0, 5.0, 1.0, 2.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports large shift values (k > N)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + // k=7 with N=5 is equivalent to k=2 + actual = circshift( x, 7 ); + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + // k=-8 with N=5 is equivalent to k=2 (since -8%5=-3, -3+5=2) + actual = circshift( x, -8 ); + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports typed array inputs', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new ndarray( 'float64', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = circshift( x, 2 ); + expected = new Float64Array( [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new ndarray( 'float32', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); + + actual = circshift( x, 2 ); + expected = new Float32Array( [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float32', 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); From 73e83459237305d60040e8899d97d51887aef3e4 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 29 Mar 2026 22:58:16 +0500 Subject: [PATCH 02/13] fix: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: 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: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/circshift/README.md | 18 ++-- .../@stdlib/blas/ext/circshift/docs/repl.txt | 27 +++--- .../blas/ext/circshift/docs/types/index.d.ts | 20 ++-- .../blas/ext/circshift/docs/types/test.ts | 4 +- .../blas/ext/circshift/examples/index.js | 10 +- .../@stdlib/blas/ext/circshift/lib/base.js | 8 +- .../@stdlib/blas/ext/circshift/lib/index.js | 2 +- .../@stdlib/blas/ext/circshift/lib/main.js | 16 +-- .../@stdlib/blas/ext/circshift/package.json | 2 +- .../@stdlib/blas/ext/circshift/test/test.js | 97 ++++++------------- 10 files changed, 79 insertions(+), 125 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/README.md b/lib/node_modules/@stdlib/blas/ext/circshift/README.md index cffb7d8df1b4..326f38a72b73 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/README.md +++ b/lib/node_modules/@stdlib/blas/ext/circshift/README.md @@ -20,7 +20,7 @@ limitations under the License. # circshift -> Circularly shift the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions by a specified number of positions. +> Circularly shift the elements of an input [ndarray][@stdlib/ndarray/ctor] by a specified number of positions along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
@@ -32,7 +32,7 @@ var circshift = require( '@stdlib/blas/ext/circshift' ); #### circshift( x, k\[, options] ) -Circularly shifts the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions by a specified number of positions. +Circularly shifts the elements of an input [ndarray][@stdlib/ndarray/ctor] by a specified number of positions along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. ```javascript var ndarray2array = require( '@stdlib/ndarray/to-array' ); @@ -53,7 +53,7 @@ var bool = ( x === y ); The function has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. -- **k**: number of positions to shift. May be either a numeric scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] for `k` must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] for `k` must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. +- **k**: number of positions to shift. May be either an integer scalar value or an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] for `k` must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] for `k` must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. - **options**: function options (_optional_). The function accepts the following options: @@ -92,7 +92,7 @@ v = ndarray2array( y ); ## Notes - The input [ndarray][@stdlib/ndarray/ctor] is shifted **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**). -- A positive `k` shifts elements to the right (toward higher indices). A negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input [ndarray][@stdlib/ndarray/ctor] is left unchanged. +- When shifting elements along a single dimension, a positive `k` shifts elements to the right (toward higher indices), and a negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input [ndarray][@stdlib/ndarray/ctor] is left unchanged. - The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the circular shift.
@@ -106,18 +106,14 @@ v = ndarray2array( y ); ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var circshift = require( '@stdlib/blas/ext/circshift' ); -// Generate an array of random numbers: -var xbuf = discreteUniform( 25, -20, 20, { +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { 'dtype': 'generic' }); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Perform operation: diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt index e05e93812e76..9b875ba39213 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/repl.txt @@ -1,11 +1,12 @@ {{alias}}( x, k[, options] ) - Circularly shifts the elements of an input ndarray along one or more - ndarray dimensions by a specified number of positions. + Circularly shifts the elements of an input ndarray by a specified number + of positions along one or more ndarray dimensions. - A positive `k` shifts elements to the right (toward higher indices). A - negative `k` shifts elements to the left (toward lower indices). If `k` is - zero, the input ndarray is left unchanged. + When shifting elements along a single dimension, a positive `k` shifts + elements to the right (toward higher indices), and a negative `k` shifts + elements to the left (toward lower indices). If `k` is zero, the input + ndarray is left unchanged. The function circularly shifts an input ndarray in-place and thus mutates an input ndarray. @@ -16,14 +17,14 @@ Input array. k: ndarray|number - Number of positions to shift. May be either a scalar value or an - ndarray having an integer data type. If provided an ndarray, the value - must have a shape which is broadcast compatible with the complement of - the shape defined by `options.dims`. For example, given the input shape - `[2, 3, 4]` and `options.dims=[0]`, an ndarray for `k` must have a - shape which is broadcast compatible with the shape `[3, 4]`. Similarly, - when performing the operation over all elements in a provided input - ndarray, an ndarray for `k` must be a zero-dimensional ndarray. + Number of positions to shift. May be either a scalar value or an ndarray + having a real-valued or "generic" data type. If provided an ndarray, the + value must have a shape which is broadcast compatible with the + complement of the shape defined by `options.dims`. For example, given + the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray for `k` + must have a shape which is broadcast compatible with the shape `[3, 4]`. + Similarly, when performing the operation over all elements in a provided + input ndarray, an ndarray for `k` must be a zero-dimensional ndarray. options: Object (optional) Function options. diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts index b2f1a9df5d09..da8df24bff8b 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts @@ -21,13 +21,12 @@ /// import { ArrayLike } from '@stdlib/types/array'; -import { typedndarray, integerndarray } from '@stdlib/types/ndarray'; +import { typedndarray, realndarray, genericndarray } from '@stdlib/types/ndarray'; /** -* Number of positions to shift. +* Input array. */ -type K = integerndarray | number; - +type InputArray = realndarray | genericndarray; /** * Interface defining options. @@ -40,22 +39,17 @@ interface Options { } /** -* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. -*/ -type Circshift = ( x: typedndarray, k: K, options?: Options ) => typedndarray; - -/** -* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* Circularly shifts the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions. * * ## Notes * * - The input ndarray is shifted **in-place** (i.e., the input ndarray is **mutated**). -* - A positive `k` shifts elements to the right (toward higher indices). A negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input ndarray is left unchanged. +* - When shifting elements along a single dimension, a positive `k` shifts elements to the right (toward higher indices), and a negative `k` shifts elements to the left (toward lower indices). If `k` is zero, the input ndarray is left unchanged. * * @param x - input ndarray * @param k - number of positions to shift * @param options - function options -* @returns output ndarray +* @returns input ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -77,7 +71,7 @@ type Circshift = ( x: typedndarray, k: K, options?: Options ) => * var y = circshift( x, -1 ); * // returns [ [ [ 2.0, 3.0 ] ], [ [ 4.0, 5.0 ] ], [ [ 6.0, 1.0 ] ] ] */ -declare const circshift: Circshift; +declare function circshift( x: T, k: typedndarray | number, options?: Options ): T; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts index 940941b2311e..6f02f9e3b217 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/test.ts @@ -32,8 +32,8 @@ import circshift = require( './index' ); 'dtype': 'float64' }); - circshift( x, 2 ); // $ExpectType typedndarray - circshift( x, 2, {} ); // $ExpectType typedndarray + circshift( x, 2 ); // $ExpectType float64ndarray + circshift( x, 2, {} ); // $ExpectType float64ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js b/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js index 60c5cabac8ea..bdb605081ba5 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/examples/index.js @@ -18,18 +18,14 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var circshift = require( './../lib' ); -// Generate an array of random numbers: -var xbuf = discreteUniform( 25, -20, 20, { +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { 'dtype': 'generic' }); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Perform operation: diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index f56c3bdeeb84..78a95197f998 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -29,8 +29,8 @@ var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' // VARIABLES // -var idtypes0 = dtypes( 'all' ); // input ndarray -var idtypes1 = dtypes( 'integer' ); // k ndarray +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'real_and_generic' ); // k ndarray var odtypes = dtypes( 'all' ); var table = { 'types': [ @@ -51,7 +51,7 @@ var options = { // MAIN // /** -* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* Circularly shifts the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions. * * @private * @name circshift @@ -66,7 +66,7 @@ var options = { * @throws {RangeError} dimension indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions * @throws {Error} must provide valid options -* @returns {ndarray} output ndarray +* @returns {ndarray} input ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js index d108ff5e154c..c4a9ad31fd39 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Circularly shift the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* Circularly shift the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions. * * @module @stdlib/blas/ext/circshift * diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index 98cfffad6ab1..13975209c11e 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); @@ -41,19 +41,19 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); // MAIN // /** -* Circularly shifts the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions. +* Circularly shifts the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions. * * @param {ndarrayLike} x - input ndarray * @param {(ndarrayLike|number)} k - number of positions to shift * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} second argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} second argument must be either an ndarray-like object or an integer * @throws {TypeError} options argument must be an object * @throws {RangeError} dimension indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions * @throws {Error} must provide valid options -* @returns {ndarray} output ndarray +* @returns {ndarray} input ndarray * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -93,7 +93,7 @@ function circshift( x, k ) { // Case: circshift( x, k ) if ( nargs === 2 ) { // Case: circshift( x, k_scalar ) - if ( isNumber( o ) ) { + if ( isInteger( o ) ) { return base( x, broadcastScalar( o, DEFAULT_DTYPE, [], ord ) ); } // Case: circshift( x, k_ndarray ) @@ -101,13 +101,13 @@ function circshift( x, k ) { // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... return base( x, o ); } - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', o ) ); + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', o ) ); } // Case: circshift( x, k, opts ) opts = arguments[ 2 ]; // Case: circshift( x, k_scalar, opts ) - if ( isNumber( o ) ) { + if ( isInteger( o ) ) { if ( hasOwnProp( opts, 'dims' ) ) { sh = nonCoreShape( getShape( x ), opts.dims ); } else { @@ -122,7 +122,7 @@ function circshift( x, k ) { o = maybeBroadcastArray( o, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len } } else { - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.', o ) ); + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', o ) ); } return base( x, o, opts ); } diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/package.json b/lib/node_modules/@stdlib/blas/ext/circshift/package.json index c9aaccebb48f..4da2b5f8c680 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/package.json +++ b/lib/node_modules/@stdlib/blas/ext/circshift/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/circshift", "version": "0.0.0", - "description": "Circularly shift the elements of an input ndarray along one or more ndarray dimensions by a specified number of positions.", + "description": "Circularly shift the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js b/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js index 3384068c57fa..b010421f5891 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/test/test.js @@ -31,10 +31,6 @@ var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); var getData = require( '@stdlib/ndarray/data-buffer' ); -var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); -var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); -var Float64Array = require( '@stdlib/array/float64' ); -var Float32Array = require( '@stdlib/array/float32' ); var circshift = require( './../lib' ); @@ -168,7 +164,7 @@ tape( 'the function throws an error if provided a first argument which is not an } }); -tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or a numeric scalar', function test( t ) { +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer', function test( t ) { var values; var x; var i; @@ -199,7 +195,7 @@ tape( 'the function throws an error if provided a `k` argument which is not an n } }); -tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or a numeric scalar (options)', function test( t ) { +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer (options)', function test( t ) { var values; var x; var i; @@ -623,7 +619,7 @@ tape( 'the function circularly shifts elements in an input ndarray (default, row expected = [ 4.0, 1.0, 2.0, 3.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -644,7 +640,7 @@ tape( 'the function circularly shifts elements in an input ndarray (default, col expected = [ 4.0, 1.0, 2.0, 3.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -667,7 +663,7 @@ tape( 'the function circularly shifts elements in an input ndarray (all dimensio expected = [ 4.0, 1.0, 2.0, 3.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -690,7 +686,7 @@ tape( 'the function circularly shifts elements in an input ndarray (all dimensio expected = [ 4.0, 1.0, 2.0, 3.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -713,7 +709,7 @@ tape( 'the function circularly shifts elements in an input ndarray (no dimension expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -736,7 +732,7 @@ tape( 'the function circularly shifts elements in an input ndarray (no dimension expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -759,7 +755,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -773,7 +769,7 @@ tape( 'the function supports specifying operation dimensions (row-major)', funct expected = [ [ 2.0, 1.0 ], [ 4.0, 3.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -796,7 +792,7 @@ tape( 'the function supports specifying operation dimensions (column-major)', fu expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -810,7 +806,7 @@ tape( 'the function supports specifying operation dimensions (column-major)', fu expected = [ [ 3.0, 1.0 ], [ 4.0, 2.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -831,7 +827,7 @@ tape( 'the function supports providing a `k` argument (scalar)', function test( expected = [ 3.0, 4.0, 1.0, 2.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -843,7 +839,7 @@ tape( 'the function supports providing a `k` argument (scalar)', function test( expected = [ 2.0, 3.0, 4.0, 1.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -864,7 +860,7 @@ tape( 'the function supports providing a `k` argument (scalar, options)', functi expected = [ 3.0, 4.0, 1.0, 2.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -876,7 +872,7 @@ tape( 'the function supports providing a `k` argument (scalar, options)', functi expected = [ 1.0, 2.0, 3.0, 4.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -901,7 +897,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray)', function te expected = [ 3.0, 4.0, 1.0, 2.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -913,7 +909,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray)', function te expected = [ 2.0, 3.0, 4.0, 1.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -925,7 +921,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray)', function te expected = [ 1.0, 2.0, 3.0, 4.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -950,7 +946,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, options)', fu expected = [ 3.0, 4.0, 1.0, 2.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -962,7 +958,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, options)', fu expected = [ 2.0, 3.0, 4.0, 1.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -974,7 +970,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, options)', fu expected = [ 1.0, 2.0, 3.0, 4.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -997,7 +993,7 @@ tape( 'the function supports providing a `k` argument (scalar, broadcasted)', fu expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1011,7 +1007,7 @@ tape( 'the function supports providing a `k` argument (scalar, broadcasted)', fu expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1025,7 +1021,7 @@ tape( 'the function supports providing a `k` argument (scalar, broadcasted)', fu expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1052,7 +1048,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, broadcasted)' expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1066,7 +1062,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, broadcasted)' expected = [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1080,7 +1076,7 @@ tape( 'the function supports providing a `k` argument (0d ndarray, broadcasted)' expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1111,7 +1107,7 @@ tape( 'the function supports providing a `k` argument (ndarray)', function test( expected = [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1127,7 +1123,7 @@ tape( 'the function supports providing a `k` argument (ndarray)', function test( expected = [ [ 1.0, 2.0, 3.0 ], [ 6.0, 4.0, 5.0 ] ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1148,7 +1144,7 @@ tape( 'the function circularly shifts elements in a 1d ndarray', function test( expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1164,7 +1160,7 @@ tape( 'the function circularly shifts elements in a 1d ndarray', function test( t.end(); }); -tape( 'the function supports large shift values (k > N)', function test( t ) { +tape( 'the function supports large shift values (|k| > N)', function test( t ) { var expected; var actual; var xbuf; @@ -1192,32 +1188,3 @@ tape( 'the function supports large shift values (k > N)', function test( t ) { t.end(); }); - -tape( 'the function supports typed array inputs', function test( t ) { - var expected; - var actual; - var xbuf; - var x; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - x = new ndarray( 'float64', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); - - actual = circshift( x, 2 ); - expected = new Float64Array( [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), expected ), true, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - x = new ndarray( 'float32', xbuf, [ 6 ], [ 1 ], 0, 'row-major' ); - - actual = circshift( x, 2 ); - expected = new Float32Array( [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] ); - - t.strictEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), 'float32', 'returns expected value' ); - t.strictEqual( isSameFloat32Array( getData( actual ), expected ), true, 'returns expected value' ); - - t.end(); -}); From 2dffa915bb6d63ae9a7d0a5b01849cd25d704827 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 29 Mar 2026 23:16:55 +0500 Subject: [PATCH 03/13] docs: apply suggesetions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/circshift/README.md | 17 +++-------- .../blas/ext/circshift/docs/types/index.d.ts | 26 +++++++--------- .../@stdlib/blas/ext/circshift/lib/base.js | 25 ++++------------ .../@stdlib/blas/ext/circshift/lib/index.js | 30 +++++++------------ .../@stdlib/blas/ext/circshift/lib/main.js | 29 +++++++----------- 5 files changed, 39 insertions(+), 88 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/README.md b/lib/node_modules/@stdlib/blas/ext/circshift/README.md index 326f38a72b73..9e20797f8cc7 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/README.md +++ b/lib/node_modules/@stdlib/blas/ext/circshift/README.md @@ -35,16 +35,13 @@ var circshift = require( '@stdlib/blas/ext/circshift' ); Circularly shifts the elements of an input [ndarray][@stdlib/ndarray/ctor] by a specified number of positions along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +// returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] var y = circshift( x, 2 ); -// returns - -var arr = ndarray2array( y ); -// returns [ 4.0, 5.0, 1.0, 2.0, 3.0 ] +// returns [ 4.0, 5.0, 1.0, 2.0, 3.0 ] var bool = ( x === y ); // returns true @@ -63,24 +60,18 @@ The function accepts the following options: By default, the function circularly shifts all elements. To perform the operation over specific dimensions, provide a `dims` option. ```javascript -var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { 'shape': [ 2, 2 ], 'order': 'row-major' }); - -var v = ndarray2array( x ); -// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] var y = circshift( x, 1, { 'dims': [ 0 ] }); -// returns - -v = ndarray2array( y ); -// returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +// returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] ``` diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts index da8df24bff8b..97c5cb76d5dc 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/circshift/docs/types/index.d.ts @@ -52,24 +52,18 @@ interface Options { * @returns input ndarray * * @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var array = require( '@stdlib/ndarray/array' ); * -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var x = new ndarray( 'float64', xbuf, [ 3, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* var y = circshift( x, 2 ); -* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); -* -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var x = new ndarray( 'float64', xbuf, [ 3, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); -* -* var y = circshift( x, -1 ); -* // returns [ [ [ 2.0, 3.0 ] ], [ [ 4.0, 5.0 ] ], [ [ 6.0, 1.0 ] ] ] +* var y = circshift( x, 1, { +* 'dims': [ 0 ] +* }); +* // returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] */ declare function circshift( x: T, k: typedndarray | number, options?: Options ): T; diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index 78a95197f998..eacf3dca8018 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -69,33 +69,18 @@ var options = { * @returns {ndarray} input ndarray * * @example -* var Float64Array = require( '@stdlib/array/float64' ); +* var array = require( '@stdlib/ndarray/array' ); * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); * -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] * -* // Define the shape of the input array: -* var sh = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Create an ndarray containing the number of positions to shift: * var k = scalar2ndarray( 2, { * 'dtype': 'int32' * }); * -* // Perform operation: -* var out = circshift( x, k ); -* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* var y = circshift( x, k ); +* // returns [ 4.0, 5.0, 1.0, 2.0, 3.0 ] */ var circshift = factory( table, [ idtypes0, idtypes1 ], odtypes, options ); diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js index c4a9ad31fd39..304f5d998bb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/index.js @@ -24,29 +24,19 @@ * @module @stdlib/blas/ext/circshift * * @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); -* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); * var circshift = require( '@stdlib/blas/ext/circshift' ); * -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* // Define the shape of the input array: -* var sh = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Perform operation: -* var out = circshift( x, 2 ); -* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* var y = circshift( x, 1, { +* 'dims': [ 0 ] +* }); +* // returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index 13975209c11e..c1ce99109ba5 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -56,27 +56,18 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); * @returns {ndarray} input ndarray * * @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var array = require( '@stdlib/ndarray/array' ); * -* // Create a data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] * -* // Define the shape of the input array: -* var sh = [ 3, 1, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray: -* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Perform operation: -* var out = circshift( x, 2 ); -* // returns [ [ [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ] ] +* var y = circshift( x, 1, { +* 'dims': [ 0 ] +* }); +* // returns [ [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] */ function circshift( x, k ) { var nargs; From 08bddb4361168d010e003c3083820f1db302918f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 12:51:53 -0700 Subject: [PATCH 04/13] style: align comments Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index eacf3dca8018..6f07a219df67 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -29,7 +29,7 @@ var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' // VARIABLES // -var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes0 = dtypes( 'all' ); // input ndarray var idtypes1 = dtypes( 'real_and_generic' ); // k ndarray var odtypes = dtypes( 'all' ); var table = { From afc81b5a77d25b3a8a119082d61adf6230165761 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 12:54:29 -0700 Subject: [PATCH 05/13] docs: add FIXME Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index 6f07a219df67..3b5606285187 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -36,6 +36,8 @@ var table = { 'types': [ 'float64', // input/output 'float32' // input/output + + // FIXME: add `complex64` and `complex128` once `zcircshift` and `ccircshift` are added ], 'fcns': [ dcircshift, From d8086df777e1e9610eadc0a50956295052237320 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:00:20 -0700 Subject: [PATCH 06/13] chore: clean-up Signed-off-by: Athan --- .../@stdlib/blas/ext/circshift/lib/main.js | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index c1ce99109ba5..aea7b79f0003 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -72,50 +72,46 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); function circshift( x, k ) { var nargs; var opts; - var ord; var sh; - var o; + var ka; nargs = arguments.length; - ord = getOrder( x ); - - o = k; // Case: circshift( x, k ) if ( nargs === 2 ) { // Case: circshift( x, k_scalar ) - if ( isInteger( o ) ) { - return base( x, broadcastScalar( o, DEFAULT_DTYPE, [], ord ) ); + if ( isInteger( k ) ) { + return base( x, broadcastScalar( o, DEFAULT_DTYPE, [], getOrder( x ) ); } // Case: circshift( x, k_ndarray ) - if ( isndarrayLike( o ) ) { + if ( isndarrayLike( k ) ) { // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... - return base( x, o ); + return base( x, k ); } - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', o ) ); + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); } // Case: circshift( x, k, opts ) opts = arguments[ 2 ]; // Case: circshift( x, k_scalar, opts ) - if ( isInteger( o ) ) { + if ( isInteger( k ) ) { if ( hasOwnProp( opts, 'dims' ) ) { sh = nonCoreShape( getShape( x ), opts.dims ); } else { sh = []; } - o = broadcastScalar( o, DEFAULT_DTYPE, sh, getOrder( x ) ); + ka = broadcastScalar( k, DEFAULT_DTYPE, sh, getOrder( x ) ); } // Case: circshift( x, k_ndarray, opts ) - else if ( isndarrayLike( o ) ) { - // When not provided `dims`, the operation is performed across all dimensions and `o` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `o` to match the shape of the non-core dimensions... + else if ( isndarrayLike( k ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `k` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `k` to match the shape of the non-core dimensions... if ( hasOwnProp( opts, 'dims' ) ) { - o = maybeBroadcastArray( o, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + ka = maybeBroadcastArray( k, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len } } else { - throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', o ) ); + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); } - return base( x, o, opts ); + return base( x, ka, opts ); } From 7367c993d299d0818e88d460b22361a88129e30b Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:00:31 -0700 Subject: [PATCH 07/13] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index aea7b79f0003..d8062907607e 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -44,7 +44,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); * Circularly shifts the elements of an input ndarray by a specified number of positions along one or more ndarray dimensions. * * @param {ndarrayLike} x - input ndarray -* @param {(ndarrayLike|number)} k - number of positions to shift +* @param {(ndarrayLike|integer)} k - number of positions to shift * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation * @throws {TypeError} first argument must be an ndarray-like object From 5d6864dfce2b3547cf447af8b3f915df29bd491c Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:01:05 -0700 Subject: [PATCH 08/13] fix: use correct variable Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index d8062907607e..07a4227f243d 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -81,7 +81,7 @@ function circshift( x, k ) { if ( nargs === 2 ) { // Case: circshift( x, k_scalar ) if ( isInteger( k ) ) { - return base( x, broadcastScalar( o, DEFAULT_DTYPE, [], getOrder( x ) ); + return base( x, broadcastScalar( k, DEFAULT_DTYPE, [], getOrder( x ) ); } // Case: circshift( x, k_ndarray ) if ( isndarrayLike( k ) ) { From b785726231e11a7b463648227a0249ee27bbfc47 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:01:37 -0700 Subject: [PATCH 09/13] docs: fix comment Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index 07a4227f243d..d9a8e27b0210 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -85,7 +85,7 @@ function circshift( x, k ) { } // Case: circshift( x, k_ndarray ) if ( isndarrayLike( k ) ) { - // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... + // As the operation is performed across all dimensions, `k` is assumed to be a zero-dimensional ndarray... return base( x, k ); } throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); From 7fd2dd243c5eedc80ab9cec014eb29913f0db9ab Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:03:15 -0700 Subject: [PATCH 10/13] chore: add keyword Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/package.json b/lib/node_modules/@stdlib/blas/ext/circshift/package.json index 4da2b5f8c680..9e131f63dc0f 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/package.json +++ b/lib/node_modules/@stdlib/blas/ext/circshift/package.json @@ -60,7 +60,8 @@ "circshift", "rotate", "roll", - "ndarray" + "ndarray", + "numpy.roll" ], "__stdlib__": {} } From 79d1cd28c169b9f8d3f026f14af50c346c702122 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 13:22:20 -0700 Subject: [PATCH 11/13] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js | 1 - lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index 3b5606285187..41b29c5b4702 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -36,7 +36,6 @@ var table = { 'types': [ 'float64', // input/output 'float32' // input/output - // FIXME: add `complex64` and `complex128` once `zcircshift` and `ccircshift` are added ], 'fcns': [ diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index d9a8e27b0210..977c57390fb4 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -81,7 +81,7 @@ function circshift( x, k ) { if ( nargs === 2 ) { // Case: circshift( x, k_scalar ) if ( isInteger( k ) ) { - return base( x, broadcastScalar( k, DEFAULT_DTYPE, [], getOrder( x ) ); + return base( x, broadcastScalar( k, DEFAULT_DTYPE, [], getOrder( x ) ) ); } // Case: circshift( x, k_ndarray ) if ( isndarrayLike( k ) ) { From a1428cf807a6b9fe4d722636cc4fb3ba483631dc Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 14:00:47 -0700 Subject: [PATCH 12/13] style: add empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js index 41b29c5b4702..89f4f4873d1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/base.js @@ -36,6 +36,7 @@ var table = { 'types': [ 'float64', // input/output 'float32' // input/output + // FIXME: add `complex64` and `complex128` once `zcircshift` and `ccircshift` are added ], 'fcns': [ From 526008be05a3f558abf20c8d436cf382c37e4462 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 29 Mar 2026 14:03:28 -0700 Subject: [PATCH 13/13] fix: alias `k` Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index 977c57390fb4..c83f975c12c5 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -107,6 +107,8 @@ function circshift( x, k ) { // When not provided `dims`, the operation is performed across all dimensions and `k` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `k` to match the shape of the non-core dimensions... if ( hasOwnProp( opts, 'dims' ) ) { ka = maybeBroadcastArray( k, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } else { + ka = k; } } else { throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) );