From 01455b23bf1ed07fc89a6e58a0affb4e6ca0d327 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 14 Mar 2026 05:48:39 +0500 Subject: [PATCH] feat: add blas/ext/base/gmskrev --- .../@stdlib/blas/ext/base/gmskrev/README.md | 180 +++++++ .../ext/base/gmskrev/benchmark/benchmark.js | 95 ++++ .../gmskrev/benchmark/benchmark.ndarray.js | 95 ++++ .../blas/ext/base/gmskrev/docs/repl.txt | 116 +++++ .../ext/base/gmskrev/docs/types/index.d.ts | 99 ++++ .../blas/ext/base/gmskrev/docs/types/test.ts | 236 +++++++++ .../blas/ext/base/gmskrev/examples/index.js | 34 ++ .../blas/ext/base/gmskrev/lib/accessors.js | 92 ++++ .../blas/ext/base/gmskrev/lib/index.js | 59 +++ .../@stdlib/blas/ext/base/gmskrev/lib/main.js | 55 ++ .../blas/ext/base/gmskrev/lib/ndarray.js | 142 ++++++ .../blas/ext/base/gmskrev/package.json | 69 +++ .../blas/ext/base/gmskrev/test/test.js | 38 ++ .../blas/ext/base/gmskrev/test/test.main.js | 450 +++++++++++++++++ .../ext/base/gmskrev/test/test.ndarray.js | 476 ++++++++++++++++++ 15 files changed, 2236 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/README.md b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/README.md new file mode 100644 index 000000000000..1e86fb043477 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/README.md @@ -0,0 +1,180 @@ + + +# gmskrev + +> Reverse a strided array in-place according to a mask. + +
+ +## Usage + +```javascript +var gmskrev = require( '@stdlib/blas/ext/base/gmskrev' ); +``` + +#### gmskrev( N, x, strideX, mask, strideMask ) + +Reverses a strided array in-place according to a mask. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + +gmskrev( x.length, x, 1, mask, 1 ); +// x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: stride length for `x`. +- **mask**: mask array. +- **strideMask**: stride length for `mask`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to reverse every other element: + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +var mask = [ 0, 0, 0, 0 ]; + +gmskrev( 4, x, 2, mask, 1 ); +// x => [ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.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' ); +var Uint8Array = require( '@stdlib/array/uint8' ); + +// Initial arrays... +var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); +var m0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var m1 = new Uint8Array( m0.buffer, m0.BYTES_PER_ELEMENT*1 ); + +// Reverse every other element... +gmskrev( 3, x1, 2, m1, 1 ); +// x0 => [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] +``` + +#### gmskrev.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) + +Reverses a strided array in-place according to a mask and using alternative indexing semantics. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + +gmskrev.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +// x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetMask**: starting index for `mask`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements: + +```javascript +var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; +var mask = [ 0, 0, 0, 0, 0, 0 ]; + +gmskrev.ndarray( 3, x, 1, x.length-3, mask, 1, 3 ); +// x => [ 1.0, -2.0, 3.0, -6.0, 5.0, -4.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `x` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). +- A mask value of `0` indicates that the corresponding element in `x` participates in the reversal, while a non-zero mask value indicates that the corresponding element should be skipped. +- Where possible, one should "reverse" a strided array by negating its stride, which is an `O(1)` operation, in contrast to performing an in-place reversal, which is `O(N)`. However, in certain circumstances, this is not tenable, particularly when interfacing with libraries which assume and/or expect a specific memory layout (e.g., strided array elements arranged in memory in ascending order). In general, when working with strided arrays, only perform an in-place reversal when strictly necessary. +- Depending on the environment, the typed versions ([`dmskrev`][@stdlib/blas/ext/base/dmskrev], [`smskrev`][@stdlib/blas/ext/base/smskrev], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var gmskrev = require( '@stdlib/blas/ext/base/gmskrev' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 ] ); +console.log( mask ); + +gmskrev( x.length, x, 1, mask, 1 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/benchmark/benchmark.js new file mode 100644 index 000000000000..96586d9ed301 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/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 zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gmskrev = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask = zeros( len, 'uint8' ); + var x = uniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + 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 = gmskrev( x.length, x, 1, mask, 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/gmskrev/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..f34836da3d6f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/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 zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gmskrev = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask = zeros( len, 'uint8' ); + var x = uniform( len, -100.0, 100.0, { + 'dtype': 'generic' + }); + 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 = gmskrev( x.length, x, 1, 0, mask, 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/gmskrev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/repl.txt new file mode 100644 index 000000000000..6936cf1f1e49 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/repl.txt @@ -0,0 +1,116 @@ + +{{alias}}( N, x, strideX, mask, strideMask ) + Reverses a strided array in-place according to a mask. + + The `N` and stride parameters determine which elements in the strided + arrays 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. + + A mask value of `0` indicates that the corresponding element in `x` + participates in the reversal, while a non-zero mask value indicates that + the corresponding element should be skipped. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + mask: ArrayLikeObject + Mask array. + + strideMask: integer + Stride length for `mask`. + + Returns + ------- + x: ArrayLikeObject + Input array `x`. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > var m = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + > {{alias}}( x.length, x, 1, m, 1 ) + [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > m = [ 0, 0, 0, 0 ]; + > {{alias}}( 4, x, 2, m, 1 ) + [ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var m0 = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 0, 0, 0, 0 ] ); + > var m1 = new {{alias:@stdlib/array/uint8}}( m0.buffer, m0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, x1, 2, m1, 1 ) + [ -6.0, 3.0, -4.0, 5.0, -2.0 ] + > x0 + [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) + Reverses a strided array in-place according to a mask and using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + mask: ArrayLikeObject + Mask array. + + strideMask: integer + Stride length for `mask`. + + offsetMask: integer + Starting index for `mask`. + + Returns + ------- + x: ArrayLikeObject + Input array `x`. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + > var m = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0, m, 1, 0 ) + [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] + + // Using an index offset: + > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > m = [ 0, 0, 0, 0, 0, 0 ]; + > {{alias}}.ndarray( 3, x, 2, 1, m, 2, 1 ) + [ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/index.d.ts new file mode 100644 index 000000000000..7baa5311425c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/index.d.ts @@ -0,0 +1,99 @@ +/* +* @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 { Collection } from '@stdlib/types/array'; + +/** +* Interface describing `gmskrev`. +*/ +interface Routine { + /** + * Reverses a strided array in-place according to a mask. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param mask - mask array + * @param strideMask - stride length for `mask` + * @returns input array + * + * @example + * var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + * + * gmskrev( x.length, x, 1, mask, 1 ); + * // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] + */ + ( N: number, x: Collection, strideX: number, mask: Collection, strideMask: number ): Collection; + + /** + * Reverses a strided array in-place according to a mask and using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param mask - mask array + * @param strideMask - stride length for `mask` + * @param offsetMask - starting index for `mask` + * @returns input array + * + * @example + * var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + * var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + * + * gmskrev.ndarray( x.length, x, 1, 0, mask, 1, 0 ); + * // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] + */ + ndarray( N: number, x: Collection, strideX: number, offsetX: number, mask: Collection, strideMask: number, offsetMask: number ): Collection; +} + +/** +* Reverses a strided array in-place according to a mask. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length for `x` +* @param mask - mask array +* @param strideMask - stride length for `mask` +* @returns input array +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev( x.length, x, 1, mask, 1 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +*/ +declare var gmskrev: Routine; + + +// EXPORTS // + +export = gmskrev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/test.ts new file mode 100644 index 000000000000..31194570d6da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/docs/types/test.ts @@ -0,0 +1,236 @@ +/* +* @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 gmskrev = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev( x.length, x, 1, mask, 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 ); + const mask = new Uint8Array( 10 ); + + gmskrev( '10', x, 1, mask, 1 ); // $ExpectError + gmskrev( true, x, 1, mask, 1 ); // $ExpectError + gmskrev( false, x, 1, mask, 1 ); // $ExpectError + gmskrev( null, x, 1, mask, 1 ); // $ExpectError + gmskrev( undefined, x, 1, mask, 1 ); // $ExpectError + gmskrev( [], x, 1, mask, 1 ); // $ExpectError + gmskrev( {}, x, 1, mask, 1 ); // $ExpectError + gmskrev( ( x: number ): number => x, x, 1, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev( x.length, 10, 1, mask, 1 ); // $ExpectError + gmskrev( x.length, true, 1, mask, 1 ); // $ExpectError + gmskrev( x.length, false, 1, mask, 1 ); // $ExpectError + gmskrev( x.length, null, 1, mask, 1 ); // $ExpectError + gmskrev( x.length, undefined, 1, mask, 1 ); // $ExpectError + gmskrev( x.length, {}, 1, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev( x.length, x, '10', mask, 1 ); // $ExpectError + gmskrev( x.length, x, true, mask, 1 ); // $ExpectError + gmskrev( x.length, x, false, mask, 1 ); // $ExpectError + gmskrev( x.length, x, null, mask, 1 ); // $ExpectError + gmskrev( x.length, x, undefined, mask, 1 ); // $ExpectError + gmskrev( x.length, x, [], mask, 1 ); // $ExpectError + gmskrev( x.length, x, {}, mask, 1 ); // $ExpectError + gmskrev( x.length, x, ( x: number ): number => x, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gmskrev( x.length, x, 1, 10, 1 ); // $ExpectError + gmskrev( x.length, x, 1, true, 1 ); // $ExpectError + gmskrev( x.length, x, 1, false, 1 ); // $ExpectError + gmskrev( x.length, x, 1, null, 1 ); // $ExpectError + gmskrev( x.length, x, 1, undefined, 1 ); // $ExpectError + gmskrev( x.length, x, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev( x.length, x, 1, mask, '10' ); // $ExpectError + gmskrev( x.length, x, 1, mask, true ); // $ExpectError + gmskrev( x.length, x, 1, mask, false ); // $ExpectError + gmskrev( x.length, x, 1, mask, null ); // $ExpectError + gmskrev( x.length, x, 1, mask, undefined ); // $ExpectError + gmskrev( x.length, x, 1, mask, [] ); // $ExpectError + gmskrev( x.length, x, 1, mask, {} ); // $ExpectError + gmskrev( x.length, x, 1, mask, ( 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 ); + const mask = new Uint8Array( 10 ); + + gmskrev(); // $ExpectError + gmskrev( x.length ); // $ExpectError + gmskrev( x.length, x ); // $ExpectError + gmskrev( x.length, x, 1 ); // $ExpectError + gmskrev( x.length, x, 1, mask ); // $ExpectError + gmskrev( x.length, x, 1, mask, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, x, 1, 0, mask, 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 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( '10', x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( true, x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( false, x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( null, x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( undefined, x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( [], x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( {}, x, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( ( x: number ): number => x, x, 1, 0, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, 10, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, true, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, false, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, null, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, undefined, 1, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, {}, 1, 0, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, x, '10', 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, true, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, false, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, null, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, undefined, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, [], 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, {}, 0, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, ( x: number ): number => x, 0, mask, 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 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, x, 1, '10', mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, true, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, false, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, null, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, undefined, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, [], mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, {}, mask, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, ( x: number ): number => x, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gmskrev.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, x, 1, 0, mask, '10', 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, true, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, false, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, null, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, undefined, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, [], 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, {}, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, '10' ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, true ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, false ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, null ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, undefined ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, [] ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, {} ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 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 ); + const mask = new Uint8Array( 10 ); + + gmskrev.ndarray(); // $ExpectError + gmskrev.ndarray( x.length ); // $ExpectError + gmskrev.ndarray( x.length, x ); // $ExpectError + gmskrev.ndarray( x.length, x, 1 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1 ); // $ExpectError + gmskrev.ndarray( x.length, x, 1, 0, mask, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/examples/index.js new file mode 100644 index 000000000000..500a0f41534a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 Uint8Array = require( '@stdlib/array/uint8' ); +var gmskrev = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 ] ); +console.log( mask ); + +gmskrev( x.length, x, 1, mask, 1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/accessors.js new file mode 100644 index 000000000000..848916429b05 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/accessors.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var floor = require( '@stdlib/math/base/special/floor' ); + + +// MAIN // + +/** +* Reverses a strided array in-place according to a mask using alternative accessors. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} mask - mask array object +* @param {integer} strideMask - stride length for `mask` +* @param {NonNegativeInteger} offsetMask - starting index for `mask` +* @returns {Object} input array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* var mask = toAccessorArray( [ 0, 0, 0, 1, 0, 0, 0, 0 ] ); +* +* gmskrev( 8, arraylike2object( x ), 1, 0, arraylike2object( mask ), 1, 0 ); +*/ +function gmskrev( N, x, strideX, offsetX, mask, strideMask, offsetMask ) { + var xbuf; + var mbuf; + var mget; + var xget; + var xset; + var tmp; + var ix; + var iy; + var im; + var jm; + var n; + var i; + + xbuf = x.data; + xget = x.accessors[ 0 ]; + xset = x.accessors[ 1 ]; + mbuf = mask.data; + mget = mask.accessors[ 0 ]; + + n = floor( N/2 ); + ix = offsetX; + iy = ix + ( ( N - 1 ) * strideX ); + im = offsetMask; + jm = im + ( ( N - 1 ) * strideMask ); + for ( i = 0; i < n; i++ ) { + if ( mget( mbuf, im ) === 0 && mget( mbuf, jm ) === 0 ) { + tmp = xget( xbuf, ix ); + xset( xbuf, ix, xget( xbuf, iy ) ); + xset( xbuf, iy, tmp ); + } + ix += strideX; + iy -= strideX; + im += strideMask; + jm -= strideMask; + } + return x; +} + + +// EXPORTS // + +module.exports = gmskrev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/index.js new file mode 100644 index 000000000000..93112febb05f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/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'; + +/** +* Reverse a strided array in-place according to a mask. +* +* @module @stdlib/blas/ext/base/gmskrev +* +* @example +* var gmskrev = require( '@stdlib/blas/ext/base/gmskrev' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev( x.length, x, 1, mask, 1 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +* +* @example +* var gmskrev = require( '@stdlib/blas/ext/base/gmskrev' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.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/gmskrev/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/main.js new file mode 100644 index 000000000000..31b4cbed5190 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 // + +/** +* Reverses a strided array in-place according to a mask. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NumericArray} mask - mask array +* @param {integer} strideMask - stride length for `mask` +* @returns {NumericArray} input array +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev( x.length, x, 1, mask, 1 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +*/ +function gmskrev( N, x, strideX, mask, strideMask ) { + var ox = stride2offset( N, strideX ); + var om = stride2offset( N, strideMask ); + return ndarray( N, x, strideX, ox, mask, strideMask, om ); +} + + +// EXPORTS // + +module.exports = gmskrev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/ndarray.js new file mode 100644 index 000000000000..fcfe1f525f42 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/lib/ndarray.js @@ -0,0 +1,142 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// VARIABLES // + +var M = 3; + + +// MAIN // + +/** +* Reverses a strided array in-place according to a mask using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} mask - mask array +* @param {integer} strideMask - stride length for `mask` +* @param {NonNegativeInteger} offsetMask - starting index for `mask` +* @returns {NumericArray} input array +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; +* +* gmskrev( x.length, x, 1, 0, mask, 1, 0 ); +* // x => [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ] +*/ +function gmskrev( N, x, strideX, offsetX, mask, strideMask, offsetMask ) { + var tmp; + var ix; + var iy; + var im; + var jm; + var o; + var m; + var n; + var i; + + if ( N <= 0 ) { + return x; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + accessors( N, o, strideX, offsetX, arraylike2object( mask ), strideMask, offsetMask ); // eslint-disable-line max-len + return o.data; + } + n = floor( N/2 ); + ix = offsetX; + im = offsetMask; + + // Use loop unrolling if the strides are equal to `1`... + if ( strideX === 1 && strideMask === 1 ) { + m = n % M; + iy = ix + N - 1; + jm = im + N - 1; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + if ( mask[ im ] === 0 && mask[ jm ] === 0 ) { + tmp = x[ ix ]; + x[ ix ] = x[ iy ]; + x[ iy ] = tmp; + } + ix += 1; + im += 1; + iy -= 1; + jm -= 1; + } + } + if ( n < M ) { + return x; + } + for ( i = m; i < n; i += M ) { + if ( mask[ im ] === 0 && mask[ jm ] === 0 ) { + tmp = x[ ix ]; + x[ ix ] = x[ iy ]; + x[ iy ] = tmp; + } + if ( mask[ im+1 ] === 0 && mask[ jm-1 ] === 0 ) { + tmp = x[ ix+1 ]; + x[ ix+1 ] = x[ iy-1 ]; + x[ iy-1 ] = tmp; + } + if ( mask[ im+2 ] === 0 && mask[ jm-2 ] === 0 ) { + tmp = x[ ix+2 ]; + x[ ix+2 ] = x[ iy-2 ]; + x[ iy-2 ] = tmp; + } + ix += M; + im += M; + iy -= M; + jm -= M; + } + return x; + } + iy = ix + ( (N-1) * strideX ); + jm = im + ( (N-1) * strideMask ); + for ( i = 0; i < n; i++ ) { + if ( mask[ im ] === 0 && mask[ jm ] === 0 ) { + tmp = x[ ix ]; + x[ ix ] = x[ iy ]; + x[ iy ] = tmp; + } + ix += strideX; + im += strideMask; + iy -= strideX; + jm -= strideMask; + } + return x; +} + + +// EXPORTS // + +module.exports = gmskrev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/package.json b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/package.json new file mode 100644 index 000000000000..f4329ee795c2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gmskrev", + "version": "0.0.0", + "description": "Reverse a strided array in-place according to a mask.", + "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", + "reverse", + "rev", + "flip", + "swap", + "mask", + "masked", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.js new file mode 100644 index 000000000000..a66693fd29a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/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 gmskrev = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gmskrev, '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 gmskrev.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.main.js new file mode 100644 index 000000000000..6202e3b19845 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.main.js @@ -0,0 +1,450 @@ +/** +* @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 Uint8Array = require( '@stdlib/array/uint8' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var gmskrev = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gmskrev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gmskrev.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function reverses a strided array according to a mask', function test( t ) { + var expected; + var mask; + var x; + + x = [ + -2.0, + 1.0, + 3.0, + -5.0, + 4.0, + 0.0, + -1.0, + -3.0 + ]; + mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + expected = [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + mask = [ 0, 0 ]; + expected = [ 2.0, 1.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0 ]; + mask = [ 0, 0, 0 ]; + expected = [ 3.0, 2.0, 1.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses a strided array according to a mask (accessors)', function test( t ) { + var expected; + var mask; + var x; + + x = new Complex128Array([ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]); + mask = [ 0, 0, 0, 0 ]; + expected = new Float64Array([ + -5.0, + 6.0, + -1.0, + 2.0, + -3.0, + 5.0, + 4.0, + 2.0 + ]); + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function skips pairs where either element is masked', function test( t ) { + var expected; + var mask; + var x; + + // Mask the first element: + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 1, 0, 0, 0 ]; + expected = [ 1.0, 3.0, 2.0, 4.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + // Mask the last element: + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 0, 0, 0, 1 ]; + expected = [ 1.0, 3.0, 2.0, 4.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the array unchanged when all elements are masked', function test( t ) { + var expected; + var mask; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 1, 1, 1, 1 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var mask; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + mask = [ 0, 0, 0, 0, 0 ]; + out = gmskrev( x.length, x, 1, mask, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var mask; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + mask = [ 0, 0, 0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gmskrev( 0, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gmskrev( -4, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying strides', function test( t ) { + var expected; + var mask; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0 // 2 + ]; + expected = [ + 6.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gmskrev( 3, x, 2, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0, // 2 + -1.0, + 0.0 // 3 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0, // 2 + 0 // 3 + ]; + expected = [ + 0.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + -5.0, // 2 + -1.0, + 2.0 // 3 + ]; + + gmskrev( 4, x, 2, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying strides (accessors)', function test( t ) { + var expected; + var mask; + var x; + + x = new Complex128Array([ + 4.0, // 0 + 2.0, // 0 + -3.0, + 5.0, + -1.0, // 1 + 2.0, // 1 + -5.0, + 6.0 + ]); + mask = [ + 0, // 0 + 0 // 1 + ]; + expected = new Float64Array([ + -1.0, // 0 + 2.0, // 0 + -3.0, + 5.0, + 4.0, // 1 + 2.0, // 1 + -5.0, + 6.0 + ]); + + gmskrev( 2, x, 2, mask, 1 ); + 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 mask; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0 // 2 + ]; + expected = [ + 6.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 2.0 // 0 + ]; + + gmskrev( 3, x, -2, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ + 2.0, // 3 + -3.0, + -5.0, // 2 + 7.0, + 6.0, // 1 + -1.0, + 0.0 // 0 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0, // 2 + 0 // 3 + ]; + expected = [ + 0.0, // 3 + -3.0, + 6.0, // 2 + 7.0, + -5.0, // 1 + -1.0, + 2.0 // 0 + ]; + + gmskrev( 4, x, -2, mask, 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 mask; + var x; + + x = new Complex128Array([ + 4.0, // 1 + 2.0, // 1 + -3.0, + 5.0, + -1.0, // 0 + 2.0, // 0 + -5.0, + 6.0 + ]); + mask = [ + 0, // 0 + 0 // 1 + ]; + expected = new Float64Array([ + -1.0, // 1 + 2.0, // 1 + -3.0, + 5.0, + 4.0, // 0 + 2.0, // 0 + -5.0, + 6.0 + ]); + + gmskrev( 2, x, -2, mask, 1 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var mask0; + var mask1; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + mask0 = new Uint8Array([ + 0, + 0, // 0 + 0, // 1 + 0 // 2 + ]); + expected = new Float64Array([ + 1.0, + 6.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 2.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); + + gmskrev( 3, x1, 2, mask1, 1 ); + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if `stride` is equal to `1`, the function efficiently reverses a strided array', function test( t ) { + var expected; + var mask; + var x; + var i; + + x = new Float64Array( 100 ); + mask = new Uint8Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + mask = new Uint8Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 101 ); + mask = new Uint8Array( 101 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, mask, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.ndarray.js new file mode 100644 index 000000000000..ac2f9ce2ab12 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gmskrev/test/test.ndarray.js @@ -0,0 +1,476 @@ +/** +* @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 Uint8Array = require( '@stdlib/array/uint8' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var gmskrev = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gmskrev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gmskrev.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function reverses a strided array according to a mask', function test( t ) { + var expected; + var mask; + var x; + + x = [ + -2.0, + 1.0, + 3.0, + -5.0, + 4.0, + 0.0, + -1.0, + -3.0 + ]; + mask = [ 0, 0, 0, 1, 0, 0, 0, 0 ]; + expected = [ -3.0, -1.0, 0.0, -5.0, 4.0, 3.0, 1.0, -2.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + mask = [ 0, 0 ]; + expected = [ 2.0, 1.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.0 ]; + mask = [ 0, 0, 0 ]; + expected = [ 3.0, 2.0, 1.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses a strided array according to a mask (accessors)', function test( t ) { + var expected; + var mask; + var x; + + x = new Complex128Array([ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]); + mask = [ 0, 0, 0, 0 ]; + expected = new Float64Array([ + -5.0, + 6.0, + -1.0, + 2.0, + -3.0, + 5.0, + 4.0, + 2.0 + ]); + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function skips pairs where either element is masked', function test( t ) { + var expected; + var mask; + var x; + + // Mask the first element: + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 1, 0, 0, 0 ]; + expected = [ 1.0, 3.0, 2.0, 4.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + // Mask the last element: + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 0, 0, 0, 1 ]; + expected = [ 1.0, 3.0, 2.0, 4.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the array unchanged when all elements are masked', function test( t ) { + var expected; + var mask; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + mask = [ 1, 1, 1, 1 ]; + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + gmskrev( x.length, x, 1, 0, mask, 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 mask; + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + mask = [ 0, 0, 0, 0, 0 ]; + out = gmskrev( x.length, x, 1, 0, mask, 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 `x` unchanged', function test( t ) { + var expected; + var mask; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + mask = [ 0, 0, 0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gmskrev( 0, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gmskrev( -4, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var mask; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0 // 2 + ]; + expected = [ + 6.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gmskrev( 3, x, 2, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0, // 2 + -1.0, + 0.0 // 3 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0, // 2 + 0 // 3 + ]; + expected = [ + 0.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + -5.0, // 2 + -1.0, + 2.0 // 3 + ]; + + gmskrev( 4, x, 2, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var mask; + var x; + + x = new Complex128Array([ + 4.0, // 0 + 2.0, // 0 + -3.0, + 5.0, + -1.0, // 1 + 2.0, // 1 + -5.0, + 6.0 + ]); + mask = [ + 0, // 0 + 0 // 1 + ]; + expected = new Float64Array([ + -1.0, // 0 + 2.0, // 0 + -3.0, + 5.0, + 4.0, // 1 + 2.0, // 1 + -5.0, + 6.0 + ]); + + gmskrev( 2, x, 2, 0, mask, 1, 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 mask; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0 // 2 + ]; + expected = [ + 6.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 2.0 // 0 + ]; + + gmskrev( 3, x, -2, x.length-1, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ + 2.0, // 3 + -3.0, + -5.0, // 2 + 7.0, + 6.0, // 1 + -1.0, + 0.0 // 0 + ]; + mask = [ + 0, // 0 + 0, // 1 + 0, // 2 + 0 // 3 + ]; + expected = [ + 0.0, // 3 + -3.0, + 6.0, // 2 + 7.0, + -5.0, // 1 + -1.0, + 2.0 // 0 + ]; + + gmskrev( 4, x, -2, x.length-1, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var mask; + var x; + + x = new Complex128Array([ + 4.0, + 2.0, + -3.0, // 1 + 5.0, // 1 + -1.0, + 2.0, + -5.0, // 0 + 6.0 // 0 + ]); + mask = [ + 0, // 0 + 0 // 1 + ]; + expected = new Float64Array([ + 4.0, + 2.0, + -5.0, // 1 + 6.0, // 1 + -1.0, + 2.0, + -3.0, // 0 + 5.0 // 0 + ]); + + gmskrev( 2, x, -2, x.length-1, mask, 1, 0 ); + t.deepEqual( reinterpret128( x, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var expected; + var mask; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]; + mask = [ + 0, + 0, // 0 + 0, // 1 + 0 // 2 + ]; + expected = [ + 1.0, + 6.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 2.0 // 2 + ]; + + gmskrev( 3, x, 2, 1, mask, 1, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0, // 2 + 7.0, + 8.0 // 3 + ]; + mask = [ + 0, + 0, // 0 + 0, // 1 + 0, // 2 + 0 // 3 + ]; + expected = [ + 1.0, + 8.0, // 0 + 3.0, + 6.0, // 1 + 5.0, + 4.0, // 2 + 7.0, + 2.0 // 3 + ]; + + gmskrev( 4, x, 2, 1, mask, 1, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if `stride` is equal to `1`, the function efficiently reverses a strided array', function test( t ) { + var expected; + var mask; + var x; + var i; + + x = new Float64Array( 100 ); + mask = new Uint8Array( 100 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 240 ); + mask = new Uint8Array( 240 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + x = new Float64Array( 101 ); + mask = new Uint8Array( 101 ); + expected = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = i; + expected[ i ] = x.length-i-1; + } + gmskrev( x.length, x, 1, 0, mask, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +});