diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/README.md b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/README.md new file mode 100644 index 000000000000..aa0203747772 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/README.md @@ -0,0 +1,157 @@ + + +# reinterpret + +> Reinterpret a [`BooleanArray`][@stdlib/array/bool] as a [`Uint8Array`][@stdlib/array/uint8]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var reinterpret = require( '@stdlib/strided/base/reinterpret-boolean' ); +``` + +#### reinterpret( x, offset ) + +Returns a [`Uint8Array`][@stdlib/array/uint8] view of a [`BooleanArray`][@stdlib/array/bool]. + +```javascript +var BooleanArray = require( '@stdlib/array/bool' ); + +var x = new BooleanArray( 10 ); + +var view = reinterpret( x, 0 ); +// returns + +var bool = ( view.buffer === x.buffer ); +// returns true + +var len = view.length; +// returns 10 +``` + +The `offset` argument specifies the starting index of the returned [`Uint8Array`][@stdlib/array/uint8] view relative to the [`BooleanArray`][@stdlib/array/bool]. + +```javascript +var BooleanArray = require( '@stdlib/array/bool' ); + +var x = new BooleanArray( [ true, false, false, true, true, false ] ); + +var view = reinterpret( x, 2 ); +// returns + +var len = view.length; +// returns 4 + +var v = view[ 0 ]; +// returns 0 + +v = view[ 1 ]; +// returns 1 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var BooleanArray = require( '@stdlib/array/bool' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-boolean' ); + +// Define a boolean array: +var x = new BooleanArray( [ true, false, false, true, true, false ] ); +// returns + +// Reinterpret as a `uint8` array: +var view = reinterpret( x, 0 ); +// returns + +// Set view elements: +view[ 0 ] = 0; +view[ 1 ] = 1; + +// Get the first element of the boolean array: +var v = x.get( 0 ); +// returns false + +// Get the second element of the boolean array: +v = x.get( 1 ); +// returns true +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/benchmark/benchmark.js b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/benchmark/benchmark.js new file mode 100644 index 000000000000..99ce1560dc7a --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 BooleanArray = require( '@stdlib/array/bool' ); +var isUint8Array = require( '@stdlib/assert/is-uint8array' ); +var pkg = require( './../package.json' ).name; +var reinterpret = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + new BooleanArray( 10 ), + new BooleanArray( 5 ), + new BooleanArray( 20 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = reinterpret( values[ i%values.length ], 1 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint8Array( out ) ) { + b.fail( 'should return a Uint8Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/repl.txt b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/repl.txt new file mode 100644 index 000000000000..3c56de2278b0 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( x, offset ) + Returns a Uint8Array view of a BooleanArray. + + Parameters + ---------- + x: BooleanArray + Input array. + + offset: integer + Starting index of the view relative to the BooleanArray. + + Returns + ------- + out: Uint8Array + Uint8Array view. + + Examples + -------- + > var x = new {{alias:@stdlib/array/bool}}( 10 ); + > var out = {{alias}}( x, 0 ) + + > var bool = ( out.buffer === x.buffer ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/index.d.ts b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/index.d.ts new file mode 100644 index 000000000000..d68821834add --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/index.d.ts @@ -0,0 +1,48 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { BooleanArray } from '@stdlib/types/array'; + +/** +* Reinterprets a `BooleanArray` as a `Uint8Array`. +* +* @param x - input array +* @param offset - starting index +* @returns `Uint8Array` view +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* +* var x = new BooleanArray( 10 ); +* +* var out = reinterpret( x, 0 ); +* // returns +* +* var bool = ( out.buffer === x.buffer ); +* // returns true +*/ +declare function reinterpret( x: BooleanArray, offset: number ): Uint8Array; + + +// EXPORTS // + +export = reinterpret; diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/test.ts b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/test.ts new file mode 100644 index 000000000000..12fa9020bf36 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/docs/types/test.ts @@ -0,0 +1,55 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 BooleanArray = require( '@stdlib/array/bool' ); +import reinterpret = require( './index' ); + + +// TESTS // + +// The function returns a Uint8Array... +{ + reinterpret( new BooleanArray( 10 ), 0 ); // $ExpectType Uint8Array +} + +// The compiler throws an error if not provided a first argument which is a BooleanArray... +{ + reinterpret( '10', 0 ); // $ExpectError + reinterpret( 10, 0 ); // $ExpectError + reinterpret( true, 0 ); // $ExpectError + reinterpret( false, 0 ); // $ExpectError + reinterpret( null, 0 ); // $ExpectError + reinterpret( undefined, 0 ); // $ExpectError + reinterpret( [], 0 ); // $ExpectError + reinterpret( {}, 0 ); // $ExpectError + reinterpret( ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if not provided a second argument which is a number... +{ + const x = new BooleanArray( 10 ); + + reinterpret( x, '10' ); // $ExpectError + reinterpret( x, true ); // $ExpectError + reinterpret( x, false ); // $ExpectError + reinterpret( x, null ); // $ExpectError + reinterpret( x, undefined ); // $ExpectError + reinterpret( x, [] ); // $ExpectError + reinterpret( x, {} ); // $ExpectError + reinterpret( x, ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/examples/index.js b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/examples/index.js new file mode 100644 index 000000000000..4edb7a1fda26 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 BooleanArray = require( '@stdlib/array/bool' ); +var reinterpret = require( './../lib' ); + +// Define a boolean array: +var x = new BooleanArray( [ true, false, false, true, true, false ] ); +// returns + +// Reinterpret as a `uint8` array: +var view = reinterpret( x, 0 ); +// returns + +// Set view elements: +view[ 0 ] = 0; +view[ 1 ] = 1; + +// Get the first element of the boolean array: +var v = x.get( 0 ); +// returns false + +// Get the second element of the boolean array: +v = x.get( 1 ); +// returns true + +console.log( v ); diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/index.js b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/index.js new file mode 100644 index 000000000000..8efbf107d99a --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* Reinterpret a `BooleanArray` as a `Uint8Array`. +* +* @module @stdlib/strided/base/reinterpret-boolean +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var reinterpret = require( '@stdlib/strided/base/reinterpret-boolean' ); +* +* var x = new BooleanArray( 10 ); +* +* var out = reinterpret( x, 0 ); +* // returns +* +* var bool = ( out.buffer === x.buffer ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/main.js b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/main.js new file mode 100644 index 000000000000..0bb18ec52ca9 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/lib/main.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Uint8Array = require( '@stdlib/array/uint8' ); + + +// MAIN // + +/** +* Reinterprets a `BooleanArray` as a `Uint8Array`. +* +* @param {BooleanArray} x - input array +* @param {NonNegativeInteger} offset - starting index +* @returns {Uint8Array} `Uint8Array` view +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* +* var x = new BooleanArray( 10 ); +* +* var out = reinterpret( x, 0 ); +* // returns +* +* var bool = ( out.buffer === x.buffer ); +* // returns true +*/ +function reinterpret( x, offset ) { + return new Uint8Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = reinterpret; diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/package.json b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/package.json new file mode 100644 index 000000000000..9bc90bb0f1dc --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/strided/base/reinterpret-boolean", + "version": "0.0.0", + "description": "Reinterpret a BooleanArray as a Uint8Array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "base", + "strided", + "array", + "boolean", + "uint8", + "reinterpret", + "cast", + "view" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/test/test.js b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/test/test.js new file mode 100644 index 000000000000..15567f303731 --- /dev/null +++ b/lib/node_modules/@stdlib/strided/base/reinterpret-boolean/test/test.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 BooleanArray = require( '@stdlib/array/bool' ); +var isUint8Array = require( '@stdlib/assert/is-uint8array' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var reinterpret = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reinterpret, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function reinterprets a boolean array', function test( t ) { + var values; + var v; + var i; + + values = [ + new BooleanArray( 10 ), + new BooleanArray( 5 ), + new BooleanArray( 20 ) + ]; + + for ( i = 0; i < values.length; i++ ) { + v = reinterpret( values[ i ], 0 ); + t.strictEqual( isUint8Array( v ), true, 'returns a Uint8Array' ); + t.strictEqual( v.buffer, values[ i ].buffer, 'returns a view' ); + t.strictEqual( v.length, values[ i ].length, 'has expected length' ); + t.strictEqual( v.byteOffset, 0, 'has expected byte offset' ); + } + t.end(); +}); + +tape( 'the function reinterprets a boolean array (byte offset)', function test( t ) { + var values; + var buf; + var v; + var i; + + buf = new ArrayBuffer( 1000 ); + values = [ + new BooleanArray( buf, 160, 10 ), + new BooleanArray( buf, 16, 5 ), + new BooleanArray( buf, 56, 20 ) + ]; + + for ( i = 0; i < values.length; i++ ) { + v = reinterpret( values[ i ], 0 ); + t.strictEqual( isUint8Array( v ), true, 'returns a Uint8Array' ); + t.strictEqual( v.buffer, buf, 'returns a view' ); + t.strictEqual( v.length, values[ i ].length, 'has expected length' ); + t.strictEqual( v.byteOffset, values[ i ].byteOffset, 'has expected byte offset' ); + } + t.end(); +}); + +tape( 'the function reinterprets a boolean array (index offset)', function test( t ) { + var values; + var v; + var i; + + values = [ + new BooleanArray( 10 ), + new BooleanArray( 5 ), + new BooleanArray( 20 ) + ]; + + for ( i = 0; i < values.length; i++ ) { + v = reinterpret( values[ i ], 2 ); + t.strictEqual( isUint8Array( v ), true, 'returns a Uint8Array' ); + t.strictEqual( v.buffer, values[ i ].buffer, 'returns a view' ); + t.strictEqual( v.length, (values[ i ].length-2), 'has expected length' ); + t.strictEqual( v.byteOffset, 2, 'has expected byte offset' ); + } + t.end(); +});