diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/README.md new file mode 100644 index 000000000000..8aeb703b9242 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/README.md @@ -0,0 +1,104 @@ + + +# srev + +> Reverse the elements of a one-dimensional single-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var srev = require( '@stdlib/blas/ext/base/ndarray/srev' ); +``` + +#### srev( arrays ) + +Reverses the elements of a one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +srev( [ x ] ); +// xbuf => [ 3.0, 2.0, 1.0 ] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing one one-dimensional `Float32` ndarray. + +
+ + + +
+ +## Examples + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var srev = require( '@stdlib/blas/ext/base/ndarray/srev' ); + +var xbuf; +var x; +var i; + +xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +x = new ndarray( 'float32', xbuf, [ 6 ], [ -1 ], 5, 'row-major' ); + +srev( [ x ] ); + +console.log( 'x:' ); +for ( i = 0; i < 6; i++ ) { + console.log( x.get( i ) ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/benchmark/benchmark.js new file mode 100644 index 000000000000..5485f7005b91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/benchmark/benchmark.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var srev = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var len; + var buf; + var x; + var i; + + len = 100; + buf = new Float32Array( len ); + for ( i = 0; i < len; i++ ) { + buf[ i ] = uniform( -10.0, 10.0 ); + } + x = new ndarray( 'float32', buf, [ len ], [ 1 ], 0, 'row-major' ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + srev( [ x ] ); + if ( isnan( x.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( x.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/repl.txt new file mode 100644 index 000000000000..938e5686b066 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( arrays ) + Reverses the elements of a one-dimensional single-precision floating-point + ndarray. + + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + + Returns + ------- + out: void + The input ndarray is modified in-place. + + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ); + > var dt = 'float32'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x ] ); + > xbuf + [ 3.0, 2.0, 1.0 ] + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/index.d.ts new file mode 100644 index 000000000000..aea1fa91c190 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/index.d.ts @@ -0,0 +1,45 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Reverses the elements of a one-dimensional single-precision floating-point ndarray. +* +* @param arrays - array-like object containing one input ndarray +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* srev( [ x ] ); +* // xbuf => [ 3.0, 2.0, 1.0 ] +*/ +declare function srev( arrays: ArrayLike ): void; + + +// EXPORTS // + +export = srev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/test.ts new file mode 100644 index 000000000000..eb33b13699a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/docs/types/test.ts @@ -0,0 +1,49 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float32Array = require( '@stdlib/array/float32' ); +import ndarray = require( '@stdlib/ndarray/base/ctor' ); +import srev = require( './index' ); + + +// TESTS // + +// The function returns void... +{ + const xbuf = new Float32Array( 10 ); + const x = new ndarray( 'float32', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + + srev( [ x ] ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarrays... +{ + srev( 'abc' ); // $ExpectError + srev( 3.14 ); // $ExpectError + srev( true ); // $ExpectError + srev( false ); // $ExpectError + srev( null ); // $ExpectError + srev( undefined ); // $ExpectError + srev( [ '1' ] ); // $ExpectError + srev( {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an insufficient number of arguments... +{ + srev(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/examples/index.js new file mode 100644 index 000000000000..96f1440090d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var srev = require( './../lib' ); + +var xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 6 ], [ -1 ], 5, 'row-major' ); + +console.log( 'Original:' ); +console.log( x.data ); + +srev( [ x ] ); + +console.log( 'Reversed:' ); +console.log( x.data ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/index.js new file mode 100644 index 000000000000..b6c1abd44af8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 the elements of a one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/srev +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var srev = require( '@stdlib/blas/ext/base/ndarray/srev' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* srev( [ x ] ); +* // xbuf => [ 3.0, 2.0, 1.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/main.js new file mode 100644 index 000000000000..ead5afcd2a37 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/lib/main.js @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); + + +// VARIABLES // + +var M = 3; + + +// MAIN // + +/** +* Reverses the elements of a one-dimensional single-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing one input ndarray +* @returns {void} +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* srev( [ x ] ); +* // xbuf => [ 3.0, 2.0, 1.0 ] +*/ +function srev( arrays ) { + var strideX; + var offset; + var tmp; + var ix; + var iy; + var m; + var n; + var i; + var x; + var N; + var d; + + x = arrays[ 0 ]; + N = numelDimension( x, 0 ); + + if ( N <= 0 ) { + return; + } + d = getData( x ); + strideX = getStride( x, 0 ); + offset = getOffset( x ); + + n = floor( N/2 ); + ix = offset; + + // Use loop unrolling if the stride is equal to `1`... + if ( strideX === 1 ) { + m = n % M; + iy = ix + N - 1; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + tmp = d[ ix ]; + d[ ix ] = d[ iy ]; + d[ iy ] = tmp; + ix += strideX; + iy -= strideX; + } + } + if ( n < M ) { + return; + } + for ( i = m; i < n; i += M ) { + tmp = d[ ix ]; + d[ ix ] = d[ iy ]; + d[ iy ] = tmp; + + tmp = d[ ix+1 ]; + d[ ix+1 ] = d[ iy-1 ]; + d[ iy-1 ] = tmp; + + tmp = d[ ix+2 ]; + d[ ix+2 ] = d[ iy-2 ]; + d[ iy-2 ] = tmp; + + ix += M; + iy -= M; + } + return; + } + iy = ix + ( ( N-1 ) * strideX ); + for ( i = 0; i < n; i++ ) { + tmp = d[ ix ]; + d[ ix ] = d[ iy ]; + d[ iy ] = tmp; + ix += strideX; + iy -= strideX; + } +} + + +// EXPORTS // + +module.exports = srev; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/package.json new file mode 100644 index 000000000000..860805bc776c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/package.json @@ -0,0 +1,86 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/srev", + "version": "0.0.0", + "description": "Reverse the elements of a one-dimensional single-precision floating-point ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "examples": "make examples", + "benchmark": "make benchmark" + }, + "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": { + "@stdlib/math/base/special/floor": "^0.2.2", + "@stdlib/ndarray/base/data-buffer": "^0.2.1", + "@stdlib/ndarray/base/numel-dimension": "^0.2.1", + "@stdlib/ndarray/base/offset": "^0.2.1", + "@stdlib/ndarray/base/stride": "^0.2.1" + }, + "devDependencies": { + "@stdlib/array/float32": "^0.2.2", + "@stdlib/ndarray/base/ctor": "^0.2.2", + "@stdlib/random/base/randu": "^0.2.1", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git", + "bench": "git+https://github.com/kgryte/bench.git" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdblas", + "blas", + "ext", + "extension", + "linear", + "algebra", + "ndarray", + "array", + "reverse", + "srev", + "float32", + "float", + "single" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/test/test.js new file mode 100644 index 000000000000..b8819577955e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/srev/test/test.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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' ); // eslint-disable-line node/no-unpublished-require +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var srev = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof srev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function reverses a strided array in-place (positive stride)', function test( t ) { + var expected; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new ndarray( 'float32', buf, [ 6 ], [ 1 ], 0, 'row-major' ); + srev( [ x ] ); + + expected = new Float32Array( [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function reverses a strided array in-place (negative stride)', function test( t ) { + var expected; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new ndarray( 'float32', buf, [ 6 ], [ -1 ], 5, 'row-major' ); + srev( [ x ] ); + + expected = new Float32Array( [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function reverses a strided array in-place (offset)', function test( t ) { + var expected; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new ndarray( 'float32', buf, [ 4 ], [ 1 ], 1, 'row-major' ); + srev( [ x ] ); + + expected = new Float32Array( [ 1.0, 5.0, 4.0, 3.0, 2.0, 6.0 ] ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns undefined', function test( t ) { + var buf; + var x; + var v; + + buf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + x = new ndarray( 'float32', buf, [ 3 ], [ 1 ], 0, 'row-major' ); + v = srev( [ x ] ); + + t.strictEqual( v, undefined, 'returns undefined' ); + t.end(); +});