diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/README.md new file mode 100644 index 000000000000..5b4fed300332 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/README.md @@ -0,0 +1,168 @@ + + +# gcircshift + +> Perform a circular shift on a strided array in-place. + +
+ +## Usage + +```javascript +var gcircshift = require( '@stdlib/blas/ext/base/gcircshift' ); +``` + +#### gcircshift( N, k, x, strideX ) + +Performs a circular shift on a strided array in-place. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + +gcircshift( x.length, 2, x, 1 ); +// x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: number of positions to shift. +- **x**: input array. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to circularly shift every other element: + +```javascript +var x = [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0 ]; + +gcircshift( 4, 1, x, 2 ); +// x => [ 4.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Circularly shift elements in the view: +gcircshift( 5, 2, x1, 1 ); +// x0 => [ 0.0, 4.0, 5.0, 1.0, 2.0, 3.0 ] +``` + +#### gcircshift.ndarray( N, k, x, strideX, offsetX ) + +Performs a circular shift on a strided array in-place using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + +gcircshift.ndarray( x.length, 2, x, 1, 0 ); +// x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array: + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +gcircshift.ndarray( 3, 1, x, 1, x.length-3 ); +// x => [ 1.0, 2.0, 3.0, 6.0, 4.0, 5.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return the strided array unchanged. +- If `k` is a multiple of `N`, both functions return the strided array unchanged. +- If `k > 0` elements are shifted to the right. +- If `k < 0` elements are shifted to the left. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). +- Depending on the environment, the typed versions ([`dcircshift`][@stdlib/blas/ext/base/dcircshift], [`scircshift`][@stdlib/blas/ext/base/scircshift], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gcircshift = require( '@stdlib/blas/ext/base/gcircshift' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +gcircshift( x.length, 3, x, 1 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.js new file mode 100644 index 000000000000..51b4ac01e70b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.js @@ -0,0 +1,95 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcircshift = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + var k = floor( len / 2 ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gcircshift( x.length, k, x, 1 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..51488c49323a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/benchmark/benchmark.ndarray.js @@ -0,0 +1,95 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcircshift = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + var k = floor( len / 2 ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gcircshift( x.length, k, x, 1, 0 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/repl.txt new file mode 100644 index 000000000000..d0bc8e8ebe8b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/repl.txt @@ -0,0 +1,100 @@ + +{{alias}}( N, k, x, strideX ) + Performs a circular shift on a strided array in-place. + + If `k > 0` elements are shifted to the right and If `k < 0` elements are + shifted to the left. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `x` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of positions to shift. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > {{alias}}( x.length, 2, x, 1 ) + [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + + // Using `N` and stride parameters: + > x = [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0 ]; + > {{alias}}( 4, 1, x, 2 ) + [ 4.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 5, 2, x1, 1 ) + [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + > x0 + [ 0.0, 4.0, 5.0, 1.0, 2.0, 3.0 ] + + +{{alias}}.ndarray( N, k, x, strideX, offsetX ) + Performs a circular shift on a strided array in-place using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Number of positions to shift. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > {{alias}}.ndarray( x.length, 2, x, 1, 0 ) + [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + + // Using an index offset: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + [ 1.0, 6.0, 3.0, 2.0, 5.0, 4.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/index.d.ts new file mode 100644 index 000000000000..3d6f2f9815bf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gcircshift`. +*/ +interface Routine { + /** + * Performs a circular shift on a strided array in-place. + * + * @param N - number of indexed elements + * @param k - number of positions to shift + * @param x - input array + * @param strideX - stride length + * @returns `x` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + * + * gcircshift( x.length, 2, x, 1 ); + * // x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + */ + ( N: number, k: number, x: T, strideX: number ): T; + + /** + * Performs a circular shift on a strided array in-place using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param k - number of positions to shift + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns `x` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + * + * gcircshift.ndarray( x.length, 2, x, 1, 0 ); + * // x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] + */ + ndarray( N: number, k: number, x: T, strideX: number, offsetX: number ): T; +} + +/** +* Performs a circular shift on a strided array in-place. +* +* @param N - number of indexed elements +* @param k - number of positions to shift +* @param x - input array +* @param strideX - stride length +* @returns `x` +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* gcircshift( x.length, 2, x, 1 ); +* // x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* gcircshift.ndarray( x.length, 2, x, 1, 0 ); +* // x => [ 4.0, 5.0, 1.0, 2.0, 3.0 ] +*/ +declare var gcircshift: Routine; + + +// EXPORTS // + +export = gcircshift; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/test.ts new file mode 100644 index 000000000000..b6316f55b0a2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/docs/types/test.ts @@ -0,0 +1,185 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import gcircshift = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 10 ); + + gcircshift( x.length, 2, x, 1 ); // $ExpectType Collection +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift( '10', 2, x, 1 ); // $ExpectError + gcircshift( true, 2, x, 1 ); // $ExpectError + gcircshift( false, 2, x, 1 ); // $ExpectError + gcircshift( null, 2, x, 1 ); // $ExpectError + gcircshift( undefined, 2, x, 1 ); // $ExpectError + gcircshift( [], 2, x, 1 ); // $ExpectError + gcircshift( {}, 2, x, 1 ); // $ExpectError + gcircshift( ( x: number ): number => x, 2, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift( x.length, '10', x, 1 ); // $ExpectError + gcircshift( x.length, true, x, 1 ); // $ExpectError + gcircshift( x.length, false, x, 1 ); // $ExpectError + gcircshift( x.length, null, x, 1 ); // $ExpectError + gcircshift( x.length, undefined, x, 1 ); // $ExpectError + gcircshift( x.length, [], x, 1 ); // $ExpectError + gcircshift( x.length, {}, x, 1 ); // $ExpectError + gcircshift( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcircshift( x.length, 2, '10', 1 ); // $ExpectError + gcircshift( x.length, 2, true, 1 ); // $ExpectError + gcircshift( x.length, 2, false, 1 ); // $ExpectError + gcircshift( x.length, 2, null, 1 ); // $ExpectError + gcircshift( x.length, 2, undefined, 1 ); // $ExpectError + gcircshift( x.length, 2, [], 1 ); // $ExpectError + gcircshift( x.length, 2, {}, 1 ); // $ExpectError + gcircshift( x.length, 2, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift( x.length, 2, x, '10' ); // $ExpectError + gcircshift( x.length, 2, x, true ); // $ExpectError + gcircshift( x.length, 2, x, false ); // $ExpectError + gcircshift( x.length, 2, x, null ); // $ExpectError + gcircshift( x.length, 2, x, undefined ); // $ExpectError + gcircshift( x.length, 2, x, [] ); // $ExpectError + gcircshift( x.length, 2, x, {} ); // $ExpectError + gcircshift( x.length, 2, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gcircshift(); // $ExpectError + gcircshift( x.length ); // $ExpectError + gcircshift( x.length, 2 ); // $ExpectError + gcircshift( x.length, 2, x ); // $ExpectError + gcircshift( x.length, 2, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( x.length, 2, x, 1, 0 ); // $ExpectType Collection +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( '10', 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( true, 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( false, 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( null, 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( undefined, 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( [], 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( {}, 2, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( ( x: number ): number => x, 2, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( x.length, 2, '10', 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, true, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, false, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, null, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, undefined, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, [], 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, {}, 1, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( x.length, 2, x, '10', 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, true, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, false, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, null, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, undefined, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, [], 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, {}, 0 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray( x.length, 2, x, 1, '10' ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, true ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, false ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, null ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, undefined ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, [] ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, {} ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gcircshift.ndarray(); // $ExpectError + gcircshift.ndarray( x.length ); // $ExpectError + gcircshift.ndarray( x.length, 2 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1 ); // $ExpectError + gcircshift.ndarray( x.length, 2, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/examples/index.js new file mode 100644 index 000000000000..969acc6a80b7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 gcircshift = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +gcircshift( x.length, 3, x, 1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/index.js new file mode 100644 index 000000000000..b26aa2093d57 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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'; + +/** +* Perform a circular shift on a strided array in-place. +* +* @module @stdlib/blas/ext/base/gcircshift +* +* @example +* var gcircshift = require( '@stdlib/blas/ext/base/gcircshift' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcircshift( x.length, 2, x, 1 ); +* // x => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +* +* @example +* var gcircshift = require( '@stdlib/blas/ext/base/gcircshift' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcircshift.ndarray( x.length, 2, x, 1, 0 ); +* // x => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/main.js new file mode 100644 index 000000000000..0c35f51ebf18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/main.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Performs a circular shift on a strided array in-place. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} k - number of positions to shift +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {NumericArray} input array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcircshift( x.length, 2, x, 1 ); +* // x => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function gcircshift( N, k, x, strideX ) { + return ndarray( N, k, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gcircshift; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/ndarray.js new file mode 100644 index 000000000000..c1c8eb4322c5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/lib/ndarray.js @@ -0,0 +1,75 @@ +/** +* @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 grev = require( '@stdlib/blas/ext/base/grev' ).ndarray; + + +// MAIN // + +/** +* Performs a circular shift on a strided array in-place. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} k - number of positions to shift +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {NumericArray} input array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gcircshift( x.length, 2, x, 1, 0 ); +* // x => [ 5.0, 6.0, 1.0, 2.0, 3.0, 4.0 ] +*/ +function gcircshift( N, k, x, strideX, offsetX ) { + var nk; + + if ( N <= 0 ) { + return x; + } + + // Normalize `k`... + nk = k % N; + if ( nk < 0 ) { + nk += N; + } + if ( nk === 0 ) { + return x; + } + + // Reverse the entire array: + grev( N, x, strideX, offsetX ); + + // Reverse the first `k` elements: + grev( nk, x, strideX, offsetX ); + + // Reverse the last `N-k` elements: + grev( N - nk, x, strideX, offsetX + ( nk * strideX ) ); + + return x; +} + + +// EXPORTS // + +module.exports = gcircshift; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/package.json new file mode 100644 index 000000000000..b5127aade07f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/ext/base/gcircshift", + "version": "0.0.0", + "description": "Perform a circular shift on a strided array in-place.", + "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", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.js new file mode 100644 index 000000000000..0e31dcb58012 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gcircshift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcircshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gcircshift.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.main.js new file mode 100644 index 000000000000..a0b452b815a2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.main.js @@ -0,0 +1,367 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var gcircshift = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcircshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gcircshift.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a circular shift (right shift, positive k)', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + gcircshift( x.length, 2, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 5.0, 1.0, 2.0, 3.0, 4.0 ]; + + gcircshift( x.length, 1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a circular shift (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0 + ]); + expected = new Float64Array([ + 5.0, + 6.0, + 7.0, + 8.0, + 1.0, + 2.0, + 3.0, + 4.0 + ]); + + gcircshift( x.length, 2, x, 1 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a circular shift (left shift, negative k)', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 1.0, 2.0 ]; + + gcircshift( x.length, -2, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 2.0, 3.0, 4.0, 5.0, 1.0 ]; + + gcircshift( x.length, -1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input array unchanged when k is a multiple of N', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + gcircshift( x.length, 0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, 4, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, -4, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, 8, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports k greater than N', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + gcircshift( x.length, 7, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 1.0, 2.0 ]; + + gcircshift( x.length, -7, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gcircshift( x.length, 2, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gcircshift( 0, 1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( -4, 1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0, + 4.0 // 3 + ]; + expected = [ + 4.0, // 0 + 0.0, + 1.0, // 1 + 0.0, + 2.0, // 2 + 0.0, + 3.0 // 3 + ]; + + gcircshift( 4, 1, x, 2 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0 + ]); + expected = new Float64Array([ + 5.0, + 6.0, + -1.0, + -1.0, + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0 + ]); + + gcircshift( 3, 1, x, 2 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 1.0, // 3 + 0.0, + 2.0, // 2 + 0.0, + 3.0, // 1 + 0.0, + 4.0 // 0 + ]; + expected = [ + 2.0, // 3 + 0.0, + 3.0, // 2 + 0.0, + 4.0, // 1 + 0.0, + 1.0 // 0 + ]; + + gcircshift( 4, 1, x, -2 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0 + ]); + expected = new Float64Array([ + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0, + -1.0, + -1.0, + 1.0, + 2.0 + ]); + + gcircshift( 3, 1, x, -2 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, // 3 + 5.0 // 4 + ]); + expected = new Float64Array([ + 0.0, + 4.0, // 0 + 5.0, // 1 + 1.0, // 2 + 2.0, // 3 + 3.0 // 4 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + gcircshift( 5, 2, x1, 1 ); + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports single-element arrays', function test( t ) { + var expected; + var x; + + x = [ 42.0 ]; + expected = [ 42.0 ]; + + gcircshift( 1, 5, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports two-element arrays', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0 ]; + expected = [ 2.0, 1.0 ]; + + gcircshift( 2, 1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 2.0, 1.0 ]; + + gcircshift( 2, -1, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.ndarray.js new file mode 100644 index 000000000000..37206bed5b55 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcircshift/test/test.ndarray.js @@ -0,0 +1,395 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var gcircshift = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcircshift, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gcircshift.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a circular shift (right shift, positive k)', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + gcircshift( x.length, 2, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 5.0, 1.0, 2.0, 3.0, 4.0 ]; + + gcircshift( x.length, 1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a circular shift (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0 + ]); + expected = new Float64Array([ + 5.0, + 6.0, + 7.0, + 8.0, + 1.0, + 2.0, + 3.0, + 4.0 + ]); + + gcircshift( x.length, 2, x, 1, 0 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a circular shift (left shift, negative k)', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 1.0, 2.0 ]; + + gcircshift( x.length, -2, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 2.0, 3.0, 4.0, 5.0, 1.0 ]; + + gcircshift( x.length, -1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input array unchanged when k is a multiple of N', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + gcircshift( x.length, 0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, 4, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, -4, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( x.length, 8, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports k greater than N', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 4.0, 5.0, 1.0, 2.0, 3.0 ]; + + gcircshift( x.length, 7, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + expected = [ 3.0, 4.0, 5.0, 1.0, 2.0 ]; + + gcircshift( x.length, -7, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gcircshift( x.length, 2, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gcircshift( 0, 1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gcircshift( -4, 1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0, + 4.0 // 3 + ]; + expected = [ + 4.0, // 0 + 0.0, + 1.0, // 1 + 0.0, + 2.0, // 2 + 0.0, + 3.0 // 3 + ]; + + gcircshift( 4, 1, x, 2, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0 + ]); + expected = new Float64Array([ + 5.0, + 6.0, + -1.0, + -1.0, + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0 + ]); + + gcircshift( 3, 1, x, 2, 0 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 1.0, // 3 + 0.0, + 2.0, // 2 + 0.0, + 3.0, // 1 + 0.0, + 4.0 // 0 + ]; + expected = [ + 2.0, // 3 + 0.0, + 3.0, // 2 + 0.0, + 4.0, // 1 + 0.0, + 1.0 // 0 + ]; + + gcircshift( 4, 1, x, -2, x.length-1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + -1.0, + -1.0, + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0 + ]); + expected = new Float64Array([ + 3.0, + 4.0, + -1.0, + -1.0, + 5.0, + 6.0, + -1.0, + -1.0, + 1.0, + 2.0 + ]); + + gcircshift( 3, 1, x, -2, x.length-1 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var expected; + var x; + + x = [ + 0.0, + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, // 3 + 5.0 // 4 + ]; + expected = [ + 0.0, + 4.0, // 0 + 5.0, // 1 + 1.0, // 2 + 2.0, // 3 + 3.0 // 4 + ]; + + gcircshift( 5, 2, x, 1, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset with a stride', function test( t ) { + var expected; + var x; + + x = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0, + 4.0 // 3 + ]; + expected = [ + 0.0, + 4.0, // 0 + 0.0, + 1.0, // 1 + 0.0, + 2.0, // 2 + 0.0, + 3.0 // 3 + ]; + + gcircshift( 4, 1, x, 2, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports single-element arrays', function test( t ) { + var expected; + var x; + + x = [ 42.0 ]; + expected = [ 42.0 ]; + + gcircshift( 1, 5, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports two-element arrays', function test( t ) { + var expected; + var x; + + x = [ 1.0, 2.0 ]; + expected = [ 2.0, 1.0 ]; + + gcircshift( 2, 1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + expected = [ 2.0, 1.0 ]; + + gcircshift( 2, -1, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +});