From 4e48d21dfdc4ea30bb80c24b07adc0f8db5f0123 Mon Sep 17 00:00:00 2001 From: Uday Kakade Date: Sat, 21 Jun 2025 13:03:11 +0530 Subject: [PATCH 1/5] feat: add array/float16 --- .../@stdlib/array/float16/README.md | 1489 +++++++++++++++++ .../benchmark/benchmark.copy_within.js | 50 + .../benchmark/benchmark.copy_within.length.js | 93 + .../array/float16/benchmark/benchmark.data.js | 75 + .../float16/benchmark/benchmark.entries.js | 50 + .../float16/benchmark/benchmark.every.js | 81 + .../benchmark/benchmark.every.length.js | 105 ++ .../array/float16/benchmark/benchmark.fill.js | 51 + .../benchmark/benchmark.fill.length.js | 94 ++ .../float16/benchmark/benchmark.filter.js | 81 + .../benchmark/benchmark.filter.length.js | 105 ++ .../array/float16/benchmark/benchmark.find.js | 82 + .../benchmark/benchmark.find.length.js | 105 ++ .../float16/benchmark/benchmark.find_index.js | 82 + .../benchmark/benchmark.find_index.length.js | 104 ++ .../float16/benchmark/benchmark.for_each.js | 88 + .../benchmark/benchmark.for_each.length.js | 106 ++ .../array/float16/benchmark/benchmark.from.js | 237 +++ .../float16/benchmark/benchmark.includes.js | 53 + .../benchmark/benchmark.includes.length.js | 96 ++ .../float16/benchmark/benchmark.index_of.js | 53 + .../benchmark/benchmark.index_of.length.js | 95 ++ .../array/float16/benchmark/benchmark.join.js | 51 + .../benchmark/benchmark.join.length.js | 94 ++ .../array/float16/benchmark/benchmark.js | 49 + .../array/float16/benchmark/benchmark.keys.js | 50 + .../benchmark/benchmark.last_index_of.js | 53 + .../benchmark.last_index_of.length.js | 95 ++ .../float16/benchmark/benchmark.length.js | 93 + .../array/float16/benchmark/benchmark.map.js | 81 + .../float16/benchmark/benchmark.map.length.js | 105 ++ .../array/float16/benchmark/benchmark.of.js | 48 + .../float16/benchmark/benchmark.properties.js | 145 ++ .../float16/benchmark/benchmark.reduce.js | 80 + .../benchmark/benchmark.reduce.length.js | 105 ++ .../benchmark/benchmark.reduce_right.js | 80 + .../benchmark.reduce_right.length.js | 105 ++ .../float16/benchmark/benchmark.reverse.js | 52 + .../benchmark/benchmark.reverse.length.js | 95 ++ .../array/float16/benchmark/benchmark.set.js | 94 ++ .../float16/benchmark/benchmark.set.length.js | 114 ++ .../float16/benchmark/benchmark.slice.js | 52 + .../benchmark/benchmark.slice.length.js | 95 ++ .../array/float16/benchmark/benchmark.some.js | 81 + .../benchmark/benchmark.some.length.js | 105 ++ .../array/float16/benchmark/benchmark.sort.js | 53 + .../benchmark/benchmark.sort.length.js | 105 ++ .../float16/benchmark/benchmark.subarray.js | 51 + .../benchmark/benchmark.subarray.length.js | 94 ++ .../benchmark/benchmark.to_locale_string.js | 51 + .../benchmark.to_locale_string.length.js | 94 ++ .../float16/benchmark/benchmark.to_string.js | 51 + .../benchmark/benchmark.to_string.length.js | 94 ++ .../float16/benchmark/benchmark.values.js | 50 + .../@stdlib/array/float16/docs/repl.txt | 959 +++++++++++ .../array/float16/docs/types/index.d.ts | 26 + .../@stdlib/array/float16/docs/types/test.ts | 36 + .../@stdlib/array/float16/examples/index.js | 31 + .../@stdlib/array/float16/lib/index.js | 52 + .../@stdlib/array/float16/lib/main.js | 28 + .../@stdlib/array/float16/lib/polyfill.js | 538 ++++++ .../@stdlib/array/float16/package.json | 69 + .../@stdlib/array/float16/test/test.js | 80 + .../array/float16/test/test.polyfill.js | 44 + 64 files changed, 7803 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/float16/README.md create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.data.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.entries.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.properties.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.length.js create mode 100644 lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.js create mode 100644 lib/node_modules/@stdlib/array/float16/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/float16/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/float16/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/float16/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/float16/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/float16/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/float16/lib/polyfill.js create mode 100644 lib/node_modules/@stdlib/array/float16/package.json create mode 100644 lib/node_modules/@stdlib/array/float16/test/test.js create mode 100644 lib/node_modules/@stdlib/array/float16/test/test.polyfill.js diff --git a/lib/node_modules/@stdlib/array/float16/README.md b/lib/node_modules/@stdlib/array/float16/README.md new file mode 100644 index 000000000000..7f1bb63c6dae --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/README.md @@ -0,0 +1,1489 @@ + + +# Float16Array + +> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of half-precision (16-bit) floating-point numbers in the platform byte order. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float16Array = require( '@stdlib/array/float16' ); + + +#### Float16Array() + +A [typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of half-precision floating-point numbers in the platform byte order. + + + +```javascript +var arr = new Float16Array(); +// returns +``` + +#### Float16Array( length ) + +Returns a [typed array][mdn-typed-array] having a specified length. + + + +```javascript +var arr = new Float16Array( 5 ); +// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] +``` + +#### Float16Array( typedarray ) + +Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var arr1 = new Float64Array( [ 0.5, 0.5, 0.5 ] ); +var arr2 = new Float16Array( arr1 ); +// returns [ 0.5, 0.5, 0.5 ] +``` + +#### Float16Array( obj ) + +Creates a [typed array][mdn-typed-array] from an array-like `object` or iterable. + + + +```javascript +var arr = new Float16Array( [ 0.5, 0.5, 0.5 ] ); +// returns [ 0.5, 0.5, 0.5 ] +``` + +#### Float16Array( buffer\[, byteOffset\[, length]] ) + +Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/array/buffer]. + + + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var buf = new ArrayBuffer( 16 ); +var arr = new Float16Array( buf, 0, 4 ); +// returns [ 0.0, 0.0, 0.0, 0.0 ] +``` + +* * * + +### Properties + + + +#### Float16Array.BYTES_PER_ELEMENT + +Number of bytes per view element. + + + +```javascript +var nbytes = Float16Array.BYTES_PER_ELEMENT; +// returns 2 +``` + + + +#### Float16Array.name + +[Typed array][mdn-typed-array] constructor name. + + + +```javascript +var str = Float16Array.name; +// returns 'Float16Array' +``` + + + +#### Float16Array.prototype.buffer + +**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the [typed array][mdn-typed-array]. + + + +```javascript +var arr = new Float16Array( 5 ); +var buf = arr.buffer; +// returns +``` + + + +#### Float16Array.prototype.byteLength + +**Read-only** property which returns the length (in bytes) of the [typed array][mdn-typed-array]. + + + +```javascript +var arr = new Float16Array( 5 ); +var byteLength = arr.byteLength; +// returns 10 +``` + + + +#### Float16Array.prototype.byteOffset + +**Read-only** property which returns the offset (in bytes) of the [typed array][mdn-typed-array] from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. + + + +```javascript +var arr = new Float16Array( 5 ); +var byteOffset = arr.byteOffset; +// returns 0 +``` + + + +#### Float16Array.prototype.BYTES_PER_ELEMENT + +Number of bytes per view element. + + + +```javascript +var arr = new Float16Array( 5 ); +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 2 +``` + + + +#### Float16Array.prototype.length + +**Read-only** property which returns the number of view elements. + + + +```javascript +var arr = new Float16Array( 5 ); +var len = arr.length; +// returns 5 +``` + +* * * + +### Methods + + + +#### Float16Array.from( src\[, map\[, thisArg]] ) + +Creates a new typed array from an array-like `object` or an iterable. + + + +```javascript +var arr = Float16Array.from( [ 1.0, 2.0 ] ); +// returns [ 1.0, 2.0 ] +``` + +To invoke a function for each `src` value, provide a callback function. + + + +```javascript +function mapFcn( v ) { + return v * 2.0; +} + +var arr = Float16Array.from( [ 1.0, 2.0 ], mapFcn ); +// returns [ 2.0, 4.0 ] +``` + +A callback function is provided two arguments: + +- `value`: source value. +- `index`: source index. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function mapFcn( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr = Float16Array.from( [ 1.0, 2.0 ], mapFcn, ctx ); +// returns [ 2.0, 4.0 ] + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.of( element0\[, element1\[, ...elementN]] ) + +Creates a new typed array from a variable number of arguments. + + + +```javascript +var arr = Float16Array.of( 1.0, 2.0 ); +// returns [ 1.0, 2.0 ] +``` + + + +#### Float16Array.prototype.copyWithin( target, start\[, end] ) + +Copies a sequence of elements within an array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Copy the last two elements to the first two elements: +arr.copyWithin( 0, 3 ); + +var v = arr[ 0 ]; +// returns 4.0 + +v = arr[ 1 ]; +// returns 5.0 +``` + +By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Copy the first two elements to the last two elements: +arr.copyWithin( 3, 0, 2 ); + +var v = arr[ 3 ]; +// returns 1.0 + +v = arr[ 4 ]; +// returns 2.0 +``` + +When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Copy the first two elements to the last two elements: +arr.copyWithin( -2, -5, -3 ); + +var v = arr[ 3 ]; +// returns 1.0 + +v = arr[ 4 ]; +// returns 2.0 +``` + + + +#### Float16Array.prototype.entries() + +Returns an iterator for iterating over array key-value pairs. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +// Create an iterator: +var it = arr.entries(); + +// Iterate over key-value pairs... +var v = it.next().value; +// returns [ 0, 1.0 ] + +v = it.next().value; +// returns [ 1, 2.0 ] + +var bool = it.next().done; +// returns true +``` + + + +#### Float16Array.prototype.every( predicate\[, thisArg] ) + +Tests whether all array elements pass a test implemented by a `predicate` function. + + + +```javascript +function predicate( v ) { + return ( v <= 1.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var bool = arr.every( predicate ); +// returns false +``` + +A `predicate` function is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function predicate( v ) { + this.count += 1; + return ( v >= 1.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var bool = arr.every( predicate, ctx ); +// returns true + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.prototype.fill( value\[, start\[, end]] ) + +Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `value`. + + + +```javascript +var arr = new Float16Array( 2 ); + +// Set all array elements to the same value: +arr.fill( 2.0 ); + +var v = arr[ 0 ]; +// returns 2.0 + +v = arr[ 1 ]; +// returns 2.0 + +// Set all array elements starting from the first index to the same value: +arr.fill( 3.0, 1 ); + +v = arr[ 0 ]; +// returns 2.0 + +v = arr[ 1 ]; +// returns 3.0 + +// Set all array elements, except the last element, to the same value: +arr.fill( 4.0, 0, arr.length-1 ); + +v = arr[ 0 ]; +// returns 4.0 + +v = arr[ 1 ]; +// returns 3.0 +``` + +When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. + + + +```javascript +var arr = new Float16Array( 2 ); + +// Set all array elements, except the last element, to the same value: +arr.fill( 2.0, -arr.length, -1 ); + +var v = arr[ 0 ]; +// returns 2.0 + +v = arr[ 1 ]; +// returns 0.0 +``` + + + +#### Float16Array.prototype.filter( predicate\[, thisArg] ) + +Creates a new array (of the same data type as the host array) which includes those elements for which a `predicate` function returns a truthy value. + + + +```javascript +function predicate( v ) { + return ( v >= 2.0 ); +} + +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.filter( predicate ); +// returns [ 2.0, 3.0 ] +``` + +If a `predicate` function does not return a truthy value for any array element, the method returns an empty array. + + + +```javascript +function predicate( v ) { + return ( v >= 10.0 ); +} + +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.filter( predicate ); +// returns [] +``` + +A `predicate` function is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function predicate( v ) { + this.count += 1; + return ( v >= 2.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.filter( predicate, ctx ); + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.find( predicate\[, thisArg] ) + +Returns the first array element for which a provided `predicate` function returns a truthy value. + + + +```javascript +function predicate( v ) { + return ( v > 2.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.find( predicate ); +// returns 3.0 +``` + +If a `predicate` function does not return a truthy value for any array element, the method returns `undefined`. + + + +```javascript +function predicate( v ) { + return ( v < 1.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.find( predicate ); +// returns undefined +``` + +A `predicate` function is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function predicate( v ) { + this.count += 1; + return ( v > 2.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.find( predicate, ctx ); +// returns 3.0 + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.findIndex( predicate\[, thisArg] ) + +Returns the index of the first array element for which a provided `predicate` function returns a truthy value. + + + +```javascript +function predicate( v ) { + return ( v >= 3.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.findIndex( predicate ); +// returns 2 +``` + +If a `predicate` function does not return a truthy value for any array element, the method returns `-1`. + + + +```javascript +function predicate( v ) { + return ( v < 1.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.findIndex( predicate ); +// returns -1 +``` + +A `predicate` function is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function predicate( v ) { + this.count += 1; + return ( v >= 3.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.findIndex( predicate, ctx ); +// returns 2 + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.forEach( fcn\[, thisArg] ) + +Invokes a callback for each array element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = ''; + +function fcn( v, i ) { + str += i + ':' + v; + if ( i < arr.length-1 ) { + str += ' '; + } +} + +arr.forEach( fcn ); + +console.log( str ); +// => '0:1 1:2 2:3' +``` + +The callback is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function fcn() { + this.count += 1; +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +arr.forEach( fcn, ctx ); + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.includes( searchElement\[, fromIndex] ) + +Returns a `boolean` indicating whether an array includes a search element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var bool = arr.includes( 3.0 ); +// returns true + +bool = arr.includes( 0.0 ); +// returns false +``` + +By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var bool = arr.includes( 1.0, 1 ); +// returns false +``` + +When a `fromIndex` is negative, the starting index is resolved relative to the last array element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var bool = arr.includes( 1.0, -2 ); +// returns false +``` + +The method does **not** distinguish between signed and unsigned zero. + + + +#### Float16Array.prototype.indexOf( searchElement\[, fromIndex] ) + +Returns the index of the first array element strictly equal to a search element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.indexOf( 3.0 ); +// returns 2 + +idx = arr.indexOf( 0.0 ); +// returns -1 +``` + +By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.indexOf( 1.0, 1 ); +// returns -1 +``` + +When a `fromIndex` is negative, the starting index is resolved relative to the last array element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.indexOf( 1.0, -2 ); +// returns -1 +``` + +The method does **not** distinguish between signed and unsigned zero. + + + +#### Float16Array.prototype.join( \[separator] ) + +Serializes an array by joining all array elements as a string. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.join(); +// returns '1,2,3' +``` + +By default, the method delineates array elements using a comma `,`. To specify a custom separator, provide a `separator` string. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.join( '|' ); +// returns '1|2|3' +``` + + + +#### Float16Array.prototype.keys() + +Returns an iterator for iterating over array keys. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +// Create an iterator: +var it = arr.keys(); + +// Iterate over keys... +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +var bool = it.next().done; +// returns true +``` + + + +#### Float16Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) + +Returns the index of the last array element strictly equal to a search element, iterating from right to left. + + + +```javascript +var arr = new Float16Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); + +var idx = arr.lastIndexOf( 0.0 ); +// returns 3 + +idx = arr.lastIndexOf( 3.0 ); +// returns -1 +``` + +By default, the method searches the entire array (`fromIndex = -1`). To begin searching from a specific array index, provide a `fromIndex`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); + +var idx = arr.lastIndexOf( 0.0, 2 ); +// returns 1 +``` + +When a `fromIndex` is negative, the starting index is resolved relative to the last array element. + + + +```javascript +var arr = new Float16Array( [ 1.0, 0.0, 2.0, 0.0, 1.0 ] ); + +var idx = arr.lastIndexOf( 0.0, -3 ); +// returns 1 +``` + +The method does **not** distinguish between signed and unsigned zero. + + + +#### Float16Array.prototype.map( fcn\[, thisArg] ) + +Maps each array element to an element in a new array having the same data type as the host array. + + + +```javascript +function fcn( v ) { + return v * 2.0; +} + +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.map( fcn ); +// returns [ 2.0, 4.0, 6.0 ] +``` + +A callback is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function fcn( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.map( fcn, ctx ); + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.reduce( fcn\[, initialValue] ) + +Applies a function against an accumulator and each element in an array and returns the accumulated result. + + + +```javascript +function fcn( acc, v ) { + return acc + ( v*v ); +} + +var arr = new Float16Array( [ 2.0, 1.0, 3.0 ] ); + +var v = arr.reduce( fcn ); +// returns 12.0 +``` + +If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument. + +If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument. + + + +```javascript +function fcn( acc, v ) { + return acc + ( v*v ); +} + +var arr = new Float16Array( [ 2.0, 1.0, 3.0 ] ); + +var v = arr.reduce( fcn, 0.0 ); +// returns 14.0 +``` + +A callback is provided four arguments: + +- `acc`: accumulated result. +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + + + +#### Float16Array.prototype.reduceRight( fcn\[, initialValue] ) + +Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left. + + + +```javascript +function fcn( acc, v ) { + return acc + ( v*v ); +} + +var arr = new Float16Array( [ 2.0, 1.0, 3.0 ] ); + +var v = arr.reduceRight( fcn ); +// returns 8.0 +``` + +If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument. + +If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument. + + + +```javascript +function fcn( acc, v ) { + return acc + ( v*v ); +} + +var arr = new Float16Array( [ 2.0, 1.0, 3.0 ] ); + +var v = arr.reduce( fcn, 0.0 ); +// returns 14.0 +``` + +A callback is provided four arguments: + +- `acc`: accumulated result. +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + + + +#### Float16Array.prototype.reverse() + +Reverses an array **in-place** (thus mutating the array on which the method is invoked). + + + +```javascript +var arr = new Float16Array( [ 2.0, 0.0, 3.0 ] ); + +// Reverse the array: +arr.reverse(); + +var v = arr[ 0 ]; +// returns 3.0 + +v = arr[ 1 ]; +// returns 0.0 + +v = arr[ 2 ]; +// returns 2.0 +``` + + + +#### Float16Array.prototype.set( arr\[, offset] ) + +Sets array elements. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); +// returns [ 1.0, 2.0, 3.0 ] + +// Set the first two array elements: +arr.set( [ 4.0, 5.0 ] ); + +var v = arr[ 0 ]; +// returns 4.0 + +v = arr[ 1 ]; +// returns 5.0 +``` + +By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); +// returns [ 1.0, 2.0, 3.0 ] + +// Set the last two array elements: +arr.set( [ 4.0, 5.0 ], 1 ); + +var v = arr[ 1 ]; +// returns 4.0 + +v = arr[ 2 ]; +// returns 5.0 +``` + + + +#### Float16Array.prototype.slice( \[begin\[, end]] ) + +Copies array elements to a new array with the same underlying data type as the host array. + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.slice(); + +var bool = ( arr1 === arr2 ); +// returns false + +bool = ( arr1.buffer === arr2.buffer ); +// returns false + +var v = arr2[ 0 ]; +// returns 1.0 + +v = arr2[ 1 ]; +// returns 2.0 + +v = arr2[ 2 ]; +// returns 3.0 +``` + +By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a `begin` index (inclusive). + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.slice( 1 ); + +var len = arr2.length; +// returns 2 + +var v = arr2[ 0 ]; +// returns 2.0 + +v = arr2[ 1 ]; +// returns 3.0 +``` + +By default, the method copies all array elements after `begin`. To specify an alternative array index at which to end copying, provide an `end` index (exclusive). + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.slice( 0, 2 ); + +var len = arr2.length; +// returns 2 + +var v = arr2[ 0 ]; +// returns 1.0 + +v = arr2[ 1 ]; +// returns 2.0 +``` + +When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.slice( -arr1.length, -1 ); + +var len = arr2.length; +// returns 2 + +var v = arr2[ 0 ]; +// returns 1.0 + +v = arr2[ 1 ]; +// returns 2.0 +``` + + + +#### Float16Array.prototype.some( predicate\[, thisArg] ) + +Tests whether at least one array element passes a test implemented by a `predicate` function. + + + +```javascript +function predicate( v ) { + return ( v >= 2.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var bool = arr.some( predicate ); +// returns true +``` + +A `predicate` function is provided three arguments: + +- `value`: array element. +- `index`: array index. +- `arr`: array on which the method is invoked. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function predicate( v ) { + this.count += 1; + return ( v >= 2.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 1.0 ] ); + +var bool = arr.some( predicate, ctx ); +// returns false + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.prototype.sort( \[compareFunction] ) + +Sorts an array **in-place** (thus mutating the array on which the method is invoked). + + + +```javascript +var arr = new Float16Array( [ 2.0, 3.0, 0.0 ] ); + +// Sort the array (in ascending order): +arr.sort(); + +var v = arr[ 0 ]; +// returns 0.0 + +v = arr[ 1 ]; +// returns 2.0 + +v = arr[ 2 ]; +// returns 3.0 +``` + +By default, the method sorts array elements in ascending order. To impose a custom order, provide a `compareFunction`. + + + +```javascript +function descending( a, b ) { + return b - a; +} + +var arr = new Float16Array( [ 2.0, 3.0, 0.0 ] ); + +// Sort the array (in descending order): +arr.sort( descending ); + +var v = arr[ 0 ]; +// returns 3.0 + +v = arr[ 1 ]; +// returns 2.0 + +v = arr[ 2 ]; +// returns 0.0 +``` + +The comparison function is provided two array elements, `a` and `b`, per invocation, and its return value determines the sort order as follows: + +- If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`). +- If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`). +- If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged. + + + +#### Float16Array.prototype.subarray( \[begin\[, end]] ) + +Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.subarray(); +// returns [ 1.0, 2.0, 3.0 ] + +var bool = ( arr1.buffer === arr2.buffer ); +// returns true +``` + +By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.subarray( 1 ); +// returns [ 2.0, 3.0 ] + +var bool = ( arr1.buffer === arr2.buffer ); +// returns true +``` + +By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.subarray( 0, 2 ); +// returns [ 1.0, 2.0 ] + +var bool = ( arr1.buffer === arr2.buffer ); +// returns true +``` + +When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.subarray( -arr1.length, -1 ); +// returns [ 1.0, 2.0 ] + +var bool = ( arr1.buffer === arr2.buffer ); +// returns true +``` + +If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array. + + + +```javascript +var arr1 = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var arr2 = arr1.subarray( 10, -1 ); +// returns [] +``` + + + +#### Float16Array.prototype.toLocaleString( \[locales\[, options]] ) + +Serializes an array as a locale-specific `string`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toLocaleString(); +// returns '1,2,3' +``` + + + +#### Float16Array.prototype.toString() + +Serializes an array as a `string`. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.toString(); +// returns '1,2,3' +``` + + + +#### Float16Array.prototype.values() + +Returns an iterator for iterating over array elements. + + + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +// Create an iterator: +var it = arr.values(); + +// Iterate over array elements... +var v = it.next().value; +// returns 1.0 + +v = it.next().value; +// returns 2.0 + +var bool = it.next().done; +// returns true +``` + +
+ + + +* * * + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var ctor = require( '@stdlib/array/float16' ); + +var arr; +var i; + +arr = new ctor( 10 ); +for ( i = 0; i < arr.length; i++ ) { + arr[ i ] = randu() * 100.0; +} +console.log( arr ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.js new file mode 100644 index 000000000000..dbf8a2837a3c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':copyWithin', function benchmark( b ) { + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== i ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.length.js new file mode 100644 index 000000000000..01668f1284ad --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.length.js @@ -0,0 +1,93 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== i ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':copyWithin:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.data.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.data.js new file mode 100644 index 000000000000..d8aa253d5caf --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.data.js @@ -0,0 +1,75 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::get,index', function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( 2 ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr[ i%N ]; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,index', function benchmark( b ) { + var arr; + var N; + var i; + + arr = new Float16Array( 2 ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ i%N ] = i; + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.entries.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.entries.js new file mode 100644 index 000000000000..f4ac2cf53b99 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.entries.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':entries', function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( [ 1.0, 2.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.entries(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.js new file mode 100644 index 000000000000..32e70afd9d8b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.js @@ -0,0 +1,81 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':every', function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); + +bench( pkg+'::this_context:every', function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate, {} ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.length.js new file mode 100644 index 000000000000..01f8bacbf7da --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.length.js @@ -0,0 +1,105 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return value >= 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':every:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.js new file mode 100644 index 000000000000..3cdf17366c8c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.js @@ -0,0 +1,51 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':fill', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = i % 128; + arr = arr.fill( v ); + if ( arr[ 0 ] !== v ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js new file mode 100644 index 000000000000..4c4338095ba0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = i % 128; + arr = arr.fill( v ); + if ( arr[ 0 ] !== v ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':fill:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.js new file mode 100644 index 000000000000..13852ea3a9f7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.js @@ -0,0 +1,81 @@ +/** +* @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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':filter', function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); + +bench( pkg+'::this_context:filter', function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate, {} ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js new file mode 100644 index 000000000000..34b7e7c5bd37 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return value >= 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.filter( predicate ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':filter:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.js new file mode 100644 index 000000000000..82b56b2e226e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.js @@ -0,0 +1,82 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':find', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); + +bench( pkg+'::this_context:find', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate, {} ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.length.js new file mode 100644 index 000000000000..d81885e5f655 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.length.js @@ -0,0 +1,105 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return value > 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - tuple length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.find( predicate ); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof out !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':find:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.js new file mode 100644 index 000000000000..88bb9d03a72c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.js @@ -0,0 +1,82 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':findIndex', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); + +bench( pkg+'::this_context:findIndex', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate, {} ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.length.js new file mode 100644 index 000000000000..ec18df389885 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.length.js @@ -0,0 +1,104 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return value > 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findIndex( predicate ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':findIndex:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.js new file mode 100644 index 000000000000..95b95fddf272 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.js @@ -0,0 +1,88 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':forEach', function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( 2 ); + N = arr.length; + + count = 0; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn ); + if ( count !== N*(i+1) ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( count !== N*i ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn() { + count += 1; + } +}); + +bench( pkg+'::this_context:forEach', function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( 2 ); + N = arr.length; + + count = 0; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn, {} ); + if ( count !== N*(i+1) ) { + b.fail( 'unexpected result' ); + } + } + b.toc(); + if ( count !== N*i ) { + b.fail( 'unexpected result' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn() { + count += 1; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.length.js new file mode 100644 index 000000000000..06a3593cfcfe --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.length.js @@ -0,0 +1,106 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var count; + var arr; + + arr = new Float16Array( len ); + count = 0; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr.forEach( fcn ); + if ( count !== count ) { + b.fail( 'should not be NaN' ); + } + } + b.toc(); + if ( count !== count ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } + + /** + * Callback invoked for each tuple element. + * + * @private + */ + function fcn() { + count += 1; + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':forEach:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js new file mode 100644 index 000000000000..3476a001aec1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js @@ -0,0 +1,237 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( pkg+'::typed_array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( [ 1.0, 2.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( buf ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array,clbk:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( [ 1.0, 2.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( buf, clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( pkg+'::array:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 2.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( buf ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array,clbk:from', function benchmark( b ) { + var buf; + var arr; + var i; + + buf = [ 1.0, 2.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( buf, clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( pkg+'::iterable:from', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( createIterable() ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out; + var i; + + out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + + i = 0; + + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + i += 1; + if ( i <= 2 ) { + return { + 'value': 0.0, + 'done': false + }; + } + return { + 'done': true + }; + } + } +}); + +bench( pkg+'::iterable,clbk:from:', opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.from( createIterable(), clbk ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out; + var i; + + out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + + i = 0; + + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + i += 1; + if ( i <= 2 ) { + return { + 'value': 1.0, + 'done': false + }; + } + return { + 'done': true + }; + } + } + + function clbk( v ) { + return v + 1.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.js new file mode 100644 index 000000000000..9b941b96ef33 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.js @@ -0,0 +1,53 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':includes', function benchmark( b ) { + var bool; + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + bool = arr.includes( v ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.length.js new file mode 100644 index 000000000000..3a1def4cd881 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.length.js @@ -0,0 +1,96 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + bool = arr.includes( v ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':includes:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.js new file mode 100644 index 000000000000..5dd1bc0244cc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.js @@ -0,0 +1,53 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':indexOf', function benchmark( b ) { + var out; + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + out = arr.indexOf( v ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.length.js new file mode 100644 index 000000000000..b86daf85d60c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + out = arr.indexOf( v ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':indexOf:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.js new file mode 100644 index 000000000000..8b8a15bf3bba --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.js @@ -0,0 +1,51 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':join', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i % 127; + out = arr.join(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.length.js new file mode 100644 index 000000000000..543fe9f7bdfa --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i % 127; + out = arr.join(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':join:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.js new file mode 100644 index 000000000000..3c9a81e61892 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var ctor = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new ctor( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +// TODO: add additional instantiation benchmarks (e.g., ArrayBuffer, etc) diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js new file mode 100644 index 000000000000..0e79e851a2d1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':keys', function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.keys(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.js new file mode 100644 index 000000000000..be16c1644652 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.js @@ -0,0 +1,53 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':lastIndexOf', function benchmark( b ) { + var out; + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + out = arr.lastIndexOf( v ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.length.js new file mode 100644 index 000000000000..ab87f85041b3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.last_index_of.length.js @@ -0,0 +1,95 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = (i%127) + 1.0; + out = arr.lastIndexOf( v ); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + } + b.toc(); + if ( out !== -1 ) { + b.fail( 'should return -1' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':lastIndexOf:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js new file mode 100644 index 000000000000..2050edf7f209 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var ctor = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new ctor( len ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js new file mode 100644 index 000000000000..997e46d36a0a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':map', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); + +bench( pkg+'::this_context:map', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn, {} ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js new file mode 100644 index 000000000000..e2429481fbf7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Maps an array element to a new value. +* +* @private +* @param {*} value - array element +* @returns {*} new value +*/ +function fcn( value ) { + return value + 1.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.map( fcn ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':map:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js new file mode 100644 index 000000000000..fcd777e7c643 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':of', function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = Float16Array.of( i, 2.0 ); + if ( arr.length !== 2 ) { + b.fail( 'should have length 2' ); + } + } + b.toc(); + if ( !isFloat16Array( arr ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.properties.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.properties.js new file mode 100644 index 000000000000..333b6d52a60e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.properties.js @@ -0,0 +1,145 @@ +/** +* @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 isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+'::get:buffer', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.buffer; + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArrayBuffer( v ) ) { + b.fail( 'should return an ArrayBuffer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteLength', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteLength; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:byteOffset', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.byteOffset; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.BYTES_PER_ELEMENT; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:length', function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... + v = arr.length; + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isNonNegativeInteger( v ) ) { + b.fail( 'should return a nonnegative integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.js new file mode 100644 index 000000000000..c87b8e8ece8b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.js @@ -0,0 +1,80 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':reduce', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( fcn ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( acc, v ) { + return acc + v + 1.0; + } +}); + +bench( pkg+'::initial_value:reduce', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( fcn, 3.14 ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.length.js new file mode 100644 index 000000000000..d1c2c8f3e909 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.length.js @@ -0,0 +1,105 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// FUNCTIONS // + +/** +* Updates an accumulated value. +* +* @private +* @param {*} acc - accumulated value +* @param {*} value - array element +* @returns {*} accumulated value +*/ +function fcn( acc, value ) { + return acc + value + 1.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( fcn ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':reduce:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.js new file mode 100644 index 000000000000..10e28ffc5ae0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.js @@ -0,0 +1,80 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':reduceRight', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( fcn ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( acc, v ) { + return acc + v + 1.0; + } +}); + +bench( pkg+'::initial_value:reduceRight', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( fcn, 3.14 ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.length.js new file mode 100644 index 000000000000..50dc92c4d5b4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.length.js @@ -0,0 +1,105 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// FUNCTIONS // + +/** +* Updates an accumulated value. +* +* @private +* @param {*} acc - accumulated value +* @param {*} value - array element +* @returns {*} accumulated value +*/ +function fcn( acc, value ) { + return acc + value + 1.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( fcn ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':reduceRight:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.js new file mode 100644 index 000000000000..40cb7b1f86db --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.js @@ -0,0 +1,52 @@ +/** +* @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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':reverse', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.reverse(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js new file mode 100644 index 000000000000..28cdc4e8bc69 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.reverse(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':reverse:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.js new file mode 100644 index 000000000000..a9b65fe212b0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.js @@ -0,0 +1,94 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::array:set', function benchmark( b ) { + var values; + var buf; + var arr; + var N; + var v; + var i; + + values = []; + for ( i = 0; i < 10; i++ ) { + values.push( i ); + } + N = values.length; + + arr = new Float16Array( 2 ); + buf = [ 0.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::typed_array:set', function benchmark( b ) { + var values; + var buf; + var arr; + var N; + var v; + var i; + + values = new Float16Array( 20 ); + N = values.length; + for ( i = 0; i < N; i++ ) { + values[ i ] = i; + } + + arr = new Float16Array( 2 ); + buf = new Float16Array( 1 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + buf[ 0 ] = values[ i%N ]; + v = arr.set( buf ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.length.js new file mode 100644 index 000000000000..9d9de7a9807d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.length.js @@ -0,0 +1,114 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var randi = require( '@stdlib/random/base/randi' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var values; + var arr1; + var arr2; + var arr; + var N; + var i; + + arr1 = []; + arr2 = []; + for ( i = 0; i < len; i++ ) { + arr1.push( randi() ); + arr2.push( randi() ); + } + arr = new Float16Array( len ); + + values = [ + arr1, + arr2 + ]; + N = values.length; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.set( values[ i%N ] ); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + } + b.toc(); + if ( typeof v !== 'undefined' ) { + b.fail( 'should return undefined' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':set:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js new file mode 100644 index 000000000000..8a85d40bd3ca --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':slice', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.slice(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js new file mode 100644 index 000000000000..a0859b021d78 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.slice(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':slice:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.js new file mode 100644 index 000000000000..df8b7323d49e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.js @@ -0,0 +1,81 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':some', function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.some( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); + +bench( pkg+'::this_context:some', function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.some( predicate, {} ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v > 0.0; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.length.js new file mode 100644 index 000000000000..d88927ada099 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.length.js @@ -0,0 +1,105 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return value > 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.some( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':some:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.js new file mode 100644 index 000000000000..e9b021455231 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.js @@ -0,0 +1,53 @@ +/** +* @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 randi = require( '@stdlib/random/base/randi' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':sort', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( [ randi(), randi() ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = randi(); + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js new file mode 100644 index 000000000000..590a46b516b3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var randi = require( '@stdlib/random/base/randi' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var data; + var arr; + var i; + + data = []; + for ( i = 0; i < len; i++ ) { + data.push( randi() ); + } + arr = new Float16Array( data ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ i%len ] = randi(); + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':sort:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.js new file mode 100644 index 000000000000..c53df7bebba3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.js @@ -0,0 +1,51 @@ +/** +* @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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':subarray', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.subarray(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.length.js new file mode 100644 index 000000000000..01a22d71f180 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.subarray(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isFloat16Array( out ) ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':subarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.js new file mode 100644 index 000000000000..e00a683d1b16 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.js @@ -0,0 +1,51 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':toLocaleString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toLocaleString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js new file mode 100644 index 000000000000..ac8fd111e353 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toLocaleString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toLocaleString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.js new file mode 100644 index 000000000000..9156b61dc86c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.js @@ -0,0 +1,51 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.length.js new file mode 100644 index 000000000000..da63ec444db6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.length.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 5; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.js new file mode 100644 index 000000000000..52caf4535cbb --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.js @@ -0,0 +1,50 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib/polyfill.js' ); + + +// MAIN // + +bench( pkg+':values', function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = arr.values(); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/docs/repl.txt b/lib/node_modules/@stdlib/array/float16/docs/repl.txt new file mode 100644 index 000000000000..9a39d53fada5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/repl.txt @@ -0,0 +1,959 @@ + +{{alias}}() + A typed array constructor which returns a typed array representing an array + of single-precision floating-point numbers in the platform byte order. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}() + + + +{{alias}}( length ) + Returns a typed array having a specified length. + + Parameters + ---------- + length: integer + Typed array length. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + + +{{alias}}( typedarray ) + Creates a typed array from another typed array. + + Parameters + ---------- + typedarray: TypedArray + Typed array from which to generate another typed array. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr1 = new {{alias:@stdlib/array/float64}}( [ 0.5, 0.5, 0.5 ] ); + > var arr2 = new {{alias}}( arr1 ) + [ 0.5, 0.5, 0.5 ] + + +{{alias}}( obj ) + Creates a typed array from an array-like object or iterable. + + Parameters + ---------- + obj: Object + Array-like object or iterable from which to generate a typed array. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr1 = [ 0.5, 0.5, 0.5 ]; + > var arr2 = new {{alias}}( arr1 ) + [ 0.5, 0.5, 0.5 ] + + +{{alias}}( buffer[, byteOffset[, length]] ) + Returns a typed array view of an ArrayBuffer. + + Parameters + ---------- + buffer: ArrayBuffer + Underlying ArrayBuffer. + + byteOffset: integer (optional) + Integer byte offset specifying the location of the first typed array + element. Default: 0. + + length: integer (optional) + View length. If not provided, the view spans from the byteOffset to + the end of the underlying ArrayBuffer. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var buf = new {{alias:@stdlib/array/buffer}}( 16 ); + > var arr = new {{alias}}( buf, 0, 4 ) + [ 0.0, 0.0, 0.0, 0.0 ] + + +{{alias}}.from( src[, map[, thisArg]] ) + Creates a new typed array from an array-like object or an iterable. + + A callback is provided the following arguments: + + - value: source value. + - index: source index. + + Parameters + ---------- + src: ArrayLike|Iterable + Source of array elements. + + map: Function (optional) + Callback to invoke for each source element. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > function mapFcn( v ) { return v * 2.0; }; + > var arr = {{alias}}.from( [ 1.0, -1.0 ], mapFcn ) + [ 2.0, -2.0 ] + + +{{alias}}.of( element0[, element1[, ...elementN]] ) + Creates a new typed array from a variable number of arguments. + + Parameters + ---------- + element0: number + Array element. + + element1: number (optional) + Array element. + + elementN: ...number (optional) + Array elements. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = {{alias}}.of( 2.0, -2.0 ) + [ 2.0, -2.0 ] + + +{{alias}}.BYTES_PER_ELEMENT + Number of bytes per view element. + + Examples + -------- + > {{alias}}.BYTES_PER_ELEMENT + 4 + + +{{alias}}.name + Typed array constructor name. + + Examples + -------- + > {{alias}}.name + 'Float16Array' + + +{{alias}}.prototype.buffer + Read-only property which returns the ArrayBuffer referenced by the typed + array. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.buffer + + + +{{alias}}.prototype.byteLength + Read-only property which returns the length (in bytes) of the typed array. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.byteLength + 20 + + +{{alias}}.prototype.byteOffset + Read-only property which returns the offset (in bytes) of the typed array + from the start of its ArrayBuffer. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.byteOffset + 0 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Number of bytes per view element. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.BYTES_PER_ELEMENT + 4 + + +{{alias}}.prototype.length + Read-only property which returns the number of view elements. + + Examples + -------- + > var arr = new {{alias}}( 5 ); + > arr.length + 5 + + +{{alias}}.prototype.copyWithin( target, start[, end] ) + Copies a sequence of elements within the array starting at `start` and + ending at `end` (non-inclusive) to the position starting at `target`. + + Parameters + ---------- + target: integer + Target start index position. + + start: integer + Source start index position. + + end: integer (optional) + Source end index position. Default: out.length. + + Returns + ------- + out: Float16Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 2.0, -2.0, 1.0, -1.0, 1.0 ] ); + > arr.copyWithin( 3, 0, 2 ); + > arr[ 3 ] + 2.0 + > arr[ 4 ] + -2.0 + + +{{alias}}.prototype.entries() + Returns an iterator for iterating over array key-value pairs. + + Returns + ------- + iter: Iterator + Iterator for iterating over array key-value pairs. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > it = arr.entries(); + > it.next().value + [ 0, 1.0 ] + > it.next().value + [ 1, -1.0 ] + > it.next().done + true + + +{{alias}}.prototype.every( predicate[, thisArg] ) + Tests whether all array elements pass a test implemented by a predicate + function. + + A predicate function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. If a predicate function + returns a truthy value, an array element passes; otherwise, an array + element fails. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether all array elements pass. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > function predicate( v ) { return ( v >= 0.0 ); }; + > arr.every( predicate ) + false + + +{{alias}}.prototype.fill( value[, start[, end]] ) + Fills an array from a start index to an end index (non-inclusive) with a + provided value. + + Parameters + ---------- + value: number + Fill value. + + start: integer (optional) + Start index. If less than zero, the start index is resolved relative to + the last array element. Default: 0. + + end: integer (optional) + End index (non-inclusive). If less than zero, the end index is resolved + relative to the last array element. Default: out.length. + + Returns + ------- + out: Float16Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > arr.fill( 2.0 ); + > arr[ 0 ] + 2.0 + > arr[ 1 ] + 2.0 + + +{{alias}}.prototype.filter( predicate[, thisArg] ) + Creates a new array which includes those elements for which a predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + The returned array has the same data type as the host array. + + If a predicate function does not return a truthy value for any array + element, the method returns `null`. + + Parameters + ---------- + predicate: Function + Predicate function which filters array elements. If a predicate function + returns a truthy value, an array element is included in the output + array; otherwise, an array element is not included in the output array. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr1 = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function predicate( v ) { return ( v >= 0.0 ); }; + > var arr2 = arr1.filter( predicate ); + > arr2.length + 2 + + +{{alias}}.prototype.find( predicate[, thisArg] ) + Returns the first array element for which a provided predicate function + returns a truthy value. + + A predicate function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + If a predicate function never returns a truthy value, the method returns + `undefined`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + value: number|undefined + Array element. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function predicate( v ) { return ( v < 0.0 ); }; + > var v = arr.find( predicate ) + -1.0 + + +{{alias}}.prototype.findIndex( predicate[, thisArg] ) + Returns the index of the first array element for which a provided predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + If a predicate function never returns a truthy value, the method returns + `-1`. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + idx: integer + Array index. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function predicate( v ) { return ( v < 0.0 ); }; + > var idx = arr.findIndex( predicate ) + 2 + + +{{alias}}.prototype.forEach( fcn[, thisArg] ) + Invokes a callback for each array element. + + A provided function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + Parameters + ---------- + fcn: Function + Function to invoke for each array element. + + thisArg: Any (optional) + Callback execution context. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > var str = ' '; + > function fcn( v, i ) { str += i + ':' + v + ' '; }; + > arr.forEach( fcn ); + > str + ' 0:1 1:0 2:-1 ' + + +{{alias}}.prototype.includes( searchElement[, fromIndex] ) + Returns a boolean indicating whether an array includes a search element. + + The method does not distinguish between signed and unsigned zero. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index from which to begin searching. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: 0. + + Returns + ------- + bool: boolean + Boolean indicating whether an array includes a search element. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > var bool = arr.includes( 2.0 ) + false + > bool = arr.includes( -1.0 ) + true + + +{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) + Returns the index of the first array element strictly equal to a search + element. + + The method does not distinguish between signed and unsigned zero. + + If unable to locate a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index from which to begin searching. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: 0. + + Returns + ------- + idx: integer + Array index. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > var idx = arr.indexOf( 2.0 ) + -1 + > idx = arr.indexOf( -1.0 ) + 2 + + +{{alias}}.prototype.join( [separator] ) + Serializes an array by joining all array elements as a string. + + Parameters + ---------- + separator: string (optional) + String delineating array elements. Default: ','. + + Returns + ------- + str: string + Array serialized as a string. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > arr.join( '|' ) + '1|0|-1' + + +{{alias}}.prototype.keys() + Returns an iterator for iterating over array keys. + + Returns + ------- + iter: Iterator + Iterator for iterating over array keys. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > it = arr.keys(); + > it.next().value + 0 + > it.next().value + 1 + > it.next().done + true + + +{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) + Returns the index of the last array element strictly equal to a search + element. + + The method iterates from the last array element to the first array element. + + The method does not distinguish between signed and unsigned zero. + + If unable to locate a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index from which to begin searching. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: -1. + + Returns + ------- + idx: integer + Array index. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0, 0.0, 1.0 ] ); + > var idx = arr.lastIndexOf( 2.0 ) + -1 + > idx = arr.lastIndexOf( 0.0 ) + 3 + + +{{alias}}.prototype.map( fcn[, thisArg] ) + Maps each array element to an element in a new typed array. + + A provided function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + The returned array has the same data type as the host array. + + Parameters + ---------- + fcn: Function + Function which maps array elements to elements in the new array. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr1 = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function fcn( v ) { return v * 2.0; }; + > var arr2 = arr1.map( fcn ) + [ 2.0, 0.0, -2.0 ] + + +{{alias}}.prototype.reduce( fcn[, initialValue] ) + Applies a function against an accumulator and each element in an array and + returns the accumulated result. + + The provided function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: index of the current array element. + - arr: array on which the method is invoked. + + If provided an initial value, the method invokes a provided function with + the initial value as the first argument and the first array element as the + second argument. + + If not provided an initial value, the method invokes a provided function + with the first array element as the first argument and the second array + element as the second argument. + + Parameters + ---------- + fcn: Function + Function to apply. + + initialValue: Any (optional) + Initial accumulation value. + + Returns + ------- + out: Any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function fcn( acc, v ) { return acc + (v*v); }; + > var v = arr.reduce( fcn, 0.0 ) + 2.0 + + +{{alias}}.prototype.reduceRight( fcn[, initialValue] ) + Applies a function against an accumulator and each element in an array and + returns the accumulated result, iterating from right to left. + + The provided function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: index of the current array element. + - arr: array on which the method is invoked. + + If provided an initial value, the method invokes a provided function with + the initial value as the first argument and the last array element as the + second argument. + + If not provided an initial value, the method invokes a provided function + with the last array element as the first argument and the second-to-last + array element as the second argument. + + Parameters + ---------- + fcn: Function + Function to apply. + + initialValue: Any (optional) + Initial accumulation value. + + Returns + ------- + out: Any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > function fcn( acc, v ) { return acc + (v*v); }; + > var v = arr.reduceRight( fcn, 0.0 ) + 2.0 + + +{{alias}}.prototype.reverse() + Reverses an array *in-place*. + + This method mutates the array on which the method is invoked. + + Returns + ------- + out: Float16Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ) + + > arr.reverse() + [ -1.0, 0.0, 1.0 ] + + +{{alias}}.prototype.set( arr[, offset] ) + Sets array elements. + + Parameters + ---------- + arr: ArrayLike + Source array containing array values to set. + + offset: integer (optional) + Array index at which to start writing values. Default: 0. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > arr.set( [ -2.0, 2.0 ], 1 ); + > arr[ 1 ] + -2.0 + > arr[ 2 ] + 2.0 + + +{{alias}}.prototype.slice( [begin[, end]] ) + Copies array elements to a new array with the same underlying data type as + the host array. + + If the method is unable to resolve indices to a non-empty array subsequence, + the method returns `null`. + + Parameters + ---------- + begin: integer (optional) + Start element index (inclusive). If less than zero, the start index is + resolved relative to the last array element. Default: 0. + + end: integer (optional) + End element index (exclusive). If less than zero, the end index is + resolved relative to the last array element. Default: arr.length. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr1 = new {{alias}}( [ 1.0, 0.0, -1.0 ] ); + > var arr2 = arr1.slice( 1 ); + > arr2.length + 2 + > arr2[ 0 ] + 0.0 + > arr2[ 1 ] + -1.0 + + +{{alias}}.prototype.some( predicate[, thisArg] ) + Tests whether at least one array element passes a test implemented by a + predicate function. + + A predicate function is provided the following arguments: + + - value: array element. + - index: array index. + - arr: array on which the method is invoked. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. If a predicate function + returns a truthy value, a array element passes; otherwise, an array + element fails. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether at least one array element passes. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > function predicate( v ) { return ( v < 0.0 ); }; + > arr.some( predicate ) + true + + +{{alias}}.prototype.sort( [compareFunction] ) + Sorts an array *in-place*. + + The comparison function is provided two array elements per invocation: `a` + and `b`. + + The comparison function return value determines the sort order as follows: + + - If the comparison function returns a value less than zero, then the method + sorts `a` to an index lower than `b` (i.e., `a` should come *before* `b`). + + - If the comparison function returns a value greater than zero, then the + method sorts `a` to an index higher than `b` (i.e., `b` should come *before* + `a`). + + - If the comparison function returns zero, then the relative order of `a` + and `b` should remain unchanged. + + This method mutates the array on which the method is invoked. + + Parameters + ---------- + compareFunction: Function (optional) + Function which specifies the sort order. The default sort order is + ascending order. + + Returns + ------- + out: Float16Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0, 0.0, 2.0, -2.0 ] ); + > arr.sort() + [ -2.0, -1.0, 0.0, 1.0, 2.0 ] + + +{{alias}}.prototype.subarray( [begin[, end]] ) + Creates a new typed array over the same underlying ArrayBuffer and with the + same underlying data type as the host array. + + If the method is unable to resolve indices to a non-empty array subsequence, + the method returns an empty typed array. + + Parameters + ---------- + begin: integer (optional) + Start element index (inclusive). If less than zero, the start index is + resolved relative to the last array element. Default: 0. + + end: integer (optional) + End element index (exclusive). If less than zero, the end index is + resolved relative to the last array element. Default: arr.length. + + Returns + ------- + out: Float16Array + A new typed array view. + + Examples + -------- + > var arr1 = new {{alias}}( [ 1.0, -1.0, 0.0, 2.0, -2.0 ] ); + > var arr2 = arr1.subarray( 2 ) + [ 0.0, 2.0, -2.0 ] + + +{{alias}}.prototype.toLocaleString( [locales[, options]] ) + Serializes an array as a locale-specific string. + + Parameters + ---------- + locales: string|Array (optional) + A BCP 47 language tag, or an array of such tags. + + options: Object (optional) + Options. + + Returns + ------- + str: string + A typed array string representation. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0, 0.0 ] ); + > arr.toLocaleString() + '1,-1,0' + + +{{alias}}.prototype.toString() + Serializes an array as a string. + + Returns + ------- + str: string + A typed array string representation. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0, 0.0 ] ); + > arr.toString() + '1,-1,0' + + +{{alias}}.prototype.values() + Returns an iterator for iterating over array elements. + + Returns + ------- + iter: Iterator + Iterator for iterating over array elements. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, -1.0 ] ); + > it = arr.values(); + > it.next().value + 1.0 + > it.next().value + -1.0 + > it.next().done + true + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/float16/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/float16/docs/types/index.d.ts new file mode 100644 index 000000000000..1dbbcdebaaf6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/types/index.d.ts @@ -0,0 +1,26 @@ +/* +* @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 + +// EXPORTS // + +/** +* Typed array constructor which returns a typed array representing an array of half-precision floating-point numbers in the platform byte order. +*/ +export = Float16Array; diff --git a/lib/node_modules/@stdlib/array/float16/docs/types/test.ts b/lib/node_modules/@stdlib/array/float16/docs/types/test.ts new file mode 100644 index 000000000000..5d2ceb4cdfaf --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/types/test.ts @@ -0,0 +1,36 @@ +/* +* @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. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import Float16Array = require( './index' ); + + +// TESTS // + +// The function returns a typed array instance... +{ + new Float16Array( 10 ); // $ExpectType Float16Array + new Float16Array( [ 2.1, 3.9, 5.2, 7.3 ] ); // $ExpectType Float16Array +} + +// The constructor function has to be invoked with `new`... +{ + Float16Array( 10 ); // $ExpectError + Float16Array( [ 2.1, 3.9, 5.2, 7.3 ] ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/float16/examples/index.js b/lib/node_modules/@stdlib/array/float16/examples/index.js new file mode 100644 index 000000000000..1653629b4680 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var ctor = require( './../lib' ); + +var arr; +var i; + +arr = new ctor( 10 ); +for ( i = 0; i < arr.length; i++ ) { + arr[ i ] = randu() * 100.0; +} +console.log( arr ); diff --git a/lib/node_modules/@stdlib/array/float16/lib/index.js b/lib/node_modules/@stdlib/array/float16/lib/index.js new file mode 100644 index 000000000000..e7c13c3a4f93 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/index.js @@ -0,0 +1,52 @@ +/** +* @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'; + +/** +* Typed array constructor which returns a typed array representing an array of half-precision floating-point numbers in the platform byte order. +* +* @module @stdlib/array/float16 +* +* @example +* var ctor = require( '@stdlib/array/float16' ); +* +* var arr = new ctor( 10 ); +* // returns +*/ + +// MODULES // + +var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); +var builtin = require( './main.js' ); +var polyfill = require( './polyfill.js' ); + + +// MAIN // + +var ctor; +if ( hasFloat16ArraySupport() ) { + ctor = builtin; +} else { + ctor = polyfill; +} + + +// EXPORTS // + +module.exports = ctor; diff --git a/lib/node_modules/@stdlib/array/float16/lib/main.js b/lib/node_modules/@stdlib/array/float16/lib/main.js new file mode 100644 index 000000000000..9c7250c3f661 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/main.js @@ -0,0 +1,28 @@ +/** +* @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'; + +// MAIN // + +var ctor = ( typeof Float16Array === 'function' ) ? Float16Array : void 0; // eslint-disable-line stdlib/require-globals + + +// EXPORTS // + +module.exports = ctor; diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js new file mode 100644 index 000000000000..498388d5a0cd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js @@ -0,0 +1,538 @@ +/** +* @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'; + +// MAIN // + +class Float16Array { + constructor(input) { + if (typeof input === 'number') { + this._buffer = new Uint16Array(input); + } else if (Array.isArray(input)) { + this._buffer = new Uint16Array(input.length); + for (let i = 0; i < input.length; i++) { + this._buffer[i] = Float16Array.toFloat16(input[i]); + } + } else { + throw new TypeError('Unsupported constructor argument'); + } + this.length = this._buffer.length; + } + + get(index) { + return Float16Array.fromFloat16(this._buffer[index]); + } + + get buffer() { + return this._buffer.buffer; + } + + get byteLength() { + return this._buffer.byteLength; + } + + get byteOffset() { + return this._buffer.byteOffset; + } + + get BYTES_PER_ELEMENT() { + return 2; + } + + get [Symbol.toStringTag]() { + return 'Float16Array'; + } + + copyWithin(target, start, end) { + target = target >> 0; + start = start >> 0; + end = end === undefined ? this.length : end >> 0; + + const to = target < 0 ? this.length + target : target; + const from = start < 0 ? this.length + start : start; + const final = end < 0 ? this.length + end : end; + + const count = Math.min(final - from, this.length - to); + const direction = from < to && to < (from + count) ? -1 : 1; + + if (direction === -1) { + for (let i = count - 1; i >= 0; i--) { + this._buffer[to + i] = this._buffer[from + i]; + } + } else { + for (let i = 0; i < count; i++) { + this._buffer[to + i] = this._buffer[from + i]; + } + } + return this; + } + + set(indexOrArray, value) { + if (typeof indexOrArray === 'number') { + if (indexOrArray < 0 || indexOrArray >= this.length) { + throw new RangeError('Index out of bounds'); + } + this._buffer[indexOrArray] = Float16Array.toFloat16(value); + return; + } + + const source = indexOrArray; + const offset = value !== undefined ? Number(value) : 0; + + if (offset < 0 || offset > this.length) { + throw new RangeError('Offset is out of bounds'); + } + + if ( + (Array.isArray(source) || + (ArrayBuffer.isView(source) && typeof source.length === 'number') || + (source instanceof Float16Array)) + ) { + const len = Math.min(source.length, this.length - offset); + for (let i = 0; i < len; i++) { + const val = typeof source.get === 'function' ? source.get(i) : source[i]; + this._buffer[offset + i] = Float16Array.toFloat16(val); + } + return; + } + + throw new TypeError('Invalid arguments for set'); + } + + entries() { + return this._entriesGenerator(); +} + +*_entriesGenerator() { + for (let i = 0; i < this.length; i++) { + yield [i, this.get(i)]; + } +} + +every(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + for (let i = 0; i < this.length; i++) { + const value = this.get(i); + if (!callback.call(thisArg, value, i, this)) { + return false; + } + } + return true; +} + +filter(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + + const result = []; + for (let i = 0; i < this.length; i++) { + const value = this.get(i); + if (callback.call(thisArg, value, i, this)) { + result.push(value); + } + } + + return new Float16Array(result); +} + +findIndex(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + + for (let i = 0; i < this.length; i++) { + const value = this.get(i); + if (callback.call(thisArg, value, i, this)) { + return i; + } + } + return -1; +} + +find(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + + for (let i = 0; i < this.length; i++) { + const value = this.get(i); + if (callback.call(thisArg, value, i, this)) { + return value; + } + } + return undefined; +} + +forEach(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + for (let i = 0; i < this.length; i++) { + callback.call(thisArg, this.get(i), i, this); + } +} + +static from(source, mapFn, thisArg) { + if (source == null) { + throw new TypeError('source cannot be null or undefined'); + } + if (mapFn !== undefined && typeof mapFn !== 'function') { + throw new TypeError('when provided, mapFn must be a function'); + } + + let values = []; + const iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator; + + if (iteratorSymbol && source[iteratorSymbol]) { + const iterator = source[iteratorSymbol](); + let step; + while (!(step = iterator.next()).done) { + values.push(step.value); + } + } else if (typeof source.length === 'number') { + for (let i = 0; i < source.length; i++) { + values.push(source[i]); + } + } else { + throw new TypeError('source is not iterable or array-like'); + } + + if (mapFn) { + if (thisArg) { + values = values.map(function(v, i) { + return mapFn.call(thisArg, v, i); + }); + } else { + values = values.map(mapFn); + } + } + + const arr = new Float16Array(values.length); + for (let i = 0; i < values.length; i++) { + arr.set(i, values[i]); + } + return arr; +} + +includes(searchElement, fromIndex = 0) { + if (fromIndex < 0) { + fromIndex = Math.max(this.length + fromIndex, 0); + } + for (let i = fromIndex; i < this.length; i++) { + if (this.get(i) === searchElement) { + return true; + } + } + return false; +} + +indexOf(searchElement, fromIndex = 0) { + fromIndex = Math.max(fromIndex >= 0 ? fromIndex : this.length + fromIndex, 0); + for (let i = fromIndex; i < this.length; i++) { + if (this.get(i) === searchElement) { + return i; + } + } + return -1; +} + +join(separator = ',') { + let result = ''; + for (let i = 0; i < this.length; i++) { + if (i > 0) result += separator; + result += String(this.get(i)); + } + return result; +} + +keys() { + return this._keysGenerator(); +} + +*_keysGenerator() { + for (let i = 0; i < this.length; i++) { + yield i; + } +} + +lastIndexOf(searchElement, fromIndex) { + let i = fromIndex !== undefined ? fromIndex : this.length - 1; + if (i >= this.length) i = this.length - 1; + if (i < 0) i = this.length + i; + + for (; i >= 0; i--) { + if (Object.is(this.get(i), searchElement)) { + return i; + } + } + return -1; +} + +map(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError(callback + ' is not a function'); + } + + const result = new this.constructor(this.length); + + for (let i = 0; i < this.length; i++) { + if (Object.prototype.hasOwnProperty.call(this, i)) { + const mappedValue = callback.call(thisArg, this.get(i), i, this); + result.set(i, mappedValue); + } + } + + return result; +} + +slice(start = 0, end = this.length) { + const len = this.length; + + let relativeStart = start < 0 ? Math.max(len + start, 0) : Math.min(start, len); + let relativeEnd = end < 0 ? Math.max(len + end, 0) : Math.min(end, len); + + const count = Math.max(relativeEnd - relativeStart, 0); + const result = new this.constructor(count); + + for (let i = 0; i < count; i++) { + result.set(i, this.get(relativeStart + i)); + } + return result; +} + +sort(compareFn) { + const values = []; + for (let i = 0; i < this.length; i++) { + values.push(this.get(i)); + } + + values.sort((a, b) => { + if (compareFn) return compareFn(a, b); + if (a !== a) return 1; + if (b !== b) return -1; + return a - b; + }); + + for (let i = 0; i < this.length; i++) { + this.set(i, values[i]); + } + return this; +} + +values() { + return this._valuesGenerator(); +} + +*_valuesGenerator() { + for (let i = 0; i < this.length; i++) { + yield this.get(i); + } +} + +some(callback, thisArg) { + if (typeof callback !== 'function') { + throw new TypeError(callback + ' is not a function'); + } + for (let i = 0; i < this.length; i++) { + const value = this.get(i); + if (callback.call(thisArg, value, i, this)) { + return true; + } + } + return false; +} + +reduce(callback, initialValue) { + const length = this.length; + if (typeof callback !== 'function') { + throw new TypeError(callback + ' is not a function'); + } + + let accumulator; + let startIndex = 0; + + if (arguments.length >= 2) { + accumulator = initialValue; + } else { + if (length === 0) { + throw new TypeError('Reduce of empty array with no initial value'); + } + accumulator = this.get(0); + startIndex = 1; + } + + for (let i = startIndex; i < length; i++) { + accumulator = callback(accumulator, this.get(i), i, this); + } + + return accumulator; +} + +reduceRight(callback, initialValue) { + const length = this.length; + if (typeof callback !== 'function') { + throw new TypeError(callback + ' is not a function'); + } + + let accumulator; + let startIndex = length - 1; + + if (arguments.length >= 2) { + accumulator = initialValue; + } else { + if (length === 0) { + throw new TypeError('Reduce of empty array with no initial value'); + } + accumulator = this.get(startIndex); + startIndex--; + } + + for (let i = startIndex; i >= 0; i--) { + accumulator = callback(accumulator, this.get(i), i, this); + } + + return accumulator; +} + +subarray(begin = 0, end = this.length) { + const len = this.length; + + let start = begin < 0 ? Math.max(len + begin, 0) : Math.min(begin, len); + let finish = end < 0 ? Math.max(len + end, 0) : Math.min(end, len); + + start = Math.min(start, len); + finish = Math.min(Math.max(finish, start), len); + + const count = Math.max(finish - start, 0); + const SubArrayCtor = this.constructor; + + const result = new SubArrayCtor(count); + + for (let i = 0; i < count; i++) { + result.set(i, this.get(start + i)); + } + return result; +} + +reverse() { + const mid = Math.floor(this.length / 2); + for (let i = 0; i < mid; i++) { + const j = this.length - 1 - i; + + const temp = this._buffer[i]; + this._buffer[i] = this._buffer[j]; + this._buffer[j] = temp; + } + return this; +} + + fill(value, start = 0, end = this.length) { + start = start < 0 ? Math.max(this.length + start, 0) : Math.min(start, this.length); + end = end < 0 ? Math.max(this.length + end, 0) : Math.min(end, this.length); + + const bits = Float16Array.toFloat16(value); + + for (let i = start; i < end; i++) { + this._buffer[i] = bits; + + Object.defineProperty(this, i, { + get: () => this.get(i), + set: (val) => this.set(i, val), + enumerable: true, + configurable: true + }); + } + return this; +} + + static of(...args) { + const arr = new Float16Array(args.length); + for (let i = 0; i < args.length; i++) { + arr.set(i, args[i]); + } + return arr; +} + + static toFloat16(val) { + const floatView = new Float32Array(1); + const intView = new Uint32Array(floatView.buffer); + + floatView[0] = val; + const x = intView[0]; + + const sign = (x >> 16) & 0x8000; + const exponent = ((x >> 23) & 0xff) - 127; + const fraction = x & 0x7fffff; + + if (exponent <= -15) { + if (exponent < -24) return sign; + const sub = (fraction | 0x800000) >> (-exponent - 1); + return sign | (sub >> 13); + } + + if (exponent >= 16) { + return sign | 0x7c00; + } + + const exp = exponent + 15; + const frac = fraction >> 13; + return sign | (exp << 10) | frac; + } + + static fromFloat16(bits) { + const sign = (bits & 0x8000) << 16; + let exponent = (bits & 0x7C00) >> 10; + const fraction = bits & 0x03FF; + + let result; + if (exponent === 0) { + if (fraction === 0) { + result = sign; + } else { + exponent = 1; + while ((fraction & 0x0400) === 0) { + fraction <<= 1; + exponent--; + } + fraction &= ~0x0400; + const exp32 = 127 - 15 - exponent; + const frac32 = fraction << 13; + result = sign | (exp32 << 23) | frac32; + } + } else if (exponent === 0x1F) { + result = sign | 0x7F800000 | (fraction << 13); + } else { + const exp32 = exponent - 15 + 127; + result = sign | (exp32 << 23) | (fraction << 13); + } + + const intView = new Uint32Array(1); + intView[0] = result; + const floatView = new Float32Array(intView.buffer); + return floatView[0]; + } +} + + +// EXPORTS // + +module.exports = Float16Array; diff --git a/lib/node_modules/@stdlib/array/float16/package.json b/lib/node_modules/@stdlib/array/float16/package.json new file mode 100644 index 000000000000..34eb6b834170 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/array/float16", + "version": "0.0.0", + "description": "Float16Array polyfill and fallback interface.", + "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/index.js", + "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", + "stdtypes", + "types", + "data", + "structure", + "array", + "typed", + "typed array", + "typed-array", + "float16array", + "float16", + "float", + "half", + "half-precision", + "ieee754" + ], + "type": "commonjs" +} diff --git a/lib/node_modules/@stdlib/array/float16/test/test.js b/lib/node_modules/@stdlib/array/float16/test/test.js new file mode 100644 index 000000000000..364340deb159 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.js @@ -0,0 +1,80 @@ +/** +* @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' ); +var proxyquire = require( 'proxyquire' ); +var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); +var polyfill = require( './../lib/polyfill.js' ); +var ctor = require( './../lib' ); + + +// VARIABLES // + +var hasFloat16Arrays = hasFloat16ArraySupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if an environment supports `Float16Array`, the export is an alias for `Float16Array`', function test( t ) { + var Foo; + + Foo = proxyquire( './../lib', { + '@stdlib/assert/has-float16array-support': isTrue, + './main.js': Mock + }); + t.strictEqual( Foo, Mock, 'returns builtin' ); + + if ( hasFloat16Arrays ) { + t.strictEqual( ctor, Float16Array, 'is alias' ); // eslint-disable-line stdlib/require-globals + } + + t.end(); + + function Mock() { + return this; + } + + function isTrue() { + return true; + } +}); + +tape( 'if an environment does not support `Float16Array`, the export is a polyfill', function test( t ) { + var Foo; + + Foo = proxyquire( './../lib', { + '@stdlib/assert/has-float16array-support': isFalse + }); + + t.strictEqual( Foo, polyfill, 'returns polyfill' ); + t.end(); + + function isFalse() { + return false; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.polyfill.js b/lib/node_modules/@stdlib/array/float16/test/test.polyfill.js new file mode 100644 index 000000000000..7ede661f99ee --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.polyfill.js @@ -0,0 +1,44 @@ +/** +* @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' ); +var ctor = require( './../lib/polyfill.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error when invoked', function test( t ) { + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + var f = new ctor(); // eslint-disable-line no-unused-vars + } +}); + +// TODO: tests From 8c52f252b972e0afd4fe490c35a3d1338a13ca07 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 21 Jun 2025 07:43:37 +0000 Subject: [PATCH 2/5] chore: update copyright years --- .../@stdlib/array/float16/benchmark/benchmark.filter.length.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.from.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.length.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.map.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.map.length.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.of.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.reverse.length.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.slice.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.slice.length.js | 2 +- .../@stdlib/array/float16/benchmark/benchmark.sort.length.js | 2 +- .../float16/benchmark/benchmark.to_locale_string.length.js | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js index 34b7e7c5bd37..a5db89b74105 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js index 3476a001aec1..01d161d647d4 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js index 2050edf7f209..3256f4f5f8e6 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js index 997e46d36a0a..410dadb2e6b0 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js index e2429481fbf7..9c33a9e6186f 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js index fcd777e7c643..62122c2fd8a7 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js index 28cdc4e8bc69..9f720967d445 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js index 8a85d40bd3ca..b4742b949cae 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js index a0859b021d78..bd3e7fd4c47b 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js index 590a46b516b3..9c5733512bcf 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js index ac8fd111e353..604006f98df4 100644 --- a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. From 8611f89659c9b1c44cc853b48cc1518cbaf7c475 Mon Sep 17 00:00:00 2001 From: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> Date: Sun, 29 Jun 2025 11:44:18 +0530 Subject: [PATCH 3/5] Refactored Polyfill.js Signed-off-by: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> --- .../@stdlib/array/float16/lib/polyfill.js | 1305 +++++++++++------ 1 file changed, 835 insertions(+), 470 deletions(-) diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js index 498388d5a0cd..f35849f885cb 100644 --- a/lib/node_modules/@stdlib/array/float16/lib/polyfill.js +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js @@ -18,520 +18,885 @@ 'use strict'; -// MAIN // +// MODULES // -class Float16Array { - constructor(input) { - if (typeof input === 'number') { - this._buffer = new Uint16Array(input); - } else if (Array.isArray(input)) { - this._buffer = new Uint16Array(input.length); - for (let i = 0; i < input.length; i++) { - this._buffer[i] = Float16Array.toFloat16(input[i]); - } - } else { - throw new TypeError('Unsupported constructor argument'); - } - this.length = this._buffer.length; - } - - get(index) { - return Float16Array.fromFloat16(this._buffer[index]); - } - - get buffer() { - return this._buffer.buffer; - } - - get byteLength() { - return this._buffer.byteLength; - } - - get byteOffset() { - return this._buffer.byteOffset; - } - - get BYTES_PER_ELEMENT() { - return 2; - } - - get [Symbol.toStringTag]() { - return 'Float16Array'; - } - - copyWithin(target, start, end) { - target = target >> 0; - start = start >> 0; - end = end === undefined ? this.length : end >> 0; - - const to = target < 0 ? this.length + target : target; - const from = start < 0 ? this.length + start : start; - const final = end < 0 ? this.length + end : end; - - const count = Math.min(final - from, this.length - to); - const direction = from < to && to < (from + count) ? -1 : 1; - - if (direction === -1) { - for (let i = count - 1; i >= 0; i--) { - this._buffer[to + i] = this._buffer[from + i]; - } - } else { - for (let i = 0; i < count; i++) { - this._buffer[to + i] = this._buffer[from + i]; - } - } - return this; - } - - set(indexOrArray, value) { - if (typeof indexOrArray === 'number') { - if (indexOrArray < 0 || indexOrArray >= this.length) { - throw new RangeError('Index out of bounds'); - } - this._buffer[indexOrArray] = Float16Array.toFloat16(value); - return; - } - - const source = indexOrArray; - const offset = value !== undefined ? Number(value) : 0; - - if (offset < 0 || offset > this.length) { - throw new RangeError('Offset is out of bounds'); - } - - if ( - (Array.isArray(source) || - (ArrayBuffer.isView(source) && typeof source.length === 'number') || - (source instanceof Float16Array)) - ) { - const len = Math.min(source.length, this.length - offset); - for (let i = 0; i < len; i++) { - const val = typeof source.get === 'function' ? source.get(i) : source[i]; - this._buffer[offset + i] = Float16Array.toFloat16(val); - } - return; - } - - throw new TypeError('Invalid arguments for set'); - } - - entries() { - return this._entriesGenerator(); -} +var min = require( '@stdlib/math/base/special/min' ); +var max = require( '@stdlib/math/base/special/max' ); +var floor = require( '@stdlib/math/base/special/floor' ); -*_entriesGenerator() { - for (let i = 0; i < this.length; i++) { - yield [i, this.get(i)]; - } -} - -every(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - for (let i = 0; i < this.length; i++) { - const value = this.get(i); - if (!callback.call(thisArg, value, i, this)) { - return false; - } - } - return true; -} -filter(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - - const result = []; - for (let i = 0; i < this.length; i++) { - const value = this.get(i); - if (callback.call(thisArg, value, i, this)) { - result.push(value); - } - } +// MAIN // - return new Float16Array(result); +/** +* Creates a new Float16Array. +* +* @constructor +* @param {(number|Array|ArrayBuffer|TypedArray)} input - Input data or buffer +* @param {NonNegativeInteger} [byteOffset=0] - Byte offset +* @param {NonNegativeInteger} [length] - Number of elements +* @throws {TypeError} Must provide valid input +*/ +function Float16Array( input, byteOffset, length ) { + var i; + var len; + var offset; + + byteOffset = byteOffset || 0; + + if ( typeof input === 'number' ) { + this._buffer = new Uint16Array( input ); + } else if ( input instanceof ArrayBuffer ) { + offset = byteOffset >>> 0; + len = ( typeof length !== 'undefined' ) ? ( length >>> 0 ) : ( ( input.byteLength - offset) / 2 ); + this._buffer = new Uint16Array( input, offset, len ); + } else if (Object.prototype.toString.call( input ) === '[object Array]' ) { + this._buffer = new Uint16Array( input.length ); + for (i = 0; i < input.length; i++) { + this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); + } + } else if ( typeof input === 'object' && typeof input.length === 'number' ) { + this._buffer = new Uint16Array( input.length ); + for ( i = 0; i < input.length; i++ ) { + this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); + } + } else { + throw new TypeError( 'Invalid argument. Must provide a number, Array, ArrayBuffer, or typed array. Value: ' + input + '.' ); + } + + this.length = this._buffer.length; } -findIndex(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - - for (let i = 0; i < this.length; i++) { - const value = this.get(i); - if (callback.call(thisArg, value, i, this)) { - return i; - } - } - return -1; -} +/** +* Get the underlying `ArrayBuffer`. +* +* @name buffer +* @memberof Float16Array.prototype +* @readonly +* @type {ArrayBuffer} +*/ +Object.defineProperty( Float16Array.prototype, 'buffer', { + get: function() { + return this._buffer.buffer; + } +}); -find(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - - for (let i = 0; i < this.length; i++) { - const value = this.get(i); - if (callback.call(thisArg, value, i, this)) { - return value; - } - } - return undefined; -} +/** +* Get the total number of bytes in the `Float16Array`. +* +* @name byteLength +* @memberof Float16Array.prototype +* @readonly +* @type {NonNegativeInteger} +*/ +Object.defineProperty( Float16Array.prototype, 'byteLength', { + get: function() { + return this._buffer.byteLength; + } +}); -forEach(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError('callback must be a function'); - } - for (let i = 0; i < this.length; i++) { - callback.call(thisArg, this.get(i), i, this); - } -} +/** +* Get the byte offset within the underlying `ArrayBuffer`. +* +* @name byteOffset +* @memberof Float16Array.prototype +* @readonly +* @type {NonNegativeInteger} +*/ +Object.defineProperty( Float16Array.prototype, 'byteOffset', { + get: function() { + return this._buffer.byteOffset; + } +}); -static from(source, mapFn, thisArg) { - if (source == null) { - throw new TypeError('source cannot be null or undefined'); - } - if (mapFn !== undefined && typeof mapFn !== 'function') { - throw new TypeError('when provided, mapFn must be a function'); - } - - let values = []; - const iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator; - - if (iteratorSymbol && source[iteratorSymbol]) { - const iterator = source[iteratorSymbol](); - let step; - while (!(step = iterator.next()).done) { - values.push(step.value); - } - } else if (typeof source.length === 'number') { - for (let i = 0; i < source.length; i++) { - values.push(source[i]); - } - } else { - throw new TypeError('source is not iterable or array-like'); - } - - if (mapFn) { - if (thisArg) { - values = values.map(function(v, i) { - return mapFn.call(thisArg, v, i); - }); - } else { - values = values.map(mapFn); - } - } - - const arr = new Float16Array(values.length); - for (let i = 0; i < values.length; i++) { - arr.set(i, values[i]); - } - return arr; -} +/** +* Size in bytes of each element. +* +* @name BYTES_PER_ELEMENT +* @memberof Float16Array.prototype +* @readonly +* @type {PositiveInteger} +*/ +Object.defineProperty( Float16Array.prototype, 'BYTES_PER_ELEMENT', { + get: function() { + return 2; + } +}); -includes(searchElement, fromIndex = 0) { - if (fromIndex < 0) { - fromIndex = Math.max(this.length + fromIndex, 0); - } - for (let i = fromIndex; i < this.length; i++) { - if (this.get(i) === searchElement) { - return true; - } - } - return false; -} +/** +* Returns the default string tag. +* +* @name [Symbol.toStringTag] +* @memberof Float16Array.prototype +* @readonly +* @type {string} +*/ +Object.defineProperty( Float16Array.prototype, ( typeof Symbol !== 'undefined' && Symbol.toStringTag ) || '__toStringTag__', { + get: function() { + return 'Float16Array'; + } +}); -indexOf(searchElement, fromIndex = 0) { - fromIndex = Math.max(fromIndex >= 0 ? fromIndex : this.length + fromIndex, 0); - for (let i = fromIndex; i < this.length; i++) { - if (this.get(i) === searchElement) { - return i; - } - } - return -1; -} +/** +* Converts a float32 number to a float16 (binary) representation. +* +* @param {number} val - Float32 value +* @returns {integer} Float16 bit pattern +*/ +Float16Array.toFloat16 = function( val ) { + var floatView = new Float32Array( 1 ); + var intView = new Uint32Array( floatView.buffer ); + var sign; + var exponent; + var fraction; + var exp; + var frac; + + floatView[ 0 ] = val; + var x = intView[ 0 ]; + + sign = ( x >> 16 ) & 0x8000; + exponent = ( ( x >> 23 ) & 0xff ) - 127; + fraction = x & 0x7fffff; + + if ( exponent <= -15 ) { + if ( exponent < -24 ) { + return sign; + } + return sign | ( ( ( fraction | 0x800000 ) >> ( -exponent - 1 ) ) >> 13 ); + } + + if ( exponent >= 16 ) { + return sign | 0x7c00; + } + + exp = exponent + 15; + frac = fraction >> 13; + return sign | ( exp << 10 ) | frac; +}; -join(separator = ',') { - let result = ''; - for (let i = 0; i < this.length; i++) { - if (i > 0) result += separator; - result += String(this.get(i)); - } - return result; -} +/** +* Converts a float16 binary representation to float32. +* +* @param {integer} bits - Float16 bit pattern +* @returns {number} Float32 value +*/ +Float16Array.fromFloat16 = function( bits ) { + var sign = ( bits & 0x8000 ) << 16; + var exponent = ( bits & 0x7C00 ) >> 10; + var fraction = bits & 0x03FF; + var intView = new Uint32Array( 1 ); + var floatView; + var result; + var exp32; + var frac32; + + if ( exponent === 0 ) { + if ( fraction === 0 ) { + result = sign; + } else { + exponent = 1; + while ( ( fraction & 0x0400 ) === 0 ) { + fraction <<= 1; + exponent -= 1; + } + fraction &= ~0x0400; + exp32 = 127 - 15 - exponent; + frac32 = fraction << 13; + result = sign | ( exp32 << 23 ) | frac32; + } + } else if ( exponent === 0x1F ) { + result = sign | 0x7F800000 | ( fraction << 13 ); + } else { + exp32 = exponent - 15 + 127; + result = sign | ( exp32 << 23 ) | ( fraction << 13 ); + } + + intView[ 0 ] = result; + floatView = new Float32Array( intView.buffer ); + return floatView[ 0 ]; +}; -keys() { - return this._keysGenerator(); -} +/** +* Create a new Float16Array from a variable number of arguments. +* +* @returns {Float16Array} New instance +*/ +Float16Array.of = function() { + var len = arguments.length; + var result = new Float16Array( len ); + var i; -*_keysGenerator() { - for (let i = 0; i < this.length; i++) { - yield i; - } -} + for ( i = 0; i < len; i++ ) { + result.set( i, arguments[ i ] ); + } + return result; +}; -lastIndexOf(searchElement, fromIndex) { - let i = fromIndex !== undefined ? fromIndex : this.length - 1; - if (i >= this.length) i = this.length - 1; - if (i < 0) i = this.length + i; - - for (; i >= 0; i--) { - if (Object.is(this.get(i), searchElement)) { - return i; - } - } - return -1; -} +/** +* Create a new Float16Array from an array-like or iterable object. +* +* @param {*} source - Source to convert +* @param {Function} [mapFn] - Optional mapping function +* @param {*} [thisArg] - Execution context for mapFn +* @returns {Float16Array} New instance +*/ +Float16Array.from = function( source, mapFn, thisArg ) { + if ( source == null ) { + throw new TypeError( 'invalid argument. Source cannot be null or undefined. Value: `' + source + '`.' ); + } + if ( typeof mapFn !== 'undefined' && typeof mapFn !== 'function' ) { + throw new TypeError( 'invalid argument. When provided, mapFn must be a function. Value: `' + mapFn + '`.' ); + } + + var values = []; + var i = 0; + var item; + + // Handle iterable (with Symbol.iterator) or array-like + if ( typeof source.length === 'number' ) { + for ( i = 0; i < source.length; i++ ) { + values.push( source[ i ] ); + } + } else if ( typeof source === 'object' && typeof source[ Symbol.iterator ] === 'function' ) { + var iterator = source[ Symbol.iterator ](); + while ( true ) { + var next = iterator.next(); + if ( next.done ) { + break; + } + values.push( next.value ); + } + } else { + throw new TypeError( 'invalid argument. Source must be iterable or array-like. Value: `' + source + '`.' ); + } + + if ( mapFn ) { + for ( i = 0; i < values.length; i++ ) { + values[ i ] = mapFn.call( thisArg, values[ i ], i ); + } + } + + var result = new Float16Array( values.length ); + for ( i = 0; i < values.length; i++ ) { + result.set( i, values[ i ] ); + } + return result; +}; -map(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } +/** +* Get a value at a given index. +* +* @param {NonNegativeInteger} index - Array index +* @returns {number} Float32 value at index +*/ +Float16Array.prototype.get = function( index ) { + return Float16Array.fromFloat16( this._buffer[ index ] ); +}; - const result = new this.constructor(this.length); +/** +* Set a value at a given index, or copy values from an array-like source. +* +* @param {(NonNegativeInteger|ArrayLike)} indexOrArray - Index or source array +* @param {*} [value] - Value to set or offset if copying +* @throws {RangeError} Index or offset out of bounds +* @throws {TypeError} Invalid arguments +*/ +Float16Array.prototype.set = function( indexOrArray, value ) { + var i; + var len; + var offset; + var srcVal; + + if ( typeof indexOrArray === 'number' ) { + if ( indexOrArray < 0 || indexOrArray >= this.length ) { + throw new RangeError( 'invalid argument. Index must be a nonnegative integer less than the array length. Value: `' + indexOrArray + '`.' ); + } + this._buffer[ indexOrArray ] = Float16Array.toFloat16( value ); + return; + } + + offset = ( value !== undefined ) ? Number( value ) : 0; + + if ( offset < 0 || offset > this.length ) { + throw new RangeError( 'invalid argument. Offset must be a nonnegative integer less than or equal to the array length. Value: `' + offset + '`.' ); + } + + if ( + Object.prototype.toString.call( indexOrArray ) === '[object Array]' || + ( typeof indexOrArray === 'object' && typeof indexOrArray.length === 'number' ) + ) { + len = min( indexOrArray.length, this.length - offset ); + for ( i = 0; i < len; i++ ) { + srcVal = ( typeof indexOrArray.get === 'function' ) ? indexOrArray.get( i ) : indexOrArray[ i ]; + this._buffer[ offset + i ] = Float16Array.toFloat16( srcVal ); + } + return; + } + + throw new TypeError( 'invalid argument. Must provide index and value or source and offset. Value: `' + indexOrArray + '`.' ); +}; - for (let i = 0; i < this.length; i++) { - if (Object.prototype.hasOwnProperty.call(this, i)) { - const mappedValue = callback.call(thisArg, this.get(i), i, this); - result.set(i, mappedValue); - } - } +/** +* Copy a sequence of array elements within the array. +* +* @param {integer} target - Target index +* @param {integer} start - Start index +* @param {integer} [end] - End index (exclusive) +* @returns {Float16Array} Modified array +*/ +Float16Array.prototype.copyWithin = function( target, start, end ) { + var to = ( target < 0 ) ? this.length + target : target; + var from = ( start < 0 ) ? this.length + start : start; + var final = ( typeof end === 'undefined' ) ? this.length : ( end < 0 ? this.length + end : end ); + var count = min( final - from, this.length - to ); + var i; + + if ( from < to && to < ( from + count ) ) { + for ( i = count - 1; i >= 0; i-- ) { + this._buffer[ to + i ] = this._buffer[ from + i ]; + } + } else { + for ( i = 0; i < count; i++ ) { + this._buffer[ to + i ] = this._buffer[ from + i ]; + } + } + return this; +}; - return result; -} +/** +* Returns a shallow copy of a portion of the array. +* +* @param {integer} [start=0] - Start index +* @param {integer} [end=array.length] - End index (exclusive) +* @returns {Float16Array} New subarray +*/ +Float16Array.prototype.slice = function( start, end ) { + var len = this.length; + var i; + var count; + var relativeStart; + var relativeEnd; + var result; + + relativeStart = ( typeof start === 'undefined' ) ? 0 : ( start < 0 ? max( len + start, 0 ) : min( start, len ) ); + relativeEnd = ( typeof end === 'undefined' ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); + + count = max( relativeEnd - relativeStart, 0 ); + result = new Float16Array( count ); + + for ( i = 0; i < count; i++ ) { + result.set( i, this.get( relativeStart + i ) ); + } + return result; +}; -slice(start = 0, end = this.length) { - const len = this.length; +/** +* Fill the array with a static value. +* +* @param {*} value - Value to fill +* @param {integer} [start=0] - Start index +* @param {integer} [end=array.length] - End index +* @returns {Float16Array} Modified array +*/ +Float16Array.prototype.fill = function( value, start, end ) { + var i; + var bits; + var s; + var e; + + s = ( typeof start === 'undefined' ) ? 0 : ( start < 0 ? max( this.length + start, 0 ) : min( start, this.length ) ); + e = ( typeof end === 'undefined' ) ? this.length : ( end < 0 ? max( this.length + end, 0 ) : min( end, this.length ) ); + + bits = Float16Array.toFloat16( value ); + + for ( i = s; i < e; i++ ) { + this._buffer[ i ] = bits; + Object.defineProperty( this, i, { + get: (function( index ) { + return function() { + return this.get( index ); + }; + })( i ), + set: (function( index ) { + return function( val ) { + this.set( index, val ); + }; + })( i ), + enumerable: true, + configurable: true + }); + } + return this; +}; - let relativeStart = start < 0 ? Math.max(len + start, 0) : Math.min(start, len); - let relativeEnd = end < 0 ? Math.max(len + end, 0) : Math.min(end, len); +/** +* Returns a new Float16Array view on the same buffer, for the specified range. +* +* @param {integer} [begin=0] - Start index +* @param {integer} [end=this.length] - End index +* @returns {Float16Array} New Float16Array +*/ +Float16Array.prototype.subarray = function( begin, end ) { + var len = this.length; + var i; + var start = ( typeof begin === 'undefined' ) ? 0 : ( begin < 0 ? max( len + begin, 0 ) : min( begin, len ) ); + var finish = ( typeof end === 'undefined' ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); + var count = max( finish - start, 0 ); + var result = new Float16Array( count ); + + for ( i = 0; i < count; i++ ) { + result.set( i, this.get( start + i ) ); + } + return result; +}; - const count = Math.max(relativeEnd - relativeStart, 0); - const result = new this.constructor(count); +/** +* Reverse the array in place. +* +* @returns {Float16Array} Modified array +*/ +Float16Array.prototype.reverse = function() { + var i; + var j; + var tmp; + var mid = floor( this.length / 2 ); + for ( i = 0; i < mid; i++ ) { + j = this.length - 1 - i; + tmp = this._buffer[ i ]; + this._buffer[ i ] = this._buffer[ j ]; + this._buffer[ j ] = tmp; + } + return this; +}; - for (let i = 0; i < count; i++) { - result.set(i, this.get(relativeStart + i)); - } - return result; -} +/** +* Sort the array in place. +* +* @param {Function} [compareFn] - Optional comparison function +* @returns {Float16Array} Sorted array +*/ +Float16Array.prototype.sort = function( compareFn ) { + var values = []; + var i; + var j; + + for ( i = 0; i < this.length; i++ ) { + values.push( this.get( i ) ); + } + + values.sort( function( a, b ) { + if ( compareFn ) { + return compareFn( a, b ); + } + if ( a !== a ) { + return 1; + } + if ( b !== b ) { + return -1; + } + return a - b; + }); + + for ( j = 0; j < this.length; j++ ) { + this.set( j, values[ j ] ); + } + return this; +}; -sort(compareFn) { - const values = []; - for (let i = 0; i < this.length; i++) { - values.push(this.get(i)); - } - - values.sort((a, b) => { - if (compareFn) return compareFn(a, b); - if (a !== a) return 1; - if (b !== b) return -1; - return a - b; - }); - - for (let i = 0; i < this.length; i++) { - this.set(i, values[i]); - } - return this; -} +/** +* Apply a function to each element and return a new Float16Array. +* +* @param {Function} callback - Mapping function +* @param {*} [thisArg] - Context for callback +* @returns {Float16Array} Mapped array +*/ +Float16Array.prototype.map = function( callback, thisArg ) { + var result = new Float16Array( this.length ); + var i; + var val; + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + for ( i = 0; i < this.length; i++ ) { + val = callback.call( thisArg, this.get( i ), i, this ); + result.set( i, val ); + } + return result; +}; -values() { - return this._valuesGenerator(); -} +/** +* Execute a function for each element of the array. +* +* @param {Function} callback - Function to invoke +* @param {*} [thisArg] - Context for callback +*/ +Float16Array.prototype.forEach = function( callback, thisArg ) { + var i; + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + for ( i = 0; i < this.length; i++ ) { + callback.call( thisArg, this.get( i ), i, this ); + } +}; -*_valuesGenerator() { - for (let i = 0; i < this.length; i++) { - yield this.get(i); - } -} +/** +* Reduce the array to a single value (left-to-right). +* +* @param {Function} callback - Reducer function +* @param {*} [initialValue] - Initial value +* @returns {*} Accumulated result +*/ +Float16Array.prototype.reduce = function( callback, initialValue ) { + var i; + var acc; + var len; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + len = this.length; + if ( arguments.length >= 2 ) { + acc = initialValue; + i = 0; + } else { + if ( len === 0 ) { + throw new TypeError( 'invalid operation. Reduce of empty array with no initial value.' ); + } + acc = this.get( 0 ); + i = 1; + } + for ( ; i < len; i++ ) { + acc = callback( acc, this.get( i ), i, this ); + } + return acc; +}; -some(callback, thisArg) { - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - for (let i = 0; i < this.length; i++) { - const value = this.get(i); - if (callback.call(thisArg, value, i, this)) { - return true; - } - } - return false; -} +/** +* Reduce the array to a single value (right-to-left). +* +* @param {Function} callback - Reducer function +* @param {*} [initialValue] - Initial value +* @returns {*} Accumulated result +*/ +Float16Array.prototype.reduceRight = function( callback, initialValue ) { + var i; + var acc; + var len; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + len = this.length; + if ( arguments.length >= 2 ) { + acc = initialValue; + i = len - 1; + } else { + if ( len === 0 ) { + throw new TypeError( 'invalid operation. Reduce of empty array with no initial value.' ); + } + acc = this.get( len - 1 ); + i = len - 2; + } + for ( ; i >= 0; i-- ) { + acc = callback( acc, this.get( i ), i, this ); + } + return acc; +}; -reduce(callback, initialValue) { - const length = this.length; - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - - let accumulator; - let startIndex = 0; - - if (arguments.length >= 2) { - accumulator = initialValue; - } else { - if (length === 0) { - throw new TypeError('Reduce of empty array with no initial value'); - } - accumulator = this.get(0); - startIndex = 1; - } - - for (let i = startIndex; i < length; i++) { - accumulator = callback(accumulator, this.get(i), i, this); - } - - return accumulator; -} +/** +* Test whether at least one element passes the test. +* +* @param {Function} callback - Predicate function +* @param {*} [thisArg] - Context +* @returns {boolean} Whether at least one passes +*/ +Float16Array.prototype.some = function( callback, thisArg ) { + var i; + var value; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return true; + } + } + return false; +}; -reduceRight(callback, initialValue) { - const length = this.length; - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - - let accumulator; - let startIndex = length - 1; - - if (arguments.length >= 2) { - accumulator = initialValue; - } else { - if (length === 0) { - throw new TypeError('Reduce of empty array with no initial value'); - } - accumulator = this.get(startIndex); - startIndex--; - } - - for (let i = startIndex; i >= 0; i--) { - accumulator = callback(accumulator, this.get(i), i, this); - } - - return accumulator; -} +/** +* Test whether all elements pass the test. +* +* @param {Function} callback - Predicate function +* @param {*} [thisArg] - Context +* @returns {boolean} Whether all pass +*/ +Float16Array.prototype.every = function( callback, thisArg ) { + var i; + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); + } + for ( i = 0; i < this.length; i++ ) { + if ( !callback.call( thisArg, this.get( i ), i, this ) ) { + return false; + } + } + return true; +}; -subarray(begin = 0, end = this.length) { - const len = this.length; +/** +* Returns the first index at which a given element can be found in the array, or -1 if it is not present. +* +* @param {*} searchElement - Element to locate +* @param {integer} [fromIndex=0] - Index to start the search at +* @returns {integer} Index of the element, or -1 if not found +*/ +Float16Array.prototype.indexOf = function( searchElement, fromIndex ) { + var i; + var start; - let start = begin < 0 ? Math.max(len + begin, 0) : Math.min(begin, len); - let finish = end < 0 ? Math.max(len + end, 0) : Math.min(end, len); + start = ( typeof fromIndex === 'undefined' ) ? 0 : fromIndex; - start = Math.min(start, len); - finish = Math.min(Math.max(finish, start), len); + if ( start < 0 ) { + start = max( this.length + start, 0 ); + } - const count = Math.max(finish - start, 0); - const SubArrayCtor = this.constructor; + for ( i = start; i < this.length; i++ ) { + if ( this.get( i ) === searchElement ) { + return i; + } + } + return -1; +}; - const result = new SubArrayCtor(count); +/** +* Returns the last index at which a given element can be found in the array, or -1 if it is not present. +* +* @param {*} searchElement - Element to locate +* @param {integer} [fromIndex=this.length-1] - Index to start the search backwards from +* @returns {integer} Last index of the element, or -1 if not found +*/ +Float16Array.prototype.lastIndexOf = function( searchElement, fromIndex ) { + var i = ( typeof fromIndex !== 'undefined' ) ? fromIndex : this.length - 1; + + if ( i >= this.length ) { + i = this.length - 1; + } + if ( i < 0 ) { + i = this.length + i; + } + + for ( ; i >= 0; i-- ) { + if ( Object.is( this.get( i ), searchElement ) ) { + return i; + } + } + return -1; +}; - for (let i = 0; i < count; i++) { - result.set(i, this.get(start + i)); - } - return result; -} +/** +* Joins all elements of the Float16Array into a string, separated by a specified separator. +* +* @param {string} [separator=','] - Separator to insert between values +* @returns {string} Joined string +*/ +Float16Array.prototype.join = function( separator ) { + var result = ''; + var i; -reverse() { - const mid = Math.floor(this.length / 2); - for (let i = 0; i < mid; i++) { - const j = this.length - 1 - i; + separator = ( typeof separator === 'undefined' ) ? ',' : String( separator ); - const temp = this._buffer[i]; - this._buffer[i] = this._buffer[j]; - this._buffer[j] = temp; - } - return this; -} + for ( i = 0; i < this.length; i++ ) { + if ( i > 0 ) { + result += separator; + } + result += String( this.get( i ) ); + } + return result; +}; - fill(value, start = 0, end = this.length) { - start = start < 0 ? Math.max(this.length + start, 0) : Math.min(start, this.length); - end = end < 0 ? Math.max(this.length + end, 0) : Math.min(end, this.length); +/** +* Determines whether the array includes a certain value among its entries. +* +* @param {*} searchElement - Element to search for +* @param {integer} [fromIndex=0] - Index to start the search at +* @returns {boolean} True if the value is found, false otherwise +*/ +Float16Array.prototype.includes = function( searchElement, fromIndex ) { + var i; + var start = ( typeof fromIndex === 'undefined' ) ? 0 : fromIndex; + + if ( start < 0 ) { + start = max( this.length + start, 0 ); + } + + for ( i = start; i < this.length; i++ ) { + if ( this.get( i ) === searchElement ) { + return true; + } + } + return false; +}; - const bits = Float16Array.toFloat16(value); +/** +* Creates a new Float16Array with all elements that pass the test implemented by the provided function. +* +* @param {Function} callback - Function to test each element +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {Float16Array} New Float16Array with filtered elements +*/ +Float16Array.prototype.filter = function( callback, thisArg ) { + var i; + var value; + var result; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); + } + + result = []; + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + result.push( value ); + } + } + return new Float16Array( result ); +}; - for (let i = start; i < end; i++) { - this._buffer[i] = bits; +/** +* Returns the value of the first element that satisfies the provided testing function. +* +* @param {Function} callback - Function to execute on each value +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {*} First matching element, or undefined if no match +*/ +Float16Array.prototype.find = function( callback, thisArg ) { + var i; + var value; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); + } + + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return value; + } + } + return void 0; // returns undefined +}; - Object.defineProperty(this, i, { - get: () => this.get(i), - set: (val) => this.set(i, val), - enumerable: true, - configurable: true - }); - } - return this; -} +/** +* Returns the index of the first element that satisfies the provided testing function. +* +* @param {Function} callback - Function to execute on each value +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {integer} Index of found element, or -1 if none found +*/ +Float16Array.prototype.findIndex = function( callback, thisArg ) { + var i; + var value; + + if ( typeof callback !== 'function' ) { + throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); + } + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return i; + } + } + return -1; +}; - static of(...args) { - const arr = new Float16Array(args.length); - for (let i = 0; i < args.length; i++) { - arr.set(i, args[i]); - } - return arr; -} +/** +* Return an iterator over [index, value] pairs. +* +* @returns {Object} Iterator +*/ +Float16Array.prototype.entries = function() { + var self = this; + var i = 0; + + return { + next: function() { + if ( i < self.length ) { + var v = [ i, self.get( i ) ]; + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + }; +}; - static toFloat16(val) { - const floatView = new Float32Array(1); - const intView = new Uint32Array(floatView.buffer); - - floatView[0] = val; - const x = intView[0]; - - const sign = (x >> 16) & 0x8000; - const exponent = ((x >> 23) & 0xff) - 127; - const fraction = x & 0x7fffff; - - if (exponent <= -15) { - if (exponent < -24) return sign; - const sub = (fraction | 0x800000) >> (-exponent - 1); - return sign | (sub >> 13); - } - - if (exponent >= 16) { - return sign | 0x7c00; - } - - const exp = exponent + 15; - const frac = fraction >> 13; - return sign | (exp << 10) | frac; - } - - static fromFloat16(bits) { - const sign = (bits & 0x8000) << 16; - let exponent = (bits & 0x7C00) >> 10; - const fraction = bits & 0x03FF; - - let result; - if (exponent === 0) { - if (fraction === 0) { - result = sign; - } else { - exponent = 1; - while ((fraction & 0x0400) === 0) { - fraction <<= 1; - exponent--; - } - fraction &= ~0x0400; - const exp32 = 127 - 15 - exponent; - const frac32 = fraction << 13; - result = sign | (exp32 << 23) | frac32; - } - } else if (exponent === 0x1F) { - result = sign | 0x7F800000 | (fraction << 13); - } else { - const exp32 = exponent - 15 + 127; - result = sign | (exp32 << 23) | (fraction << 13); - } - - const intView = new Uint32Array(1); - intView[0] = result; - const floatView = new Float32Array(intView.buffer); - return floatView[0]; - } -} +/** +* Return an iterator over indices. +* +* @returns {Object} Iterator +*/ +Float16Array.prototype.keys = function() { + var self = this; + var i = 0; + + return { + next: function() { + if ( i < self.length ) { + var v = i; + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + }; +}; +/** +* Return an iterator over values. +* +* @returns {Object} Iterator +*/ +Float16Array.prototype.values = function() { + var self = this; + var i = 0; + + return { + next: function() { + if ( i < self.length ) { + var v = self.get( i ); + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + }; +}; // EXPORTS // From 12e481429a4eecdd77d8ddb69c3c0af4d5dfea91 Mon Sep 17 00:00:00 2001 From: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> Date: Mon, 30 Jun 2025 01:33:46 +0530 Subject: [PATCH 4/5] Refactored polyfill.js Signed-off-by: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> --- .../@stdlib/array/float16/lib/polyfill.js | 1485 +++++++++-------- 1 file changed, 813 insertions(+), 672 deletions(-) diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js index f35849f885cb..47d8e126927d 100644 --- a/lib/node_modules/@stdlib/array/float16/lib/polyfill.js +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js @@ -20,9 +20,17 @@ // MODULES // +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var floor = require( '@stdlib/math/base/special/floor' ); var min = require( '@stdlib/math/base/special/min' ); var max = require( '@stdlib/math/base/special/max' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var isArray = require( '@stdlib/assert/is-array' ); +var format = require( '@stdlib/string/format' ); // MAIN // @@ -37,35 +45,50 @@ var floor = require( '@stdlib/math/base/special/floor' ); * @throws {TypeError} Must provide valid input */ function Float16Array( input, byteOffset, length ) { - var i; - var len; - var offset; - - byteOffset = byteOffset || 0; - - if ( typeof input === 'number' ) { - this._buffer = new Uint16Array( input ); - } else if ( input instanceof ArrayBuffer ) { - offset = byteOffset >>> 0; - len = ( typeof length !== 'undefined' ) ? ( length >>> 0 ) : ( ( input.byteLength - offset) / 2 ); - this._buffer = new Uint16Array( input, offset, len ); - } else if (Object.prototype.toString.call( input ) === '[object Array]' ) { - this._buffer = new Uint16Array( input.length ); - for (i = 0; i < input.length; i++) { - this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); - } - } else if ( typeof input === 'object' && typeof input.length === 'number' ) { - this._buffer = new Uint16Array( input.length ); - for ( i = 0; i < input.length; i++ ) { - this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); - } - } else { - throw new TypeError( 'Invalid argument. Must provide a number, Array, ArrayBuffer, or typed array. Value: ' + input + '.' ); - } - - this.length = this._buffer.length; + var i; + var len; + var offset; + + byteOffset = byteOffset || 0; + + if ( isNonNegativeInteger( input ) ) { + this._buffer = new Uint16Array( input ); + } else if ( input instanceof ArrayBuffer ) { + offset = Number( byteOffset ); + if ( !isNonNegativeInteger( offset ) ) { + throw new RangeError( format( 'invalid argument. Byte offset must be a non-negative integer. Value: `%s`.', byteOffset ) ); + } + + if ( length !== void 0 ) { + if ( !isNonNegativeInteger( length ) ) { + throw new RangeError( format( 'invalid argument. Length must be a non-negative integer. Value: `%s`.', length ) ); + } + len = length; + } else { + len = ( input.byteLength - offset ) / 2; + } + + this._buffer = new Uint16Array( input, offset, len ); + } else if ( isArray( input ) ) { + this._buffer = new Uint16Array( input.length ); + for ( i = 0; i < input.length; i++ ) { + this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); + } + } else if ( isCollection( input ) ) { + this._buffer = new Uint16Array( input.length ); + for ( i = 0; i < input.length; i++ ) { + this._buffer[ i ] = Float16Array.toFloat16( input[ i ] ); + } + } else { + throw new TypeError( format( 'invalid argument. Must provide a number, Array, ArrayBuffer, or typed array. Value: `%s`.', input ) ); + } + + this.length = this._buffer.length; } +setReadOnly( Float16Array, 'name', 'Float16Array' ); +setReadOnly( Float16Array, 'BYTES_PER_ELEMENT', 2 ); + /** * Get the underlying `ArrayBuffer`. * @@ -74,11 +97,10 @@ function Float16Array( input, byteOffset, length ) { * @readonly * @type {ArrayBuffer} */ -Object.defineProperty( Float16Array.prototype, 'buffer', { - get: function() { - return this._buffer.buffer; - } -}); +function getBuffer() { + return this._buffer.buffer; +} +setReadOnlyAccessor( Float16Array.prototype, 'buffer', getBuffer ); /** * Get the total number of bytes in the `Float16Array`. @@ -88,11 +110,10 @@ Object.defineProperty( Float16Array.prototype, 'buffer', { * @readonly * @type {NonNegativeInteger} */ -Object.defineProperty( Float16Array.prototype, 'byteLength', { - get: function() { - return this._buffer.byteLength; - } -}); +function getByteLength() { + return this._buffer.byteLength; +} +setReadOnlyAccessor( Float16Array.prototype, 'byteLength', getByteLength ); /** * Get the byte offset within the underlying `ArrayBuffer`. @@ -102,11 +123,10 @@ Object.defineProperty( Float16Array.prototype, 'byteLength', { * @readonly * @type {NonNegativeInteger} */ -Object.defineProperty( Float16Array.prototype, 'byteOffset', { - get: function() { - return this._buffer.byteOffset; - } -}); +function getByteOffset() { + return this._buffer.byteOffset; +} +setReadOnlyAccessor( Float16Array.prototype, 'byteOffset', getByteOffset ); /** * Size in bytes of each element. @@ -116,11 +136,10 @@ Object.defineProperty( Float16Array.prototype, 'byteOffset', { * @readonly * @type {PositiveInteger} */ -Object.defineProperty( Float16Array.prototype, 'BYTES_PER_ELEMENT', { - get: function() { - return 2; - } -}); +function getBytesPerElement() { + return 2; +} +setReadOnlyAccessor( Float16Array.prototype, 'BYTES_PER_ELEMENT', getBytesPerElement ); /** * Returns the default string tag. @@ -130,745 +149,854 @@ Object.defineProperty( Float16Array.prototype, 'BYTES_PER_ELEMENT', { * @readonly * @type {string} */ -Object.defineProperty( Float16Array.prototype, ( typeof Symbol !== 'undefined' && Symbol.toStringTag ) || '__toStringTag__', { - get: function() { - return 'Float16Array'; - } -}); +var symbolToStringTag = ( typeof Symbol !== 'undefined' && Symbol.toStringTag ) || '__toStringTag__'; + +function getToStringTag() { + return 'Float16Array'; +} +setReadOnlyAccessor( Float16Array.prototype, symbolToStringTag, getToStringTag ); /** -* Converts a float32 number to a float16 (binary) representation. +* Copy a sequence of array elements within the array. * -* @param {number} val - Float32 value -* @returns {integer} Float16 bit pattern +* @param {integer} target - Target index +* @param {integer} start - Start index +* @param {integer} [end] - End index (exclusive) +* @throws {TypeError} If any index is not an integer +* @throws {RangeError} If any index is out of bounds +* @returns {Float16Array} Modified array */ -Float16Array.toFloat16 = function( val ) { - var floatView = new Float32Array( 1 ); - var intView = new Uint32Array( floatView.buffer ); - var sign; - var exponent; - var fraction; - var exp; - var frac; - - floatView[ 0 ] = val; - var x = intView[ 0 ]; - - sign = ( x >> 16 ) & 0x8000; - exponent = ( ( x >> 23 ) & 0xff ) - 127; - fraction = x & 0x7fffff; - - if ( exponent <= -15 ) { - if ( exponent < -24 ) { - return sign; - } - return sign | ( ( ( fraction | 0x800000 ) >> ( -exponent - 1 ) ) >> 13 ); - } - - if ( exponent >= 16 ) { - return sign | 0x7c00; - } - - exp = exponent + 15; - frac = fraction >> 13; - return sign | ( exp << 10 ) | frac; +Float16Array.prototype.copyWithin = function( target, start, end ) { + var to; + var from; + var final; + var count; + var i; + + if ( !isInteger( target ) ) { + throw new TypeError( format( 'invalid argument. Target index must be an integer. Value: `%s`.', target ) ); + } + if ( !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Start index must be an integer. Value: `%s`.', start ) ); + } + if ( end !== void 0 && !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. End index must be an integer when provided. Value: `%s`.', end ) ); + } + + to = ( target < 0 ) ? this.length + target : target; + from = ( start < 0 ) ? this.length + start : start; + final = ( end === void 0 ) ? this.length : ( end < 0 ? this.length + end : end ); + + if ( to < 0 || to > this.length ) { + throw new RangeError( format( 'invalid argument. Target index is out of bounds. Value: `%s`.', target ) ); + } + if ( from < 0 || from > this.length ) { + throw new RangeError( format( 'invalid argument. Start index is out of bounds. Value: `%s`.', start ) ); + } + if ( final < 0 || final > this.length ) { + throw new RangeError( format( 'invalid argument. End index is out of bounds. Value: `%s`.', end ) ); + } + + count = min( final - from, this.length - to ); + + if ( from < to && to < ( from + count ) ) { + for ( i = count - 1; i >= 0; i-- ) { + this._buffer[ to + i ] = this._buffer[ from + i ]; + } + } else { + for ( i = 0; i < count; i++ ) { + this._buffer[ to + i ] = this._buffer[ from + i ]; + } + } + return this; }; /** -* Converts a float16 binary representation to float32. +* Return an iterator over [index, value] pairs. * -* @param {integer} bits - Float16 bit pattern -* @returns {number} Float32 value +* @returns {Object} Iterator */ -Float16Array.fromFloat16 = function( bits ) { - var sign = ( bits & 0x8000 ) << 16; - var exponent = ( bits & 0x7C00 ) >> 10; - var fraction = bits & 0x03FF; - var intView = new Uint32Array( 1 ); - var floatView; - var result; - var exp32; - var frac32; - - if ( exponent === 0 ) { - if ( fraction === 0 ) { - result = sign; - } else { - exponent = 1; - while ( ( fraction & 0x0400 ) === 0 ) { - fraction <<= 1; - exponent -= 1; - } - fraction &= ~0x0400; - exp32 = 127 - 15 - exponent; - frac32 = fraction << 13; - result = sign | ( exp32 << 23 ) | frac32; - } - } else if ( exponent === 0x1F ) { - result = sign | 0x7F800000 | ( fraction << 13 ); - } else { - exp32 = exponent - 15 + 127; - result = sign | ( exp32 << 23 ) | ( fraction << 13 ); - } - - intView[ 0 ] = result; - floatView = new Float32Array( intView.buffer ); - return floatView[ 0 ]; +Float16Array.prototype.entries = function() { + var self = this; + var i = 0; + + function nextEntries() { + if ( i < self.length ) { + var v = [ i, self.get( i ) ]; + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + + function getEntriesIterator() { + return iterator; + } + + var iterator = { + next: nextEntries + }; + + if ( typeof Symbol === 'function' && Symbol.iterator ) { + iterator[ Symbol.iterator ] = getEntriesIterator; + } + + return iterator; }; /** -* Create a new Float16Array from a variable number of arguments. +* Test whether all elements pass the test. * -* @returns {Float16Array} New instance +* @param {Function} callback - Predicate function +* @param {*} [thisArg] - Context +* @returns {boolean} Whether all pass */ -Float16Array.of = function() { - var len = arguments.length; - var result = new Float16Array( len ); - var i; - - for ( i = 0; i < len; i++ ) { - result.set( i, arguments[ i ] ); - } - return result; +Float16Array.prototype.every = function( callback, thisArg ) { + var i; + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + for ( i = 0; i < this.length; i++ ) { + if ( !callback.call( thisArg, this.get( i ), i, this ) ) { + return false; + } + } + return true; }; /** -* Create a new Float16Array from an array-like or iterable object. +* Fill the array with a static value. * -* @param {*} source - Source to convert -* @param {Function} [mapFn] - Optional mapping function -* @param {*} [thisArg] - Execution context for mapFn -* @returns {Float16Array} New instance +* @param {*} value - Value to fill +* @param {integer} [start=0] - Start index +* @param {integer} [end=array.length] - End index +* @throws {TypeError} If start or end are not integers +* @returns {Float16Array} Modified array */ -Float16Array.from = function( source, mapFn, thisArg ) { - if ( source == null ) { - throw new TypeError( 'invalid argument. Source cannot be null or undefined. Value: `' + source + '`.' ); - } - if ( typeof mapFn !== 'undefined' && typeof mapFn !== 'function' ) { - throw new TypeError( 'invalid argument. When provided, mapFn must be a function. Value: `' + mapFn + '`.' ); - } - - var values = []; - var i = 0; - var item; - - // Handle iterable (with Symbol.iterator) or array-like - if ( typeof source.length === 'number' ) { - for ( i = 0; i < source.length; i++ ) { - values.push( source[ i ] ); - } - } else if ( typeof source === 'object' && typeof source[ Symbol.iterator ] === 'function' ) { - var iterator = source[ Symbol.iterator ](); - while ( true ) { - var next = iterator.next(); - if ( next.done ) { - break; - } - values.push( next.value ); - } - } else { - throw new TypeError( 'invalid argument. Source must be iterable or array-like. Value: `' + source + '`.' ); - } - - if ( mapFn ) { - for ( i = 0; i < values.length; i++ ) { - values[ i ] = mapFn.call( thisArg, values[ i ], i ); - } - } - - var result = new Float16Array( values.length ); - for ( i = 0; i < values.length; i++ ) { - result.set( i, values[ i ] ); - } - return result; +function createFloat16Getter( index ) { + return function getFloat16Index() { + return this.get( index ); + }; +} + +function createFloat16Setter( index ) { + return function setFloat16Index( val ) { + this.set( index, val ); + }; +} +Float16Array.prototype.fill = function( value, start, end ) { + var i; + var bits; + var s; + var e; + + if ( start !== void 0 && !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Start index must be an integer. Value: `%s`.', start ) ); + } + if ( end !== void 0 && !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. End index must be an integer. Value: `%s`.', end ) ); + } + + s = ( start === void 0 ) ? 0 : ( start < 0 ? max( this.length + start, 0 ) : min( start, this.length ) ); + e = ( end === void 0 ) ? this.length : ( end < 0 ? max( this.length + end, 0 ) : min( end, this.length ) ); + + bits = Float16Array.toFloat16( value ); + + for ( i = s; i < e; i++ ) { + this._buffer[ i ] = bits; + Object.defineProperty( this, i, { + get: createFloat16Getter( i ), + set: createFloat16Setter( i ), + enumerable: true, + configurable: true + }); + } + return this; }; /** -* Get a value at a given index. +* Creates a new Float16Array with all elements that pass the test implemented by the provided function. * -* @param {NonNegativeInteger} index - Array index -* @returns {number} Float32 value at index +* @param {Function} callback - Function to test each element +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {Float16Array} New Float16Array with filtered elements */ -Float16Array.prototype.get = function( index ) { - return Float16Array.fromFloat16( this._buffer[ index ] ); +Float16Array.prototype.filter = function( callback, thisArg ) { + var i; + var value; + var result; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + + result = []; + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + result.push( value ); + } + } + return new Float16Array( result ); }; /** -* Set a value at a given index, or copy values from an array-like source. +* Returns the value of the first element that satisfies the provided testing function. * -* @param {(NonNegativeInteger|ArrayLike)} indexOrArray - Index or source array -* @param {*} [value] - Value to set or offset if copying -* @throws {RangeError} Index or offset out of bounds -* @throws {TypeError} Invalid arguments +* @param {Function} callback - Function to execute on each value +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {*} First matching element, or undefined if no match */ -Float16Array.prototype.set = function( indexOrArray, value ) { - var i; - var len; - var offset; - var srcVal; - - if ( typeof indexOrArray === 'number' ) { - if ( indexOrArray < 0 || indexOrArray >= this.length ) { - throw new RangeError( 'invalid argument. Index must be a nonnegative integer less than the array length. Value: `' + indexOrArray + '`.' ); - } - this._buffer[ indexOrArray ] = Float16Array.toFloat16( value ); - return; - } - - offset = ( value !== undefined ) ? Number( value ) : 0; - - if ( offset < 0 || offset > this.length ) { - throw new RangeError( 'invalid argument. Offset must be a nonnegative integer less than or equal to the array length. Value: `' + offset + '`.' ); - } - - if ( - Object.prototype.toString.call( indexOrArray ) === '[object Array]' || - ( typeof indexOrArray === 'object' && typeof indexOrArray.length === 'number' ) - ) { - len = min( indexOrArray.length, this.length - offset ); - for ( i = 0; i < len; i++ ) { - srcVal = ( typeof indexOrArray.get === 'function' ) ? indexOrArray.get( i ) : indexOrArray[ i ]; - this._buffer[ offset + i ] = Float16Array.toFloat16( srcVal ); - } - return; - } - - throw new TypeError( 'invalid argument. Must provide index and value or source and offset. Value: `' + indexOrArray + '`.' ); +Float16Array.prototype.find = function( callback, thisArg ) { + var i; + var value; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return value; + } + } + return void 0; }; /** -* Copy a sequence of array elements within the array. +* Returns the index of the first element that satisfies the provided testing function. * -* @param {integer} target - Target index -* @param {integer} start - Start index -* @param {integer} [end] - End index (exclusive) -* @returns {Float16Array} Modified array +* @param {Function} callback - Function to execute on each value +* @param {*} [thisArg] - Value to use as `this` when executing `callback` +* @throws {TypeError} Must provide a function as callback +* @returns {integer} Index of found element, or -1 if none found */ -Float16Array.prototype.copyWithin = function( target, start, end ) { - var to = ( target < 0 ) ? this.length + target : target; - var from = ( start < 0 ) ? this.length + start : start; - var final = ( typeof end === 'undefined' ) ? this.length : ( end < 0 ? this.length + end : end ); - var count = min( final - from, this.length - to ); - var i; - - if ( from < to && to < ( from + count ) ) { - for ( i = count - 1; i >= 0; i-- ) { - this._buffer[ to + i ] = this._buffer[ from + i ]; - } - } else { - for ( i = 0; i < count; i++ ) { - this._buffer[ to + i ] = this._buffer[ from + i ]; - } - } - return this; +Float16Array.prototype.findIndex = function( callback, thisArg ) { + var i; + var value; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return i; + } + } + return -1; }; /** -* Returns a shallow copy of a portion of the array. +* Execute a function for each element of the array. * -* @param {integer} [start=0] - Start index -* @param {integer} [end=array.length] - End index (exclusive) -* @returns {Float16Array} New subarray +* @param {Function} callback - Function to invoke +* @param {*} [thisArg] - Context for callback */ -Float16Array.prototype.slice = function( start, end ) { - var len = this.length; - var i; - var count; - var relativeStart; - var relativeEnd; - var result; - - relativeStart = ( typeof start === 'undefined' ) ? 0 : ( start < 0 ? max( len + start, 0 ) : min( start, len ) ); - relativeEnd = ( typeof end === 'undefined' ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); - - count = max( relativeEnd - relativeStart, 0 ); - result = new Float16Array( count ); - - for ( i = 0; i < count; i++ ) { - result.set( i, this.get( relativeStart + i ) ); - } - return result; +Float16Array.prototype.forEach = function( callback, thisArg ) { + var i; + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + for ( i = 0; i < this.length; i++ ) { + callback.call( thisArg, this.get( i ), i, this ); + } }; /** -* Fill the array with a static value. +* Create a new Float16Array from an array-like or iterable object. * -* @param {*} value - Value to fill -* @param {integer} [start=0] - Start index -* @param {integer} [end=array.length] - End index -* @returns {Float16Array} Modified array +* @param {*} source - Source to convert +* @param {Function} [mapFn] - Optional mapping function +* @param {*} [thisArg] - Execution context for mapFn +* @returns {Float16Array} New instance +* @throws {TypeError} If source is invalid or mapFn is not a function */ -Float16Array.prototype.fill = function( value, start, end ) { - var i; - var bits; - var s; - var e; - - s = ( typeof start === 'undefined' ) ? 0 : ( start < 0 ? max( this.length + start, 0 ) : min( start, this.length ) ); - e = ( typeof end === 'undefined' ) ? this.length : ( end < 0 ? max( this.length + end, 0 ) : min( end, this.length ) ); - - bits = Float16Array.toFloat16( value ); - - for ( i = s; i < e; i++ ) { - this._buffer[ i ] = bits; - Object.defineProperty( this, i, { - get: (function( index ) { - return function() { - return this.get( index ); - }; - })( i ), - set: (function( index ) { - return function( val ) { - this.set( index, val ); - }; - })( i ), - enumerable: true, - configurable: true - }); - } - return this; +Float16Array.from = function( source, mapFn, thisArg ) { + if ( source == null ) { + throw new TypeError( format( 'invalid argument. Source cannot be null or undefined. Value: %s.', source ) ); + } + if ( mapFn !== void 0 && !isFunction( mapFn ) ) { + throw new TypeError( format( 'invalid argument. When provided, mapFn must be a function. Value: %s.', mapFn ) ); + } + + var values = []; + var i = 0; + + if ( typeof source.length === 'number' ) { + for ( i = 0; i < source.length; i++ ) { + values.push( source[ i ] ); + } + } + else if ( typeof source === 'object' && typeof source[ Symbol.iterator ] === 'function' ) { + var iterator = source[ Symbol.iterator ](); + while ( true ) { + var next = iterator.next(); + if ( next.done ) { + break; + } + values.push( next.value ); + } + } else { + throw new TypeError( format( 'invalid argument. Source must be iterable or array-like. Value: %s.', source ) ); + } + + if ( mapFn ) { + for ( i = 0; i < values.length; i++ ) { + values[ i ] = mapFn.call( thisArg, values[ i ], i ); + } + } + + var result = new Float16Array( values.length ); + for ( i = 0; i < values.length; i++ ) { + result.set( i, values[ i ] ); + } + return result; }; /** -* Returns a new Float16Array view on the same buffer, for the specified range. +* Converts a float16 binary representation to float32. * -* @param {integer} [begin=0] - Start index -* @param {integer} [end=this.length] - End index -* @returns {Float16Array} New Float16Array +* @param {integer} bits - Float16 bit pattern +* @throws {TypeError} Must provide a 16-bit unsigned integer +* @returns {number} Float32 value */ -Float16Array.prototype.subarray = function( begin, end ) { - var len = this.length; - var i; - var start = ( typeof begin === 'undefined' ) ? 0 : ( begin < 0 ? max( len + begin, 0 ) : min( begin, len ) ); - var finish = ( typeof end === 'undefined' ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); - var count = max( finish - start, 0 ); - var result = new Float16Array( count ); - - for ( i = 0; i < count; i++ ) { - result.set( i, this.get( start + i ) ); - } - return result; +Float16Array.fromFloat16 = function( bits ) { + var sign; + var exponent; + var fraction; + var intView; + var floatView; + var result; + var exp32; + var frac32; + + if ( !isNonNegativeInteger( bits ) || bits > 0xFFFF ) { + throw new TypeError( format( 'invalid argument. Must provide a 16-bit unsigned integer. Value: `%s`.', bits ) ); + } + + sign = ( bits & 0x8000 ) << 16; + exponent = ( bits & 0x7C00 ) >> 10; + fraction = bits & 0x03FF; + intView = new Uint32Array( 1 ); + + if ( exponent === 0 ) { + if ( fraction === 0 ) { + result = sign; + } else { + exponent = 1; + while ( ( fraction & 0x0400 ) === 0 ) { + fraction <<= 1; + exponent -= 1; + } + fraction &= ~0x0400; + exp32 = 127 - 15 - exponent; + frac32 = fraction << 13; + result = sign | ( exp32 << 23 ) | frac32; + } + } else if ( exponent === 0x1F ) { + result = sign | 0x7F800000 | ( fraction << 13 ); + } else { + exp32 = exponent - 15 + 127; + result = sign | ( exp32 << 23 ) | ( fraction << 13 ); + } + + intView[ 0 ] = result; + floatView = new Float32Array( intView.buffer ); + return floatView[ 0 ]; }; /** -* Reverse the array in place. +* Get a value at a given index. * -* @returns {Float16Array} Modified array +* @param {NonNegativeInteger} index - Array index +* @throws {RangeError} If index is out of bounds +* @returns {number} Float32 value at index */ -Float16Array.prototype.reverse = function() { - var i; - var j; - var tmp; - var mid = floor( this.length / 2 ); - for ( i = 0; i < mid; i++ ) { - j = this.length - 1 - i; - tmp = this._buffer[ i ]; - this._buffer[ i ] = this._buffer[ j ]; - this._buffer[ j ] = tmp; - } - return this; +Float16Array.prototype.get = function( index ) { + if ( !isNonNegativeInteger( index ) || index >= this.length ) { + throw new RangeError( format( 'invalid argument. Index out of bounds. Value: `%s`.', index ) ); + } + return Float16Array.fromFloat16( this._buffer[ index ] ); }; /** -* Sort the array in place. +* Determines whether the array includes a certain value among its entries. * -* @param {Function} [compareFn] - Optional comparison function -* @returns {Float16Array} Sorted array +* @param {*} searchElement - Element to search for +* @param {integer} [fromIndex=0] - Index to start the search at +* @throws {TypeError} If fromIndex is not an integer +* @returns {boolean} True if the value is found, false otherwise */ -Float16Array.prototype.sort = function( compareFn ) { - var values = []; - var i; - var j; - - for ( i = 0; i < this.length; i++ ) { - values.push( this.get( i ) ); - } - - values.sort( function( a, b ) { - if ( compareFn ) { - return compareFn( a, b ); - } - if ( a !== a ) { - return 1; - } - if ( b !== b ) { - return -1; - } - return a - b; - }); - - for ( j = 0; j < this.length; j++ ) { - this.set( j, values[ j ] ); - } - return this; +Float16Array.prototype.includes = function( searchElement, fromIndex ) { + var i; + var start; + + if ( fromIndex !== void 0 && !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. FromIndex must be an integer. Value: `%s`.', fromIndex ) ); + } + + start = ( fromIndex === void 0 ) ? 0 : fromIndex; + if ( start < 0 ) { + start = max( this.length + start, 0 ); + } + + for ( i = start; i < this.length; i++ ) { + if ( this.get( i ) === searchElement ) { + return true; + } + } + return false; }; /** -* Apply a function to each element and return a new Float16Array. +* Returns the first index at which a given element can be found in the array, or -1 if it is not present. * -* @param {Function} callback - Mapping function -* @param {*} [thisArg] - Context for callback -* @returns {Float16Array} Mapped array +* @param {*} searchElement - Element to locate +* @param {integer} [fromIndex=0] - Index to start the search at +* @throws {TypeError} If fromIndex is not an integer +* @returns {integer} Index of the element, or -1 if not found */ -Float16Array.prototype.map = function( callback, thisArg ) { - var result = new Float16Array( this.length ); - var i; - var val; - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - for ( i = 0; i < this.length; i++ ) { - val = callback.call( thisArg, this.get( i ), i, this ); - result.set( i, val ); - } - return result; +Float16Array.prototype.indexOf = function( searchElement, fromIndex ) { + var i; + var start; + + if ( fromIndex !== void 0 && !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. FromIndex must be an integer. Value: `%s`.', fromIndex ) ); + } + + start = ( fromIndex === void 0 ) ? 0 : fromIndex; + if ( start < 0 ) { + start = max( this.length + start, 0 ); + } + + for ( i = start; i < this.length; i++ ) { + if ( this.get( i ) === searchElement ) { + return i; + } + } + return -1; }; /** -* Execute a function for each element of the array. +* Joins all elements of the Float16Array into a string, separated by a specified separator. * -* @param {Function} callback - Function to invoke -* @param {*} [thisArg] - Context for callback +* @param {string} [separator=','] - Separator to insert between values +* @returns {string} Joined string */ -Float16Array.prototype.forEach = function( callback, thisArg ) { - var i; - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - for ( i = 0; i < this.length; i++ ) { - callback.call( thisArg, this.get( i ), i, this ); - } +Float16Array.prototype.join = function( separator ) { + var result = ''; + var i; + + separator = ( typeof separator === 'undefined' ) ? ',' : String( separator ); + + for ( i = 0; i < this.length; i++ ) { + if ( i > 0 ) { + result += separator; + } + result += String( this.get( i ) ); + } + return result; }; /** -* Reduce the array to a single value (left-to-right). +* Return an iterator over indices. * -* @param {Function} callback - Reducer function -* @param {*} [initialValue] - Initial value -* @returns {*} Accumulated result +* @returns {Object} Iterator */ -Float16Array.prototype.reduce = function( callback, initialValue ) { - var i; - var acc; - var len; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - len = this.length; - if ( arguments.length >= 2 ) { - acc = initialValue; - i = 0; - } else { - if ( len === 0 ) { - throw new TypeError( 'invalid operation. Reduce of empty array with no initial value.' ); - } - acc = this.get( 0 ); - i = 1; - } - for ( ; i < len; i++ ) { - acc = callback( acc, this.get( i ), i, this ); - } - return acc; +Float16Array.prototype.keys = function() { + var self = this; + var i = 0; + + function nextKeys() { + if ( i < self.length ) { + var v = i; + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + + function getKeysIterator() { + return iterator; + } + + var iterator = { + next: nextKeys + }; + + if ( typeof Symbol === 'function' && Symbol.iterator ) { + iterator[ Symbol.iterator ] = getKeysIterator; + } + + return iterator; }; /** -* Reduce the array to a single value (right-to-left). +* Returns the last index at which a given element can be found in the array, or -1 if it is not present. * -* @param {Function} callback - Reducer function -* @param {*} [initialValue] - Initial value -* @returns {*} Accumulated result +* @param {*} searchElement - Element to locate +* @param {integer} [fromIndex=this.length-1] - Index to start the search backwards from +* @throws {TypeError} If fromIndex is not an integer +* @returns {integer} Last index of the element, or -1 if not found */ -Float16Array.prototype.reduceRight = function( callback, initialValue ) { - var i; - var acc; - var len; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - len = this.length; - if ( arguments.length >= 2 ) { - acc = initialValue; - i = len - 1; - } else { - if ( len === 0 ) { - throw new TypeError( 'invalid operation. Reduce of empty array with no initial value.' ); - } - acc = this.get( len - 1 ); - i = len - 2; - } - for ( ; i >= 0; i-- ) { - acc = callback( acc, this.get( i ), i, this ); - } - return acc; +Float16Array.prototype.lastIndexOf = function( searchElement, fromIndex ) { + var i; + + if ( fromIndex !== void 0 && !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. FromIndex must be an integer. Value: `%s`.', fromIndex ) ); + } + + i = ( fromIndex !== void 0 ) ? fromIndex : this.length - 1; + + if ( i >= this.length ) { + i = this.length - 1; + } + if ( i < 0 ) { + i = this.length + i; + } + + for ( ; i >= 0; i-- ) { + if ( Object.is( this.get( i ), searchElement ) ) { + return i; + } + } + return -1; }; /** -* Test whether at least one element passes the test. +* Apply a function to each element and return a new Float16Array. * -* @param {Function} callback - Predicate function -* @param {*} [thisArg] - Context -* @returns {boolean} Whether at least one passes +* @param {Function} callback - Mapping function +* @param {*} [thisArg] - Context for callback +* @returns {Float16Array} Mapped array */ -Float16Array.prototype.some = function( callback, thisArg ) { - var i; - var value; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - for ( i = 0; i < this.length; i++ ) { - value = this.get( i ); - if ( callback.call( thisArg, value, i, this ) ) { - return true; - } - } - return false; +Float16Array.prototype.map = function( callback, thisArg ) { + var result = new Float16Array( this.length ); + var i; + var val; + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + for ( i = 0; i < this.length; i++ ) { + val = callback.call( thisArg, this.get( i ), i, this ); + result.set( i, val ); + } + return result; }; /** -* Test whether all elements pass the test. +* Create a new Float16Array from a variable number of arguments. * -* @param {Function} callback - Predicate function -* @param {*} [thisArg] - Context -* @returns {boolean} Whether all pass +* @returns {Float16Array} New instance */ -Float16Array.prototype.every = function( callback, thisArg ) { - var i; - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Callback must be a function. Value: `' + callback + '`.' ); - } - for ( i = 0; i < this.length; i++ ) { - if ( !callback.call( thisArg, this.get( i ), i, this ) ) { - return false; - } - } - return true; +Float16Array.of = function() { + var len = arguments.length; + var result = new Float16Array( len ); + var i; + + for ( i = 0; i < len; i++ ) { + result.set( i, arguments[ i ] ); + } + return result; }; /** -* Returns the first index at which a given element can be found in the array, or -1 if it is not present. +* Reduce the array to a single value (left-to-right). * -* @param {*} searchElement - Element to locate -* @param {integer} [fromIndex=0] - Index to start the search at -* @returns {integer} Index of the element, or -1 if not found +* @param {Function} callback - Reducer function +* @param {*} [initialValue] - Initial value +* @returns {*} Accumulated result */ -Float16Array.prototype.indexOf = function( searchElement, fromIndex ) { - var i; - var start; - - start = ( typeof fromIndex === 'undefined' ) ? 0 : fromIndex; - - if ( start < 0 ) { - start = max( this.length + start, 0 ); - } - - for ( i = start; i < this.length; i++ ) { - if ( this.get( i ) === searchElement ) { - return i; - } - } - return -1; +Float16Array.prototype.reduce = function( callback, initialValue ) { + var i; + var acc; + var len; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + len = this.length; + if ( arguments.length >= 2 ) { + acc = initialValue; + i = 0; + } else { + if ( len === 0 ) { + throw new TypeError( format( 'invalid operation. Reduce of empty array with no initial value.' ) ); + } + acc = this.get( 0 ); + i = 1; + } + for ( ; i < len; i++ ) { + acc = callback( acc, this.get( i ), i, this ); + } + return acc; }; /** -* Returns the last index at which a given element can be found in the array, or -1 if it is not present. +* Reduce the array to a single value (right-to-left). * -* @param {*} searchElement - Element to locate -* @param {integer} [fromIndex=this.length-1] - Index to start the search backwards from -* @returns {integer} Last index of the element, or -1 if not found +* @param {Function} callback - Reducer function +* @param {*} [initialValue] - Initial value +* @returns {*} Accumulated result */ -Float16Array.prototype.lastIndexOf = function( searchElement, fromIndex ) { - var i = ( typeof fromIndex !== 'undefined' ) ? fromIndex : this.length - 1; - - if ( i >= this.length ) { - i = this.length - 1; - } - if ( i < 0 ) { - i = this.length + i; - } - - for ( ; i >= 0; i-- ) { - if ( Object.is( this.get( i ), searchElement ) ) { - return i; - } - } - return -1; +Float16Array.prototype.reduceRight = function( callback, initialValue ) { + var i; + var acc; + var len; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + len = this.length; + if ( arguments.length >= 2 ) { + acc = initialValue; + i = len - 1; + } else { + if ( len === 0 ) { + throw new TypeError( format( 'invalid operation. Reduce of empty array with no initial value.' ) ); + } + acc = this.get( len - 1 ); + i = len - 2; + } + for ( ; i >= 0; i-- ) { + acc = callback( acc, this.get( i ), i, this ); + } + return acc; }; /** -* Joins all elements of the Float16Array into a string, separated by a specified separator. +* Reverse the array in place. * -* @param {string} [separator=','] - Separator to insert between values -* @returns {string} Joined string +* @returns {Float16Array} Modified array */ -Float16Array.prototype.join = function( separator ) { - var result = ''; - var i; - - separator = ( typeof separator === 'undefined' ) ? ',' : String( separator ); - - for ( i = 0; i < this.length; i++ ) { - if ( i > 0 ) { - result += separator; - } - result += String( this.get( i ) ); - } - return result; +Float16Array.prototype.reverse = function() { + var i; + var j; + var tmp; + var mid = floor( this.length / 2 ); + for ( i = 0; i < mid; i++ ) { + j = this.length - 1 - i; + tmp = this._buffer[ i ]; + this._buffer[ i ] = this._buffer[ j ]; + this._buffer[ j ] = tmp; + } + return this; }; /** -* Determines whether the array includes a certain value among its entries. +* Set a value at a given index, or copy values from an array-like source. * -* @param {*} searchElement - Element to search for -* @param {integer} [fromIndex=0] - Index to start the search at -* @returns {boolean} True if the value is found, false otherwise +* @param {(NonNegativeInteger|ArrayLike)} indexOrArray - Index or source array +* @param {*} [value] - Value to set or offset if copying +* @throws {RangeError} Index or offset out of bounds +* @throws {TypeError} Invalid arguments */ -Float16Array.prototype.includes = function( searchElement, fromIndex ) { - var i; - var start = ( typeof fromIndex === 'undefined' ) ? 0 : fromIndex; - - if ( start < 0 ) { - start = max( this.length + start, 0 ); - } - - for ( i = start; i < this.length; i++ ) { - if ( this.get( i ) === searchElement ) { - return true; - } - } - return false; +Float16Array.prototype.set = function( indexOrArray, value ) { + var i; + var len; + var offset; + var srcVal; + + if ( isNonNegativeInteger( indexOrArray ) ) { + if ( indexOrArray >= this.length ) { + throw new RangeError( format( 'invalid argument. Index must be a nonnegative integer less than the array length. Value: `%s`.', indexOrArray ) ); + } + this._buffer[ indexOrArray ] = Float16Array.toFloat16( value ); + return; + } + + offset = ( value !== void 0 ) ? Number( value ) : 0; + if ( !isNonNegativeInteger( offset ) || offset > this.length ) { + throw new RangeError( format( 'invalid argument. Offset must be a nonnegative integer less than or equal to the array length. Value: `%s`.', offset ) ); + } + + if ( isArray( indexOrArray ) || isCollection( indexOrArray ) ) { + len = min( indexOrArray.length, this.length - offset ); + for ( i = 0; i < len; i++ ) { + srcVal = ( typeof indexOrArray.get === 'function' ) ? indexOrArray.get( i ) : indexOrArray[ i ]; + this._buffer[ offset + i ] = Float16Array.toFloat16( srcVal ); + } + return; + } + + throw new TypeError( format( 'invalid argument. Must provide index and value or source and offset. Value: `%s`.', indexOrArray ) ); }; /** -* Creates a new Float16Array with all elements that pass the test implemented by the provided function. +* Returns a shallow copy of a portion of the array. * -* @param {Function} callback - Function to test each element -* @param {*} [thisArg] - Value to use as `this` when executing `callback` -* @throws {TypeError} Must provide a function as callback -* @returns {Float16Array} New Float16Array with filtered elements +* @param {integer} [start=0] - Start index +* @param {integer} [end=array.length] - End index (exclusive) +* @throws {TypeError} If start or end is not an integer +* @returns {Float16Array} New subarray */ -Float16Array.prototype.filter = function( callback, thisArg ) { - var i; - var value; - var result; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); - } - - result = []; - for ( i = 0; i < this.length; i++ ) { - value = this.get( i ); - if ( callback.call( thisArg, value, i, this ) ) { - result.push( value ); - } - } - return new Float16Array( result ); +Float16Array.prototype.slice = function( start, end ) { + var len = this.length; + var i; + var count; + var relativeStart; + var relativeEnd; + var result; + + if ( start !== void 0 && !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Start index must be an integer. Value: `%s`.', start ) ); + } + if ( end !== void 0 && !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. End index must be an integer. Value: `%s`.', end ) ); + } + + relativeStart = ( start === void 0 ) ? 0 : ( start < 0 ? max( len + start, 0 ) : min( start, len ) ); + relativeEnd = ( end === void 0 ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); + + count = max( relativeEnd - relativeStart, 0 ); + result = new Float16Array( count ); + + for ( i = 0; i < count; i++ ) { + result.set( i, this.get( relativeStart + i ) ); + } + return result; }; /** -* Returns the value of the first element that satisfies the provided testing function. +* Test whether at least one element passes the test. * -* @param {Function} callback - Function to execute on each value -* @param {*} [thisArg] - Value to use as `this` when executing `callback` -* @throws {TypeError} Must provide a function as callback -* @returns {*} First matching element, or undefined if no match +* @param {Function} callback - Predicate function +* @param {*} [thisArg] - Context +* @returns {boolean} Whether at least one passes */ -Float16Array.prototype.find = function( callback, thisArg ) { - var i; - var value; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); - } - - for ( i = 0; i < this.length; i++ ) { - value = this.get( i ); - if ( callback.call( thisArg, value, i, this ) ) { - return value; - } - } - return void 0; // returns undefined +Float16Array.prototype.some = function( callback, thisArg ) { + var i; + var value; + + if ( !isFunction( callback ) ) { + throw new TypeError( format( 'invalid argument. Callback must be a function. Value: `%s`.', callback ) ); + } + for ( i = 0; i < this.length; i++ ) { + value = this.get( i ); + if ( callback.call( thisArg, value, i, this ) ) { + return true; + } + } + return false; }; /** -* Returns the index of the first element that satisfies the provided testing function. +* Sort the array in place. * -* @param {Function} callback - Function to execute on each value -* @param {*} [thisArg] - Value to use as `this` when executing `callback` -* @throws {TypeError} Must provide a function as callback -* @returns {integer} Index of found element, or -1 if none found +* @param {Function} [compareFn] - Optional comparison function +* @throws {TypeError} If compareFn is not a function +* @returns {Float16Array} Sorted array */ -Float16Array.prototype.findIndex = function( callback, thisArg ) { - var i; - var value; - - if ( typeof callback !== 'function' ) { - throw new TypeError( 'invalid argument. Must provide a function. Value: `' + callback + '`.' ); - } - for ( i = 0; i < this.length; i++ ) { - value = this.get( i ); - if ( callback.call( thisArg, value, i, this ) ) { - return i; - } - } - return -1; +function getComparator( compareFn ) { + return function compareFloat16( a, b ) { + if ( compareFn ) { + return compareFn( a, b ); + } + if ( a !== a ) { + return 1; + } + if ( b !== b ) { + return -1; + } + return a - b; + }; +} + +Float16Array.prototype.sort = function( compareFn ) { + var values = []; + var i; + var j; + + if ( compareFn !== void 0 && !isFunction( compareFn ) ) { + throw new TypeError( format( 'invalid argument. Comparison function must be a function. Value: `%s`.', compareFn ) ); + } + + for ( i = 0; i < this.length; i++ ) { + values.push( this.get( i ) ); + } + + values.sort( getComparator( compareFn ) ); + + for ( j = 0; j < this.length; j++ ) { + this.set( j, values[ j ] ); + } + return this; }; /** -* Return an iterator over [index, value] pairs. +* Returns a new Float16Array view on the same buffer, for the specified range. * -* @returns {Object} Iterator +* @param {integer} [begin=0] - Start index +* @param {integer} [end=this.length] - End index +* @returns {Float16Array} New Float16Array */ -Float16Array.prototype.entries = function() { - var self = this; - var i = 0; - - return { - next: function() { - if ( i < self.length ) { - var v = [ i, self.get( i ) ]; - i += 1; - return { - value: v, - done: false - }; - } - return { - value: void 0, - done: true - }; - } - }; +Float16Array.prototype.subarray = function( begin, end ) { + var len = this.length; + var i; + var start = ( typeof begin === 'undefined' ) ? 0 : ( begin < 0 ? max( len + begin, 0 ) : min( begin, len ) ); + var finish = ( typeof end === 'undefined' ) ? len : ( end < 0 ? max( len + end, 0 ) : min( end, len ) ); + var count = max( finish - start, 0 ); + var result = new Float16Array( count ); + + for ( i = 0; i < count; i++ ) { + result.set( i, this.get( start + i ) ); + } + return result; }; /** -* Return an iterator over indices. +* Converts a float32 number to a float16 (binary) representation. * -* @returns {Object} Iterator +* @param {*} val - Float32 value (coerced if not number) +* @returns {integer} Float16 bit pattern */ -Float16Array.prototype.keys = function() { - var self = this; - var i = 0; - - return { - next: function() { - if ( i < self.length ) { - var v = i; - i += 1; - return { - value: v, - done: false - }; - } - return { - value: void 0, - done: true - }; - } - }; +Float16Array.toFloat16 = function( val ) { + var num = Number( val ); + + var floatView = new Float32Array( 1 ); + var intView = new Uint32Array( floatView.buffer ); + var sign; + var exponent; + var fraction; + var exp; + var frac; + var x; + + floatView[ 0 ] = num; + x = intView[ 0 ]; + + sign = ( x >> 16 ) & 0x8000; + exponent = ( ( x >> 23 ) & 0xff ) - 127; + fraction = x & 0x7fffff; + + if ( exponent <= -15 ) { + if ( exponent < -24 ) { + return sign; + } + return sign | ( ( ( fraction | 0x800000 ) >> ( -exponent - 1 ) ) >> 13 ); + } + if ( exponent >= 16 ) { + return sign | 0x7c00; + } + exp = exponent + 15; + frac = fraction >> 13; + return sign | ( exp << 10 ) | frac; }; /** @@ -877,27 +1005,40 @@ Float16Array.prototype.keys = function() { * @returns {Object} Iterator */ Float16Array.prototype.values = function() { - var self = this; - var i = 0; - - return { - next: function() { - if ( i < self.length ) { - var v = self.get( i ); - i += 1; - return { - value: v, - done: false - }; - } - return { - value: void 0, - done: true - }; - } - }; + var self = this; + var i = 0; + + function nextValues() { + if ( i < self.length ) { + var v = self.get( i ); + i += 1; + return { + value: v, + done: false + }; + } + return { + value: void 0, + done: true + }; + } + + function getValuesIterator() { + return iterator; + } + + var iterator = { + next: nextValues + }; + + if ( typeof Symbol === 'function' && Symbol.iterator ) { + iterator[ Symbol.iterator ] = getValuesIterator; + } + + return iterator; }; + // EXPORTS // module.exports = Float16Array; From 1f18925d1660cf12d7f4ec45619087fd03ad4b6a Mon Sep 17 00:00:00 2001 From: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> Date: Tue, 1 Jul 2025 17:13:07 +0530 Subject: [PATCH 5/5] Update package.json Signed-off-by: Uday Kakade <141299403+udaykakade25@users.noreply.github.com> --- lib/node_modules/@stdlib/array/float16/package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/float16/package.json b/lib/node_modules/@stdlib/array/float16/package.json index 34eb6b834170..63d51e83fa90 100644 --- a/lib/node_modules/@stdlib/array/float16/package.json +++ b/lib/node_modules/@stdlib/array/float16/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/float16", "version": "0.0.0", - "description": "Float16Array polyfill and fallback interface.", + "description": "Float16Array.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -64,6 +64,5 @@ "half", "half-precision", "ieee754" - ], - "type": "commonjs" + ] }