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..a5db89b74105 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.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 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..01d161d647d4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js @@ -0,0 +1,237 @@ +/** +* @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 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..3256f4f5f8e6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.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 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..410dadb2e6b0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.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+':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..9c33a9e6186f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.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 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..62122c2fd8a7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js @@ -0,0 +1,48 @@ +/** +* @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+':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..9f720967d445 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.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 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..b4742b949cae --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.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+':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..bd3e7fd4c47b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.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 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..9c5733512bcf --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.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 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..604006f98df4 --- /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) 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.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..f35849f885cb --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill.js @@ -0,0 +1,903 @@ +/** +* @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 min = require( '@stdlib/math/base/special/min' ); +var max = require( '@stdlib/math/base/special/max' ); +var floor = require( '@stdlib/math/base/special/floor' ); + + +// MAIN // + +/** +* 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; +} + +/** +* Get the underlying `ArrayBuffer`. +* +* @name buffer +* @memberof Float16Array.prototype +* @readonly +* @type {ArrayBuffer} +*/ +Object.defineProperty( Float16Array.prototype, 'buffer', { + get: function() { + return this._buffer.buffer; + } +}); + +/** +* 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; + } +}); + +/** +* 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; + } +}); + +/** +* 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; + } +}); + +/** +* 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'; + } +}); + +/** +* 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; +}; + +/** +* 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 ]; +}; + +/** +* 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; + + for ( i = 0; i < len; i++ ) { + result.set( i, arguments[ i ] ); + } + return result; +}; + +/** +* 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; +}; + +/** +* 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 ] ); +}; + +/** +* 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 + '`.' ); +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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 ); + } +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; +}; + +/** +* 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; + + 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; +}; + +/** +* 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; +}; + +/** +* 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; + + 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; +}; + +/** +* 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; +}; + +/** +* 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 ); +}; + +/** +* 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 +}; + +/** +* 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; +}; + +/** +* 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 + }; + } + }; +}; + +/** +* 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 // + +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