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..a6131501442c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/README.md @@ -0,0 +1,1481 @@ + + +# Float16Array + +> [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. + + + +
+ +
+ + + + + +
+ +## 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( 8 ); +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..ca30dda4d455 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.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 isFloat16Array = require( '@stdlib/assert/is-float16array' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( pkg+':fill', function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = [ 1.0, 2.0, 3.0 ]; + arr = new Float16Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + 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.fill.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js new file mode 100644 index 000000000000..0023ad38cf93 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js @@ -0,0 +1,98 @@ +/** +* @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 values; + var out; + var i; + + values = [ 1.0, 2.0, 3.0 ]; + arr = new Float16Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + 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+':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..cae0ff1f2aee --- /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' ); + + +// 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..5238739ac924 --- /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' ); + + +// 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..13cdb5355013 --- /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' ); + + +// 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..d83014e82145 --- /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' ); + + +// 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..d76e10422306 --- /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' ); + + +// 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..1b221a7fcc30 --- /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' ); + + +// 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..1b8144895b35 --- /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' ); + + +// 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..3c20942c9e61 --- /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' ); + + +// 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..33d5a282e248 --- /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' ); + + +// 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..11c88f41c94a --- /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' ); + + +// 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..739a8a31396c --- /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' ); + + +// 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/from_iterator.js b/lib/node_modules/@stdlib/array/float16/lib/from_iterator.js new file mode 100644 index 000000000000..b6190d00321b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/from_iterator.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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @returns {Array} output array +*/ +function fromIterator( it ) { + var out; + var v; + + out = []; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + out.push( v.value ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/float16/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/float16/lib/from_iterator_map.js new file mode 100644 index 000000000000..346ff3c47a4f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/from_iterator_map.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'; + +// MAIN // + +/** +* Returns an array of iterated values. +* +* @private +* @param {Object} it - iterator +* @param {Function} clbk - callback to invoke for each iterated value +* @param {*} thisArg - invocation context +* @returns {Array} output array +*/ +function fromIteratorMap( it, clbk, thisArg ) { + var out; + var v; + var i; + + out = []; + i = -1; + while ( true ) { + v = it.next(); + if ( v.done ) { + break; + } + i += 1; + out.push( clbk.call( thisArg, v.value, i ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; 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..175d68ace350 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/index.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'; + +/** +* 16-bit floating-point number array constructor. +* +* @module @stdlib/array/float16 +* +* @example +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var arr = new Float16Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var arr = new Float16Array( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var arr = new Float16Array( [ true, false ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float16Array( buf ); +* // returns +* +* var len = arr.length; +* // returns 8 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float16Array( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float16Array( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; 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..50f9ecab5697 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/main.js @@ -0,0 +1,2493 @@ +/* eslint-disable stdlib/jsdoc-no-undefined-references */ +/* eslint-disable stdlib/jsdoc-no-shortcut-reference-link */ +/* eslint-disable stdlib/jsdoc-typedef-typos, max-lines */ + +/** +* @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 no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isObject = require( '@stdlib/assert/is-object' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var getter = require( '@stdlib/array/base/getter' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); +var fromIterator = require( './from_iterator.js' ); +var fromIteratorMap = require( './from_iterator_map.js' ); + + +// VARIABLES // + +var BYTES_PER_ELEMENT = Uint16Array.BYTES_PER_ELEMENT; +var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating if a value is a `Float16Array`. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a `Float16Array` +*/ +function isFloat16Array( value ) { + return ( + typeof value === 'object' && + value !== null && + value.constructor.name === 'Float16Array' && + value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT + ); +} + +/** +* Returns a boolean indicating if a value is a floating-point typed array constructor. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a floating-point typed array constructor +*/ +function isFloatingPointArrayConstructor( value ) { + return ( value === Float16Array ); +} + + +// MAIN // + +/** +* 16-bit floating-point number array constructor. +* +* @constructor +* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable +* @param {NonNegativeInteger} [byteOffset=0] - byte offset +* @param {NonNegativeInteger} [length] - view length +* @throws {RangeError} ArrayBuffer byte length must be a multiple of `2` +* @throws {TypeError} if provided only a single argument, must provide a valid argument +* @throws {TypeError} byte offset must be a nonnegative integer +* @throws {RangeError} byte offset must be a multiple of `2` +* @throws {TypeError} view length must be a positive multiple of `2` +* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements +* @returns {Float16Array} floating-point number array +* +* @example +* var arr = new Float16Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Float16Array( 5 ); +* // returns +* +* var len = arr.length; +* // returns 5 +* +* @example +* var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float16Array( buf ); +* // returns +* +* var len = arr.length; +* // returns 8 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = new Float16Array( buf, 8 ); +* // returns +* +* var len = arr.length; +* // returns 4 +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = new Float16Array( buf, 8, 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +function Float16Array() { + var byteOffset; + var nargs; + var buf; + var len; + + nargs = arguments.length; + if ( !(this instanceof Float16Array) ) { + if ( nargs === 0 ) { + return new Float16Array(); + } + if ( nargs === 1 ) { + return new Float16Array( arguments[0] ); + } + if ( nargs === 2 ) { + return new Float16Array( arguments[0], arguments[1] ); + } + return new Float16Array( arguments[0], arguments[1], arguments[2] ); + } + // Create the underlying data buffer... + if ( nargs === 0 ) { + buf = new Uint16Array( 0 ); // backward-compatibility + } else if ( nargs === 1 ) { + if ( isNonNegativeInteger( arguments[0] ) ) { + buf = new Uint16Array( arguments[0] ); + } else if ( isCollection( arguments[0] ) ) { + buf = arguments[0]; + buf = new Uint16Array( buf ); + } else if ( isArrayBuffer( arguments[0] ) ) { + buf = new Uint16Array( arguments[0] ); + } else if ( isObject( arguments[0] ) ) { + buf = arguments[ 0 ]; + if ( HAS_ITERATOR_SYMBOL === false ) { + throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', buf ) ); + } + if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = buf[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + } + buf = new Uint16Array( fromIterator( buf ) ); + } else { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arguments[0] ) ); + } + } else { + buf = arguments[ 0 ]; + if ( !isArrayBuffer( buf ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) ); + } + byteOffset = arguments[ 1 ]; + if ( !isNonNegativeInteger( byteOffset ) ) { + throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) ); + } + if ( nargs === 2 ) { + buf = new Uint16Array( buf, byteOffset ); + } else { + len = arguments[ 2 ]; + if ( !isNonNegativeInteger( len ) ) { + throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) ); + } + if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len*BYTES_PER_ELEMENT ) ); + } + buf = new Uint16Array( buf, byteOffset, len ); + } + } + setReadOnly( this, '_buffer', buf ); + setReadOnly( this, '_length', buf.length ); + + return this; +} + +/** +* Size (in bytes) of each array element. +* +* @name BYTES_PER_ELEMENT +* @memberof Float16Array +* @readonly +* @type {PositiveInteger} +* @default 2 +* +* @example +* var nbytes = Float16Array.BYTES_PER_ELEMENT; +* // returns 2 +*/ +setReadOnly( Float16Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT ); + +/** +* Constructor name. +* +* @name name +* @memberof Float16Array +* @readonly +* @type {string} +* @default 'Float16Array' +* +* @example +* var str = Float16Array.name; +* // returns 'Float16Array' +*/ +setReadOnly( Float16Array, 'name', 'Float16Array' ); + +/** +* Creates a new 16-bit floating-point number array from an array-like object or an iterable. +* +* @name from +* @memberof Float16Array +* @type {Function} +* @param {(Collection|Iterable)} src - array-like object or iterable +* @param {Function} [clbk] - callback to invoke for each source element +* @param {*} [thisArg] - context +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a floating-point array +* @throws {TypeError} first argument must be an array-like object or an iterable +* @throws {TypeError} second argument must be a function +* @returns {Float16Array} floating-point number array +* +* @example +* var arr = Float16Array.from( [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = Float16Array.from( [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* function clbk( v ) { +* return v * 2.0; +* } +* +* var arr = Float16Array.from( [ 1.0, 2.0 ], clbk ); +* // returns +* +* var len = arr.length; +* // returns 2 +*/ +setReadOnly( Float16Array, 'from', function from( src ) { + var thisArg; + var nargs; + var clbk; + var out; + var buf; + var tmp; + var get; + var len; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isFloatingPointArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point array.' ); + } + nargs = arguments.length; + if ( nargs > 1 ) { + clbk = arguments[ 1 ]; + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + } + if ( nargs > 2 ) { + thisArg = arguments[ 2 ]; + } + } + if ( isArrayLikeObject( src ) ) { + if ( clbk ) { + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ i ] = clbk.call( thisArg, get( src, i ), i ); + } + return out; + } + return new this( src ); + } + if ( isCollection( src ) ) { + if ( clbk ) { + len = src.length; + if ( src.get && src.set ) { + get = accessorGetter( 'default' ); + } else { + get = getter( 'default' ); + } + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ i ] = clbk.call( thisArg, get( src, i ), i ); + } + return out; + } + return new this( src ); + } + if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len + buf = src[ ITERATOR_SYMBOL ](); + if ( !isFunction( buf.next ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + } + if ( clbk ) { + tmp = fromIteratorMap( buf, clbk, thisArg ); + } else { + tmp = fromIterator( buf ); + } + len = tmp.length; + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ i ] = tmp[ i ]; + } + return out; + } + throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); +}); + +/** +* Creates a new 16-bit floating-point number array from a variable number of arguments. +* +* @name of +* @memberof Float16Array +* @type {Function} +* @param {...*} element - array elements +* @throws {TypeError} `this` context must be a constructor +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Float16Array} 16-bit floating-point number array +* +* @example +* var arr = Float16Array.of( 1.0, 1.0, 1.0, 1.0 ); +* // returns +* +* var len = arr.length; +* // returns 4 +*/ +setReadOnly( Float16Array, 'of', function of() { + var args; + var i; + if ( !isFunction( this ) ) { + throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + } + if ( !isFloatingPointArrayConstructor( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return new this( args ); +}); + +/** +* Returns an array element with support for both nonnegative and negative integer indices. +* +* @name at +* @memberof Float16Array.prototype +* @type {Function} +* @param {integer} idx - element index +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} must provide an integer +* @returns {(Complex64|void)} array element +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 10.0, 0 ); +* arr.set( 20.0, 1 ); +* arr.set( 30.0, 2 ); +* +* var v = arr.at( 0 ); +* // returns 10 +* +* v = arr.at( -1 ); +* // returns 30 +* +* v = arr.at( 100 ); +* // returns undefined +*/ +setReadOnly( Float16Array.prototype, 'at', function at( idx ) { + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); + } + if ( idx < 0 ) { + idx += this._length; + } + if ( idx < 0 || idx >= this._length ) { + return; + } + return this._buffer[ idx ]; +}); + +/** +* Pointer to the underlying data buffer. +* +* @name buffer +* @memberof Float16Array.prototype +* @readonly +* @type {ArrayBuffer} +* +* @example +* var arr = new Float16Array( 10 ); +* +* var buf = arr.buffer; +* // returns +*/ +setReadOnlyAccessor( Float16Array.prototype, 'buffer', function get() { + return this._buffer.buffer; +}); + +/** +* Size (in bytes) of the array. +* +* @name byteLength +* @memberof Float16Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Float16Array( 10 ); +* +* var byteLength = arr.byteLength; +* // returns 20 +*/ +setReadOnlyAccessor( Float16Array.prototype, 'byteLength', function get() { + return this._buffer.byteLength; +}); + +/** +* Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. +* +* @name byteOffset +* @memberof Float16Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Float16Array( 10 ); +* +* var byteOffset = arr.byteOffset; +* // returns 0 +*/ +setReadOnlyAccessor( Float16Array.prototype, 'byteOffset', function get() { + return this._buffer.byteOffset; +}); + +/** +* Size (in bytes) of each array element. +* +* @name BYTES_PER_ELEMENT +* @memberof Float16Array.prototype +* @readonly +* @type {PositiveInteger} +* @default 2 +* +* @example +* var arr = new Float16Array( 10 ); +* +* var nbytes = arr.BYTES_PER_ELEMENT; +* // returns 2 +*/ +setReadOnly( Float16Array.prototype, 'BYTES_PER_ELEMENT', Float16Array.BYTES_PER_ELEMENT ); + +/** +* Copies a sequence of elements within the array to the position starting at `target`. +* +* @name copyWithin +* @memberof Float16Array.prototype +* @type {Function} +* @param {integer} target - index at which to start copying elements +* @param {integer} start - source index at which to copy elements from +* @param {integer} [end] - source index at which to stop copying elements from +* @throws {TypeError} `this` must be a floating-point array +* @returns {Float16Array} modified array +* +* @example +* var arr = new Float16Array( 4 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 2.0, 1 ); +* arr.set( 3.0, 2 ); +* arr.set( 4.0, 3 ); +* +* // Copy the first two elements to the last two elements: +* arr.copyWithin( 2, 0, 2 ); +* +* var v = arr.get( 2 ); +* // returns 1.0 +* +* v = arr.get( 3 ); +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'copyWithin', function copyWithin( target, start ) { + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled + if ( arguments.length === 2 ) { + this._buffer.copyWithin( target, start ); + } else { + this._buffer.copyWithin( target, start, arguments[2] ); + } + return this; +}); + +/** +* Returns an iterator for iterating over array key-value pairs. +* +* @name entries +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Iterator} iterator +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 2.0, 1 ); +* arr.set( 3.0, 2 ); +* +* var it = arr.entries(); +* +* var v = it.next().value; +* // returns [ 0, 1.0 ] +* +* v = it.next().value; +* // returns [ 1, 2.0 ] +* +* v = it.next().value; +* // returns [ 2, 3.0 ] +* +* var bool = it.next().done; +* // returns true +*/ +setReadOnly( Float16Array.prototype, 'entries', function entries() { + var self; + var iter; + var len; + var buf; + var FLG; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + self = this; + buf = this._buffer; + len = this._length; + + // Initialize an iteration index: + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + if ( ITERATOR_SYMBOL ) { + setReadOnly( iter, ITERATOR_SYMBOL, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i >= len ) { + return { + 'done': true + }; + } + return { + 'value': [ i, buf[ i ] ], + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return self.entries(); + } +}); + +/** +* Tests whether all elements in an array pass a test implemented by a predicate function. +* +* @name every +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {boolean} boolean indicating whether all elements pass a test +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 0.0, 1 ); +* arr.set( 0.0, 2 ); +* +* var bool = arr.every( predicate ); +* // returns true +*/ +setReadOnly( Float16Array.prototype, 'every', function every( predicate, thisArg ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + if ( !predicate.call( thisArg, buf[ i ], i, this ) ) { + return false; + } + } + return true; +}); + +/** +* Returns a modified typed array filled with a fill value. +* +* @name fill +* @memberof Float16Array.prototype +* @type {Function} +* @param {number} value - fill value +* @param {integer} [start=0] - starting index (inclusive) +* @param {integer} [end] - ending index (exclusive) +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a floating-point number +* @throws {TypeError} second argument must be an integer +* @throws {TypeError} third argument must be an integer +* @returns {Float16Array} modified array +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.fill( 1.0, 1 ); +* +* var v = arr.get( 0 ); +* // returns 0.0 +* +* v = arr.get( 1 ); +* // returns 1.0 +* +* v = arr.get( 2 ); +* // returns 1.0 +*/ +setReadOnly( Float16Array.prototype, 'fill', function fill( value, start, end ) { + var buf; + var len; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isNumber( value ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a number. Value: `%s`.', value ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + if ( !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); + } + if ( start < 0 ) { + start += len; + if ( start < 0 ) { + start = 0; + } + } + if ( arguments.length > 2 ) { + if ( !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); + } + if ( end < 0 ) { + end += len; + if ( end < 0 ) { + end = 0; + } + } + if ( end > len ) { + end = len; + } + } else { + end = len; + } + } else { + start = 0; + end = len; + } + for ( i = start; i < end; i++ ) { + buf[ i ] = value; + } + return this; +}); + +/** +* Returns a new array containing the elements of an array which pass a test implemented by a predicate function. +* +* @name filter +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {Float16Array} floating-point number array +* +* @example +* function predicate( v ) { +* return ( v === 0.0 ); +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 0.0, 2 ); +* +* var out = arr.filter( predicate ); +* // returns +* +* var len = out.length; +* // returns 2 +* +* var v = out.get( 0 ); +* // returns 0.0 +* +* v = out.get( 1 ); +* // returns 0.0 +*/ +setReadOnly( Float16Array.prototype, 'filter', function filter( predicate, thisArg ) { + var buf; + var out; + var i; + var v; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + v = buf[ i ]; + if ( predicate.call( thisArg, v, i, this ) ) { + out.push( v ); + } + } + return new this.constructor( out ); +}); + +/** +* Returns the first element in an array for which a predicate function returns a truthy value. +* +* @name find +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {(boolean|void)} array element or undefined +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 0.0, 2 ); +* +* var v = arr.find( predicate ); +* // returns 0.0 +*/ +setReadOnly( Float16Array.prototype, 'find', function find( predicate, thisArg ) { + var buf; + var v; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + v = buf[ i ]; + if ( predicate.call( thisArg, v, i, this ) ) { + return v; + } + } +}); + +/** +* Returns the index of the first element in an array for which a predicate function returns a truthy value. +* +* @name findIndex +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {integer} index or -1 +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var v = arr.findIndex( predicate ); +* // returns 0 +*/ +setReadOnly( Float16Array.prototype, 'findIndex', function findIndex( predicate, thisArg ) { + var buf; + var v; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + v = buf[ i ]; + if ( predicate.call( thisArg, v, i, this ) ) { + return i; + } + } + return -1; +}); + +/** +* Returns the last element in an array for which a predicate function returns a truthy value. +* +* @name findLast +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {(boolean|void)} array element or undefined +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 0.0, 2 ); +* +* var v = arr.findLast( predicate ); +* // returns 0.0 +*/ +setReadOnly( Float16Array.prototype, 'findLast', function findLast( predicate, thisArg ) { + var buf; + var v; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = this._length-1; i >= 0; i-- ) { + v = buf[ i ]; + if ( predicate.call( thisArg, v, i, this ) ) { + return v; + } + } +}); + +/** +* Returns the index of the last element in an array for which a predicate function returns a truthy value. +* +* @name findLastIndex +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {integer} index or -1 +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 0.0, 2 ); +* +* var v = arr.findLastIndex( predicate ); +* // returns 2 +*/ +setReadOnly( Float16Array.prototype, 'findLastIndex', function findLastIndex( predicate, thisArg ) { + var buf; + var v; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = this._length-1; i >= 0; i-- ) { + v = buf[ i ]; + if ( predicate.call( thisArg, v, i, this ) ) { + return i; + } + } + return -1; +}); + +/** +* Invokes a function once for each array element. +* +* @name forEach +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} fcn - function to invoke +* @param {*} [thisArg] - function invocation context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* +* @example +* function log( v, i ) { +* console.log( '%s: %s', i, v.toString() ); +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* arr.forEach( log ); +*/ +setReadOnly( Float16Array.prototype, 'forEach', function forEach( fcn, thisArg ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + fcn.call( thisArg, buf[ i ], i, this ); + } +}); + +/** +* Returns an array element. +* +* @name get +* @memberof Float16Array.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - element index +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} must provide a nonnegative integer +* @returns {(boolean|void)} array element +* +* @example +* var arr = new Float16Array( 10 ); +* +* var v = arr.get( 0 ); +* // returns 0.0 +* +* arr.set( [ 1.0, 0.0 ], 0 ); +* +* v = arr.get( 0 ); +* // returns 1.0 +* +* v = arr.get( 100 ); +* // returns undefined +*/ +setReadOnly( Float16Array.prototype, 'get', function get( idx ) { + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + return this._buffer[ idx ]; +}); + +/** +* Returns a boolean indicating whether an array includes a provided value. +* +* @name includes +* @memberof Float16Array.prototype +* @type {Function} +* @param {number} searchElement - search element +* @param {integer} [fromIndex=0] - starting index (inclusive) +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a floating-point number +* @throws {TypeError} second argument must be an integer +* @returns {boolean} boolean indicating whether an array includes a value +* +* @example +* var arr = new Float16Array( 5 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* arr.set( 3.0, 3 ); +* arr.set( 4.0, 4 ); +* +* var bool = arr.includes( 1.0 ); +* // returns true +* +* bool = arr.includes( 1.0, 2 ); +* // returns false +* +* bool = arr.includes( 5.0 ); +* // returns false +*/ +setReadOnly( Float16Array.prototype, 'includes', function includes( searchElement, fromIndex ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isNumber( searchElement ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a number. Value: `%s`.', searchElement ) ); + } + if ( arguments.length > 1 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex < 0 ) { + fromIndex += this._length; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } + } else { + fromIndex = 0; + } + buf = this._buffer; + for ( i = fromIndex; i < this._length; i++ ) { + if ( searchElement === buf[ i ] ) { + return true; + } + } + return false; +}); + +/** +* Returns the first index at which a given element can be found. +* +* @name indexOf +* @memberof Float16Array.prototype +* @type {Function} +* @param {float16} searchElement - element to find +* @param {integer} [fromIndex=0] - starting index (inclusive) +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a floating-point number +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var arr = new Float16Array( 5 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* arr.set( 3.0, 3 ); +* arr.set( 4.0, 4 ); +* +* var idx = arr.indexOf( 2.0 ); +* // returns 2 +* +* idx = arr.indexOf( 2.0, 3 ); +* // returns -1 +* +* idx = arr.indexOf( 3.0, 3 ); +* // returns 3 +*/ +setReadOnly( Float16Array.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isNumber( searchElement ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a number. Value: `%s`.', searchElement ) ); + } + if ( arguments.length > 1 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex < 0 ) { + fromIndex += this._length; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } + } else { + fromIndex = 0; + } + buf = this._buffer; + for ( i = fromIndex; i < this._length; i++ ) { + if ( searchElement === buf[ i ] ) { + return i; + } + } + return -1; +}); + +/** +* Returns a new string by concatenating all array elements. +* +* @name join +* @memberof Float16Array.prototype +* @type {Function} +* @param {string} [separator=','] - element separator +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a string +* @returns {string} string representation +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var str = arr.join(); +* // returns '0,1,2' +* +* str = arr.join( '|' ); +* // returns '0|1|2' +*/ +setReadOnly( Float16Array.prototype, 'join', function join( separator ) { + var buf; + var out; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( arguments.length > 0 ) { + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) ); + } + } else { + separator = ','; + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + out.push( buf[i] ); + } + return out.join( separator ); +}); + +/** +* Returns an iterator for iterating over each index key in a typed array. +* +* @name keys +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Iterator} iterator +* +* @example +* var arr = new Float16Array( 2 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 2.0, 1 ); +* +* var iter = arr.keys(); +* +* var v = iter.next().value; +* // returns 0 +* +* v = iter.next().value; +* // returns 1 +* +* var bool = iter.next().done; +* // returns true +*/ +setReadOnly( Float16Array.prototype, 'keys', function keys() { + var self; + var iter; + var len; + var FLG; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + self = this; + len = this._length; + + // Initialize an iteration index: + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + if ( ITERATOR_SYMBOL ) { + setReadOnly( iter, ITERATOR_SYMBOL, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i >= len ) { + return { + 'done': true + }; + } + return { + 'value': i, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return self.keys(); + } +}); + +/** +* Returns the last index at which a given element can be found. +* +* @name lastIndexOf +* @memberof Float16Array.prototype +* @type {Function} +* @param {number} searchElement - element to find +* @param {integer} [fromIndex] - starting index (inclusive) +* @throws {TypeError} `this` must be a boolean array +* @throws {TypeError} first argument must be a boolean value +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var arr = new Float16Array( 5 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* arr.set( 3.0, 3 ); +* arr.set( 2.0, 4 ); +* +* var idx = arr.lastIndexOf( 2.0 ); +* // returns 4 +* +* idx = arr.lastIndexOf( 2.0, 3 ); +* // returns 2 +* +* idx = arr.lastIndexOf( 4.0, 3 ); +* // returns -1 +* +* idx = arr.lastIndexOf( 1.0, -3 ); +* // returns 1 +*/ +setReadOnly( Float16Array.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isNumber( searchElement ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a number. Value: `%s`.', searchElement ) ); + } + if ( arguments.length > 1 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + if ( fromIndex >= this._length ) { + fromIndex = this._length - 1; + } else if ( fromIndex < 0 ) { + fromIndex += this._length; + } + } else { + fromIndex = this._length - 1; + } + buf = this._buffer; + for ( i = fromIndex; i >= 0; i-- ) { + if ( searchElement === buf[ i ] ) { + return i; + } + } + return -1; +}); + +/** +* Number of array elements. +* +* @name length +* @memberof Float16Array.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new Float16Array( 10 ); +* +* var len = arr.length; +* // returns 10 +*/ +setReadOnlyAccessor( Float16Array.prototype, 'length', function get() { + return this._length; +}); + +/** +* Returns a new array with each element being the result of a provided callback function. +* +* @name map +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} fcn - callback function +* @param {*} [thisArg] - callback function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {Float16Array} new floating-point number array +* +* @example +* function scale( v ) { +* return v*2.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var out = arr.map( scale ); +* // returns +* +* var z = out.get( 0 ); +* // returns 0.0 +* +* z = out.get( 1 ); +* // returns 2.0 +* +* z = out.get( 2 ); +* // returns 4.0 +*/ +setReadOnly( Float16Array.prototype, 'map', function map( fcn, thisArg ) { + var outbuf; + var out; + var buf; + var i; + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ); + } + buf = this._buffer; + out = new this.constructor( this._length ); + outbuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < this._length; i++ ) { + outbuf[ i ] = fcn.call( thisArg, buf[ i ], i, this ); + } + return out; +}); + +/** +* Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. +* +* @name reduce +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} reducer - callback function +* @param {*} [initialValue] - initial value +* @throws {TypeError} `this` must be a floating-point number array +* @throws {Error} if not provided an initial value, the array must have at least one element +* @returns {*} accumulated result +* +* @example +* function add( acc, v ) { +* return acc + v; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 2.0, 1 ); +* arr.set( 3.0, 2 ); +* +* var out = arr.reduce( add, 0 ); +* // returns 6.0 +*/ +setReadOnly( Float16Array.prototype, 'reduce', function reduce( reducer, initialValue ) { + var buf; + var len; + var acc; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( reducer ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + acc = initialValue; + i = 0; + } else { + if ( len === 0 ) { + throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); + } + acc = buf[ 0 ]; + i = 1; + } + for ( ; i < len; i++ ) { + acc = reducer( acc, buf[ i ], i, this ); + } + return acc; +}); + +/** +* Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. +* +* @name reduceRight +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} reducer - callback function +* @param {*} [initialValue] - initial value +* @throws {TypeError} `this` must be a floating-point number array +* @throws {Error} if not provided an initial value, the array must have at least one element +* @returns {*} accumulated result +* +* @example +* function add( acc, v ) { +* return acc + v; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 2.0, 1 ); +* arr.set( 3.0, 2 ); +* +* var out = arr.reduceRight( add, 0 ); +* // returns 6.0 +*/ +setReadOnly( Float16Array.prototype, 'reduceRight', function reduceRight( reducer, initialValue ) { + var buf; + var len; + var acc; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( reducer ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + acc = initialValue; + i = len - 1; + } else { + if ( len === 0 ) { + throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); + } + acc = buf[ len-1 ]; + i = len - 2; + } + for ( ; i >= 0; i-- ) { + acc = reducer( acc, buf[ i ], i, this ); + } + return acc; +}); + +/** +* Reverses an array in-place. +* +* @name reverse +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Float16Array} reversed array +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var out = arr.reverse(); +* // returns +* +* var v = out.get( 0 ); +* // returns 2.0 +* +* v = out.get( 1 ); +* // returns 1.0 +* +* v = out.get( 2 ); +* // returns 0.0 +*/ +setReadOnly( Float16Array.prototype, 'reverse', function reverse() { + var buf; + var tmp; + var len; + var N; + var i; + var j; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + buf = this._buffer; + len = this._length; + N = floor( len / 2 ); + for ( i = 0; i < N; i++ ) { + j = len - i - 1; + tmp = buf[ i ]; + buf[ i ] = buf[ j ]; + buf[ j ] = tmp; + } + return this; +}); + +/** +* Sets an array element. +* +* ## Notes +* +* - When provided a typed array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. +* +* In the other overlapping scenario, +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values, as intended. +* +* @name set +* @memberof Float16Array.prototype +* @type {Function} +* @param {(Collection|Float16Array|*)} value - value(s) +* @param {NonNegativeInteger} [i=0] - element index at which to start writing values +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} index argument is out-of-bounds +* @throws {RangeError} target array lacks sufficient storage to accommodate source values +* @returns {void} +* +* @example +* var arr = new Float16Array( 10 ); +* +* var v = arr.get( 0 ); +* // returns 0.0 +* +* arr.set( [ 1.0, 2.0 ], 0 ); +* +* v = arr.get( 0 ); +* // returns 1.0 +*/ +setReadOnly( Float16Array.prototype, 'set', function set( value ) { + var sbuf; + var idx; + var buf; + var tmp; + var N; + var i; + var j; + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + buf = this._buffer; + if ( arguments.length > 1 ) { + idx = arguments[ 1 ]; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + } else { + idx = 0; + } + if ( isCollection( value ) ) { + N = value.length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + if ( isFloat16Array( value ) ) { + sbuf = value._buffer; // eslint-disable-line no-underscore-dangle + } else { + sbuf = value; + } + // Check for overlapping memory... + j = buf.byteOffset + (idx*BYTES_PER_ELEMENT); + if ( + sbuf.buffer === buf.buffer && + ( + sbuf.byteOffset < j && + sbuf.byteOffset+sbuf.byteLength > j + ) + ) { + // We need to copy source values... + tmp = new Uint16Array( sbuf.length ); + for ( i = 0; i < sbuf.length; i++ ) { + tmp[ i ] = sbuf[ i ]; // TODO: handle accessor arrays + } + sbuf = tmp; + } + for ( i = 0; i < N; idx++, i++ ) { + buf[ idx ] = sbuf[ i ]; + } + return; + } + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + buf[ idx ] = value; +}); + +/** +* Copies a portion of a typed array to a new typed array. +* +* @name slice +* @memberof Float16Array.prototype +* @type {Function} +* @param {integer} [begin] - start index (inclusive) +* @param {integer} [end] - end index (exclusive) +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be integer +* @throws {TypeError} second argument must be integer +* @returns {Float16Array} floating-point number array +* +* @example +* var arr = new Float16Array( 5 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* arr.set( 3.0, 3 ); +* arr.set( 4.0, 4 ); +* +* var out = arr.slice(); +* // returns +* +* var len = out.length; +* // returns 5 +* +* var bool = out.get( 0 ); +* // returns 0.0 +* +* bool = out.get( len-1 ); +* // returns 4.0 +* +* out = arr.slice( 1, -2 ); +* // returns +* +* len = out.length; +* // returns 2 +* +* bool = out.get( 0 ); +* // returns 1.0 +* +* bool = out.get( len-1 ); +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'slice', function slice( begin, end ) { + var outlen; + var outbuf; + var out; + var buf; + var len; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length === 0 ) { + begin = 0; + end = len; + } else { + if ( !isInteger( begin ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) ); + } + if ( begin < 0 ) { + begin += len; + if ( begin < 0 ) { + begin = 0; + } + } + if ( arguments.length === 1 ) { + end = len; + } else { + if ( !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); + } + if ( end < 0 ) { + end += len; + if ( end < 0 ) { + end = 0; + } + } else if ( end > len ) { + end = len; + } + } + } + if ( begin < end ) { + outlen = end - begin; + } else { + outlen = 0; + } + out = new this.constructor( outlen ); + outbuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < outlen; i++ ) { + outbuf[ i ] = buf[ i+begin ]; + } + return out; +}); + +/** +* Tests whether at least one element in an array passes a test implemented by a predicate function. +* +* @name some +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {boolean} boolean indicating whether at least one element passes a test +* +* @example +* function predicate( v ) { +* return v === 0.0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var bool = arr.some( predicate ); +* // returns true +*/ +setReadOnly( Float16Array.prototype, 'some', function some( predicate, thisArg ) { + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + if ( predicate.call( thisArg, buf[ i ], i, this ) ) { + return true; + } + } + return false; +}); + +/** +* Sorts an array in-place. +* +* @name sort +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} [compareFcn] - comparison function +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {Float16Array} sorted array +* +* @example +* function compare( a, b ) { +* if ( a < b ) { +* return -1; +* } +* if ( a > b ) { +* return 1; +* } +* return 0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 1.0, 0 ); +* arr.set( 0.0, 1 ); +* arr.set( 2.0, 2 ); +* +* arr.sort( compare ); +* +* var v = arr.get( 0 ); +* // returns 0.0 +* +* v = arr.get( 1 ); +* // returns 1.0 +* +* v = arr.get( 2 ); +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'sort', function sort( compareFcn ) { + var buf; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + buf = this._buffer; + if ( arguments.length === 0 ) { + buf.sort(); + return this; + } + if ( !isFunction( compareFcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + } + buf.sort( compare ); + return this; + + /** + * Comparison function for sorting. + * + * @private + * @param {float16} a - first floating-point number for comparison + * @param {float16} b - second floating-point number for comparison + * @returns {number} comparison result + */ + function compare( a, b ) { + return compareFcn( a, b ); + } +}); + +/** +* Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array. +* +* @name subarray +* @memberof Float16Array.prototype +* @type {Function} +* @param {integer} [begin] - start index (inclusive) +* @param {integer} [end] - end index (exclusive) +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be an integer +* @throws {TypeError} second argument must be an integer +* @returns {Float16Array} subarray +* +* @example +* var arr = new Float16Array( 5 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* arr.set( 3.0, 3 ); +* arr.set( 4.0, 4 ); +* +* var subarr = arr.subarray(); +* // returns +* +* var len = subarr.length; +* // returns 5 +* +* var bool = subarr.get( 0 ); +* // returns 0.0 +* +* bool = subarr.get( len-1 ); +* // returns 4.0 +* +* subarr = arr.subarray( 1, -2 ); +* // returns +* +* len = subarr.length; +* // returns 2 +* +* bool = subarr.get( 0 ); +* // returns 1.0 +* +* bool = subarr.get( len-1 ); +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'subarray', function subarray( begin, end ) { + var offset; + var buf; + var len; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length === 0 ) { + begin = 0; + end = len; + } else { + if ( !isInteger( begin ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) ); + } + if ( begin < 0 ) { + begin += len; + if ( begin < 0 ) { + begin = 0; + } + } + if ( arguments.length === 1 ) { + end = len; + } else { + if ( !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); + } + if ( end < 0 ) { + end += len; + if ( end < 0 ) { + end = 0; + } + } else if ( end > len ) { + end = len; + } + } + } + if ( begin >= len ) { + len = 0; + offset = buf.byteLength; + } else if ( begin >= end ) { + len = 0; + offset = buf.byteOffset + ( begin*BYTES_PER_ELEMENT ); + } else { + len = end - begin; + offset = buf.byteOffset + ( begin*BYTES_PER_ELEMENT ); + } + return new this.constructor( buf.buffer, offset, ( len < 0 ) ? 0 : len ); +}); + +/** +* Serializes an array as a locale-specific string. +* +* @name toLocaleString +* @memberof Float16Array.prototype +* @type {Function} +* @param {(string|Array)} [locales] - locale identifier(s) +* @param {Object} [options] - configuration options +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a string or an array of strings +* @throws {TypeError} options argument must be an object +* @returns {string} string representation +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var str = arr.toLocaleString(); +* // returns '0,1,2' +*/ +setReadOnly( Float16Array.prototype, 'toLocaleString', function toLocaleString( locales, options ) { + var opts; + var loc; + var out; + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( arguments.length === 0 ) { + loc = []; + } else if ( isString( locales ) || isStringArray( locales ) ) { + loc = locales; + } else { + throw new TypeError( format( 'invalid argument. First argument must be a string or an array of strings. Value: `%s`.', locales ) ); + } + if ( arguments.length < 2 ) { + opts = {}; + } else if ( isObject( options ) ) { + opts = options; + } else { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + out.push( buf[ i ].toLocaleString( loc, opts ) ); + } + return out.join( ',' ); +}); + +/** +* Returns a new typed array containing the elements in reversed order. +* +* @name toReversed +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Float16Array} reversed array +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var out = arr.toReversed(); +* // returns +* +* var v = out.get( 0 ); +* // returns 2.0 +* +* v = out.get( 1 ); +* // returns 1.0 +* +* v = out.get( 2 ); +* // returns 0.0 +*/ +setReadOnly( Float16Array.prototype, 'toReversed', function toReversed() { + var outbuf; + var out; + var len; + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + len = this._length; + out = new this.constructor( len ); + buf = this._buffer; + outbuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + outbuf[ i ] = buf[ len - i - 1 ]; + } + return out; +}); + +/** +* Returns a new typed array containing the elements in sorted order. +* +* @name toSorted +* @memberof Float16Array.prototype +* @type {Function} +* @param {Function} [compareFcn] - comparison function +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be a function +* @returns {Float16Array} sorted array +* +* @example +* function compare( a, b ) { +* if ( a > b ) { +* return 1; +* } +* if ( a < b ) { +* return -1; +* } +* return 0; +* } +* +* var arr = new Float16Array( 3 ); +* +* arr.set( 2.0, 0 ); +* arr.set( 0.0, 1 ); +* arr.set( 1.0, 2 ); +* +* var out = arr.sort( compare ); +* // returns +* +* var v = out.get( 0 ); +* // returns 0.0 +* +* v = out.get( 1 ); +* // returns 1.0 +* +* v = out.get( 2 ); +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'toSorted', function toSorted( compareFcn ) { + var outbuf; + var out; + var len; + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + len = this._length; + out = new this.constructor( len ); + buf = this._buffer; + outbuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + outbuf[ i ] = buf[ i ]; + } + if ( arguments.length === 0 ) { + outbuf.sort(); + return out; + } + if ( !isFunction( compareFcn ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + } + outbuf.sort( compare ); + return out; + + /** + * Comparison function for sorting. + * + * @private + * @param {boolean} a - first floating-point number for comparison + * @param {boolean} b - second floating-point number for comparison + * @returns {number} comparison result + */ + function compare( a, b ) { + return compareFcn( a, b ); + } +}); + +/** +* Serializes an array as a string. +* +* @name toString +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {string} string representation +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var str = arr.toString(); +* // returns '0,1,2' +*/ +setReadOnly( Float16Array.prototype, 'toString', function toString() { + var out; + var buf; + var i; + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + out = []; + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + out.push( buf[i] ); + } + return out.join( ',' ); +}); + +/** +* Returns an iterator for iterating over each value in a typed array. +* +* @name values +* @memberof Float16Array.prototype +* @type {Function} +* @throws {TypeError} `this` must be a floating-point number array +* @returns {Iterator} iterator +* +* @example +* var arr = new Float16Array( 2 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* +* var iter = arr.values(); +* +* var v = iter.next().value; +* // returns 0.0 +* +* v = iter.next().value; +* // returns 1.0 +* +* var bool = iter.next().done; +* // returns true +*/ +setReadOnly( Float16Array.prototype, 'values', function values() { + var iter; + var self; + var len; + var FLG; + var buf; + var i; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + self = this; + buf = this._buffer; + len = this._length; + + // Initialize an iteration index: + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + if ( ITERATOR_SYMBOL ) { + setReadOnly( iter, ITERATOR_SYMBOL, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + i += 1; + if ( FLG || i >= len ) { + return { + 'done': true + }; + } + return { + 'value': buf[ i ], + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return self.values(); + } +}); + +/** +* Returns a new typed array with the element at a provided index replaced with a provided value. +* +* @name with +* @memberof Float16Array.prototype +* @type {Function} +* @param {integer} index - element index +* @param {number} value - new value +* @throws {TypeError} `this` must be a floating-point number array +* @throws {TypeError} first argument must be an integer +* @throws {RangeError} index argument is out-of-bounds +* @throws {TypeError} second argument must be a floating-point number +* @returns {Float16Array} new typed array +* +* @example +* var arr = new Float16Array( 3 ); +* +* arr.set( 0.0, 0 ); +* arr.set( 1.0, 1 ); +* arr.set( 2.0, 2 ); +* +* var out = arr.with( 0, 3.0 ); +* // returns +* +* var v = out.get( 0 ); +* // returns 3.0 +*/ +setReadOnly( Float16Array.prototype, 'with', function copyWith( index, value ) { + var buf; + var out; + var len; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isInteger( index ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) ); + } + len = this._length; + if ( index < 0 ) { + index += len; + } + if ( index < 0 || index >= len ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) ); + } + if ( !isNumber( value ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a floating-point number. Value: `%s`.', value ) ); + } + out = new this.constructor( this._buffer ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + buf[ index ] = value; + return out; +}); + + +// 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..63d51e83fa90 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/array/float16", + "version": "0.0.0", + "description": "Float16Array.", + "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" + ] +} 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