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..73e5ae961fd9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/README.md @@ -0,0 +1,1564 @@ + + +# Float16Array + +> 16-bit half-precision floating-point number array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float16Array = require( '@stdlib/array/float16' ); +``` + + + +#### Float16Array() + +Creates a 16-bit half-precision floating-point number array. + +```javascript +var arr = new Float16Array(); +// returns +``` + +#### Float16Array( length ) + +Creates a 16-bit half-precision floating-point number array having a specified `length`. + +```javascript +var arr = new Float16Array( 5 ); +// returns + +var len = arr.length; +// returns 5 +``` + +#### Float16Array( typedarray ) + +Creates a 16-bit half-precision floating-point number array from a [typed array][@stdlib/array/typed]. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var buf = new Float64Array( [ 0.5, 0.5, 0.5 ] ); +// returns + +var arr = new Float16Array( buf ); +// returns + +var len = arr.length; +// returns 3 +``` + +#### Float16Array( obj ) + +Creates a 16-bit half-precision floating-point number array from an array-like object or iterable. + +```javascript +var arr = new Float16Array( [ 0.5, 0.5, 0.5 ] ); +// returns + +var len = arr.length; +// returns 3 +``` + +#### Float16Array( buffer\[, byteOffset\[, length]] ) + +Returns a 16-bit half-precision floating-point number 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 ); +// returns + +var len = arr.length; +// returns 4 + +arr = new Float16Array( buf, 2 ); +// returns + +len = arr.length; +// returns 3 + +arr = new Float16Array( buf, 2, 2 ); +// returns + +len = arr.length; +// returns 2 +``` + +* * * + +### Properties + + + +#### Float16Array.BYTES_PER_ELEMENT + +Static property returning the size (in bytes) of each array element. + +```javascript +var nbytes = Float16Array.BYTES_PER_ELEMENT; +// returns 2 +``` + + + +#### Float16Array.name + +Static property returning the constructor name. + +```javascript +var str = Float16Array.name; +// returns 'Float16Array' +``` + + + +#### Float16Array.prototype.buffer + +Pointer to the underlying data buffer. + +```javascript +var arr = new Float16Array( 5 ); +// returns + +var buf = arr.buffer; +// returns +``` + + + +#### Float16Array.prototype.byteLength + +Size (in bytes) of the array. + +```javascript +var arr = new Float16Array( 5 ); +// returns + +var byteLength = arr.byteLength; +// returns 10 +``` + + + +#### Float16Array.prototype.byteOffset + +Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. + +```javascript +var ArrayBuffer = require( '@stdlib/array/buffer' ); + +var arr = new Float16Array( 5 ); +// returns + +var offset = arr.byteOffset; +// returns 0 + +var buf = new ArrayBuffer( 20 ); +arr = new Float16Array( buf, 10 ); +// returns + +offset = arr.byteOffset; +// returns 10 +``` + + + +#### Float16Array.prototype.BYTES_PER_ELEMENT + +Size (in bytes) of each array element. + +```javascript +var arr = new Float16Array( 5 ); +// returns + +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 2 +``` + + + +#### Float16Array.prototype.length + +Number of array elements. + +```javascript +var arr = new Float16Array( 5 ); +// returns + +var len = arr.length; +// returns 5 +``` + +* * * + +### Methods + + + +#### Float16Array.from( src\[, clbk\[, thisArg]] ) + +Creates a new 16-bit half-precision floating-point number array from an array-like object or an iterable. + +```javascript +var arr = Float16Array.from( [ 1.0, 2.0 ] ); +// returns + +var v = arr[ 0 ]; +// returns 1.0 + +v = arr[ 1 ]; +// returns 2.0 + +var len = arr.length; +// returns 2 +``` + +To invoke a function for each `src` value, provide a callback function. + +```javascript +var arr = Float16Array.from( [ 1.0, 2.0 ], clbk ); +// returns + +var v = arr[ 0 ]; +// returns 2.0 + +v = arr[ 1 ]; +// returns 4.0 + +var len = arr.length; +// returns 2 + +function clbk( v ) { + return v * 2.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 map( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr = Float16Array.from( [ 1.0, 2.0 ], map, ctx ); +// returns + +var v = arr[ 0 ]; +// returns 2.0 + +v = arr[ 1 ]; +// returns 4.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.of( element0\[, element1\[, ...elementN]] ) + +Creates a new 16-bit half-precision floating-point number array from a variable number of arguments. + +```javascript +var arr = Float16Array.of( 1.0, 2.0 ); +// returns + +var v = arr[ 0 ]; +// returns 1.0 + +v = arr[ 1 ]; +// returns 2.0 +``` + + + +#### Float16Array.prototype.at( i ) + +Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions. + +```javascript +var arr = new Float16Array( [ 10.0, 20.0, 30.0 ] ); + +var v = arr.at( 0 ); +// returns 10.0 + +v = arr.at( -1 ); +// returns 30.0 +``` + +If provided an out-of-bounds index, the method returns `undefined`. + +```javascript +var arr = new Float16Array( 10 ); + +var v = arr.at( 100 ); +// returns undefined + +v = arr.at( -100 ); +// returns undefined +``` + + + +#### 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 + +v = arr[ 2 ]; +// returns 3.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 + +v = arr[ 0 ]; +// returns 1.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 + +v = arr[ 0 ]; +// returns 1.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 +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + +#### Float16Array.prototype.every( predicate\[, thisArg] ) + +Returns a boolean indicating whether all elements pass a test. + +```javascript +function predicate( v ) { + return ( v < 0.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var bool = arr.every( predicate ); +// returns false + +arr = new Float16Array( [ -1.0, -2.0 ] ); + +bool = arr.every( predicate ); +// returns true +``` + +A `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function predicate( v ) { + this.count += 1; + return ( v > 0.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]] ) + +Returns a modified typed array filled with a fill 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] ) + +Returns a new array containing the elements of an array which pass a test implemented by a predicate function. + +```javascript +function predicate( v ) { + return ( v > 1.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.filter( predicate ); +// returns + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 3.0 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function predicate( v ) { + this.count += 1; + return ( v > 1.0 ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 2.0, 3.0 ] ); +var out = arr.filter( predicate, ctx ); +// returns + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 3.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.prototype.find( predicate\[, thisArg] ) + +Returns the first element in an array for which a predicate function returns a truthy value. + +```javascript +function predicate( v ) { + return ( v > 1.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.find( predicate ); +// returns 2.0 +``` + +A `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +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, 3.0 ] ); + +var v = arr.find( predicate, ctx ); +// returns 2.0 + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.prototype.findIndex( predicate\[, thisArg] ) + +Returns the index of the first element in an array for which a 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 idx = arr.findIndex( predicate ); +// returns 2 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function 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 -1 + +var n = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.findLast( predicate\[, thisArg] ) + +Returns the last element in an array for which a 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.findLast( predicate ); +// returns 3.0 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function 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.findLast( predicate, ctx ); +// returns 3.0 + +var count = ctx.count; +// returns 1 +``` + + + +#### Float16Array.prototype.findLastIndex( predicate\[, thisArg] ) + +Returns the index of the last element in an array for which a 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.findLastIndex( predicate ); +// returns 2 +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function 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.findLastIndex( predicate, ctx ); +// returns 2 + +var count = ctx.count; +// returns 1 +``` + + + +#### Float16Array.prototype.forEach( callbackFn\[, thisArg] ) + +Invokes a callback for each array element. + +```javascript +function log( v, i ) { + console.log( '%s: %s', i, v.toString() ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +arr.forEach( log ); +/* => + 0: 1 + 1: 2 + 2: 3 +*/ +``` + +The invoked function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function log( v, i ) { + this.count += 1; + console.log( '%s: %s', i, v.toString() ); +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +arr.forEach( log, ctx ); +/* => + 0: 1 + 1: 2 + 2: 3 +*/ + +var count = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.includes( searchElement\[, fromIndex] ) + +Returns a boolean indicating whether an array includes a provided value. + +```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 +``` + + + +#### Float16Array.prototype.indexOf( searchElement\[, fromIndex] ) + +Returns the first index at which a given element can be found. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.indexOf( 2.0 ); +// returns 1 + +idx = arr.indexOf( 3.0 ); +// returns 2 +``` + +If `searchElement` is not present in the array, the method returns `-1`. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var idx = arr.indexOf( 4.0 ); +// returns -1 +``` + + + +#### Float16Array.prototype.join( \[separator] ) + +Returns a new string by concatenating all array elements. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var str = arr.join(); +// returns '1,2,3' +``` + +By default, the method separates serialized array elements with a comma. To use an alternative 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 each index key in a typed array. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var it = arr.keys(); + +var v = it.next().value; +// returns 0 + +v = it.next().value; +// returns 1 + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + +#### Float16Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) + +Returns the last index at which a given element can be found. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 2.0 ] ); + +var idx = arr.lastIndexOf( 3.0 ); +// returns 2 + +idx = arr.lastIndexOf( 2.0 ); +// returns 4 + +idx = arr.lastIndexOf( 2.0, 2 ); +// returns 1 +``` + +If `searchElement` is not present in the array, the method returns `-1`. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var idx = arr.lastIndexOf( 3.0 ); +// returns -1 + +idx = arr.lastIndexOf( 2.0, 0 ); +// returns -1 +``` + + + +#### Float16Array.prototype.map( callbackFn\[, thisArg] ) + +Returns a new array with each element being the result of a provided callback function. + +```javascript +function scale( v ) { + return v * 2.0; +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.map( scale ); +// returns + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 4.0 + +v = out[ 2 ]; +// returns 6.0 +``` + +The callback function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function scale( v ) { + this.count += 1; + return v * 2.0; +} + +var ctx = { + 'count': 0 +}; + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.map( scale, ctx ); +// returns + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 4.0 + +v = out[ 2 ]; +// returns 6.0 + +var count = ctx.count; +// returns 3 +``` + + + +#### Float16Array.prototype.reduce( reducerFn\[, initialValue] ) + +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. + +```javascript +function fcn( acc, v ) { + return acc + ( v * v ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.reduce( fcn ); +// returns 14.0 +``` + +The reducer function is provided four arguments: + +- **acc**: accumulated result. +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. + +```javascript +function fcn( acc, v ) { + return acc + ( v * v ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.reduce( fcn, 0.0 ); +// returns 14.0 +``` + + + +#### Float16Array.prototype.reduceRight( reducerFn\[, initialValue] ) + +Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. + +```javascript +function fcn( acc, v ) { + return acc + ( v * v ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.reduceRight( fcn ); +// returns 8.0 +``` + +The reducer function is provided four arguments: + +- **acc**: accumulated result. +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. + +```javascript +function fcn( acc, v ) { + return acc + ( v * v ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var v = arr.reduceRight( fcn, 0.0 ); +// returns 14.0 +``` + + + +#### Float16Array.prototype.reverse() + +Reverses an array in-place. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +// Reverse the array: +arr.reverse(); + +var v = arr[ 0 ]; +// returns 3.0 + +v = arr[ 1 ]; +// returns 2.0 + +v = arr[ 2 ]; +// returns 1.0 +``` + + + +#### Float16Array.prototype.set( arr\[, offset] ) + +Sets one or more array elements. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); +// returns + +arr.set( [ 4.0, 5.0 ] ); + +var v = arr[ 0 ]; +// returns 4.0 + +v = arr[ 1 ]; +// returns 5.0 + +v = arr[ 2 ]; +// returns 3.0 +``` + +By default, the method sets array elements starting at position (index) `i = 0`. To set elements starting elsewhere in the array, provide an index argument `i`. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); +// returns + +// 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 +``` + +A few notes: + +- If `i` is out-of-bounds, the method throws an error. +- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. +- If provided a [typed array][@stdlib/array/typed] which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. + + + +#### Float16Array.prototype.slice( \[begin\[, end]] ) + +Copies a portion of a typed array to a new typed array. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.slice(); + +var len = out.length; +// returns 3 + +var v = out[ 0 ]; +// returns 1.0 + +v = out[ 1 ]; +// returns 2.0 + +v = out[ 2 ]; +// returns 3.0 +``` + +By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a `start` index (inclusive). + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.slice( 1 ); + +var len = out.length; +// returns 2 + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 3.0 +``` + +By default, the method returns a typed array which includes all array elements after `start`. To limit the number of array elements after `start`, provide an `end` index (exclusive). + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var out = arr.slice( 1, -1 ); + +var len = out.length; +// returns 2 + +var v = out[ 0 ]; +// returns 2.0 + +v = out[ 1 ]; +// returns 3.0 +``` + + + +#### Float16Array.prototype.some( predicate\[, thisArg] ) + +Returns a boolean indicating whether at least one element passes a test. + +```javascript +function predicate( v ) { + return ( v > 2.0 ); +} + +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var bool = arr.some( predicate ); +// returns true +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function 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 ] ); + +var bool = arr.some( predicate, ctx ); +// returns false + +var n = ctx.count; +// returns 2 +``` + + + +#### Float16Array.prototype.sort( \[compareFcn] ) + +Sorts an array in-place. + +```javascript +function compare( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + +var arr = new Float16Array( [ 2.0, 3.0, 1.0 ] ); + +arr.sort( compare ); + +var v = arr[ 0 ]; +// returns 1.0 + +v = arr[ 1 ]; +// returns 2.0 + +v = arr[ 2 ]; +// returns 3.0 +``` + +The `compareFcn` determines the order of the elements. The function is called with the following arguments: + +- **a**: the first element for comparison. +- **b**: the second element for comparison. + +The function should return a number where: + +- a negative value indicates that `a` should come before `b`. +- a positive value indicates that `a` should come after `b`. +- zero or `NaN` indicates that `a` and `b` are considered equal. + + + +#### 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 arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var subarr = arr.subarray(); +// returns + +var v = subarr[ 0 ]; +// returns 1.0 + +v = subarr[ 1 ]; +// returns 2.0 + +v = subarr[ 2 ]; +// returns 3.0 + +var len = subarr.length; +// returns 3 +``` + +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 arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var subarr = arr.subarray( 1 ); +// returns + +var v = subarr[ 0 ]; +// returns 2.0 + +v = subarr[ 1 ]; +// returns 3.0 + +var len = subarr.length; +// returns 2 +``` + +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 arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var subarr = arr.subarray( 1, -1 ); +// returns + +var v = subarr[ 0 ]; +// returns 2.0 + +v = subarr[ 1 ]; +// returns 3.0 + +var len = subarr.length; +// returns 2 +``` + + + +#### 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' +``` + +The method supports the following arguments: + +- **locales**: a string with a BCP 47 language tag or an array of such strings. +- **options**: configuration properties. + + + +#### Float16Array.prototype.toReversed() + +Returns a new typed array containing the elements in reversed order. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.toReversed(); +// returns + +var v = out[ 0 ]; +// returns 3.0 + +v = out[ 1 ]; +// returns 2.0 + +v = out[ 2 ]; +// returns 1.0 +``` + + + +#### Float16Array.prototype.toSorted( \[compareFcn] ) + +Returns a new typed array containing the elements in sorted order. + +```javascript +function compare( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + +var arr = new Float16Array( [ 2.0, 3.0, 1.0 ] ); + +var out = arr.toSorted( compare ); +// returns + +var v = out[ 0 ]; +// returns 1.0 + +v = out[ 1 ]; +// returns 2.0 + +v = out[ 2 ]; +// returns 3.0 +``` + +The `compareFcn` determines the order of the elements. The function is called with the following arguments: + +- **a**: the first element for comparison. +- **b**: the second element for comparison. + +The function should return a number where: + +- a negative value indicates that `a` should come before `b`. +- a positive value indicates that `a` should come after `b`. +- zero or `NaN` indicates that `a` and `b` are considered equal. + + + +#### 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 each value in a typed array. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0 ] ); + +var it = arr.values(); + +var v = it.next().value; +// returns 1.0 + +v = it.next().value; +// returns 2.0 + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + +#### Float16Array.prototype.with( index, value ) + +Returns a new typed array with the element at a provided index replaced with a provided value. + +```javascript +var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + +var out = arr.with( 0, 0.0 ); +// returns + +var v = out[ 0 ]; +// returns 0.0 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +* * * + +## Examples + + + +```javascript +var Uint16Array = require( '@stdlib/array/uint16' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float16Array = require( '@stdlib/array/float16' ); + +// Create a half-precision floating-point number array by specifying a length: +var out = new Float16Array( 3 ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array of numbers: +var arr = [ 1.05, 2.05, 3.05 ]; +out = new Float16Array( arr ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array buffer: +arr = new Uint16Array( [ 1000, 2000, 3000, 4000 ] ); +out = new Float16Array( arr.buffer ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array buffer view: +arr = new Uint16Array( [ 1000, 2000, 3000, 4000 ] ); +out = new Float16Array( arr.buffer, 2, 2 ); +logEach( '%s', out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.at.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.at.js new file mode 100644 index 000000000000..6a15bbe19b87 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.at.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::nonnegative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 0.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.at( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::negative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 1.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.at( -(i%N)-1 ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); 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..2736ce934e08 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:copyWithin', pkg ), function benchmark( b ) { + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return 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..3c880c500114 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.copy_within.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.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[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + 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( format( '%s:copyWithin:len=%d', pkg, len ), f ); + } +} + +main(); 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..b0f765e6d6dc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.entries.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:entries', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.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..5fe7184997b4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::this_context:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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..1ddd5911b507 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.every.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:every:len=%d', pkg, 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..848881b37c02 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:fill', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = [ 1.0, 2.0, 3.0 ]; + arr = new Float16Array( 2 ); + + 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 ( typeof out !== 'object' ) { + 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..14d82e2115f4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.fill.length.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +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 ]; + + 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 ( typeof out !== 'object' ) { + 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( format( '%s:fill:len=%d', pkg, 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..e117df96cdff --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); + +bench( format( '%s::this_context:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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..d4c52778e3dc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.filter.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s:filter:len=%d', pkg, 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..e1339df1ef9d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:find', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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( format( '%s::this_context:find', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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..b352bd20098e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:find:len=%d', pkg, 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..3ab5107f6d22 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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( format( '%s::this_context:findIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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..4536c3d68267 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_index.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:findIndex:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last.js new file mode 100644 index 000000000000..67626c3553f0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findLast', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( 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( format( '%s::this_context:findLast', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( 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_last.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last.length.js new file mode 100644 index 000000000000..f0909eba4214 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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.findLast( 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( format( '%s:findLast:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last_index.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last_index.js new file mode 100644 index 000000000000..2a83539d445d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last_index.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:findLastIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( 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( format( '%s::this_context:findLastIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( 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_last_index.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last_index.length.js new file mode 100644 index 000000000000..7398343b5c35 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.find_last_index.length.js @@ -0,0 +1,110 @@ +/** + * @license Apache-2.0 +* +* Copyright (c) 2026 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 stdlib/jsdoc-typedef-typos */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {boolean} value - array element +* @param {NonNegativeInteger} idx - array element index +* @param {Float16Array} arr - array instance +* @returns {boolean} boolean indicating whether a value 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( uniform( len, 0.0, 10.0 ) ); + 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.findLastIndex( 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( format( '%s:findLastIndex:len=%d', pkg, 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..ee07819a1017 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + 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( format( '%s::this_context:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + 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..3897c1e3e5cc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.for_each.length.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:forEach:len=%d', pkg, 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..d6d5ef85cf0c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.from.js @@ -0,0 +1,238 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::typed_array:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( uniform( 2, 0.0, 10.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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::typed_array,clbk:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( uniform( 2, 0.0, 10.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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::array:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::array,clbk:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::iterable:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + 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( format( '%s::iterable,clbk:from:', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + 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.get.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.get.js new file mode 100644 index 000000000000..86f6c3a2035a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.get.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:get', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 0.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr[ i%N ]; + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); 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..06f67b600586 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:includes', pkg ), 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..d304639202bb --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.includes.length.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +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( format( '%s:includes:len=%d', pkg, 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..88df5aafc09e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:indexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.indexOf( 11.0 ); + if ( typeof out !== 'number' ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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..e3f3c575be1a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.index_of.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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.indexOf( 11.0 ); + if ( typeof out !== 'number' ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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( format( '%s:indexOf:len=%d', pkg, 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..35dec5015f5c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:join', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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..1cf958fa1a4d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.join.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:join:len=%d', pkg, 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..54a9b694b812 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.js @@ -0,0 +1,338 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float16Array; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,length', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,typed_array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Uint16Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,iterable', pkg ), opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( format( '%s::instantiation,arraybuffer', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,arraybuffer,byte_offset', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::instantiation,arraybuffer,byte_offset,length', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::get:buffer', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::get:byteLength', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::get:byteOffset', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::get:length', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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.keys.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js new file mode 100644 index 000000000000..ca4c38fcb097 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:keys', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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.keys.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.length.js new file mode 100644 index 000000000000..8838fc0b8ec4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.keys.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var iter; + var i; + + 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 ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + 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( format( '%s:keys:len=%d', pkg, len ), f ); + } +} + +main(); 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..2c6e3e426e73 --- /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) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:lastIndexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( 11.0 ); + 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..0c4de2ed170c --- /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) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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.lastIndexOf( 11.0 ); + 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( format( '%s:lastIndexOf:len=%d', pkg, 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..925e727f7b33 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.length.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +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 ) { + 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 Float16Array( len ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( typeof arr !== 'object' ) { + 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( format( '%s:len=%d', pkg, 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..253d75e3d35b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:map', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::this_context:map', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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..4b582f84c2fe --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.map.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s:map:len=%d', pkg, 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..7aa34aeaaf77 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.of.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:of', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + 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..7d5aa2177a44 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::initial_value:reduce', pkg ), 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..cedeb919e3ea --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:reduce:len=%d', pkg, 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..a0022c45ae95 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reduceRight', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::initial_value:reduceRight', pkg ), 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..62375889fb0c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reduce_right.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:reduceRight:len=%d', pkg, 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..1a39a346989f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reverse', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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..60be96f0f1f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.reverse.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s:reverse:len=%d', pkg, 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..80347d4b23c9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::array:set', pkg ), 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( format( '%s::typed_array:set', pkg ), 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..276aee216852 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.set.length.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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; + + arr1 = uniform( len, 0.0, 10.0 ); + arr2 = uniform( len, 0.0, 10.0 ); + 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( format( '%s:set:len=%d', pkg, 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..2697530e9cfa --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:slice', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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..bdc9fb4b2fb9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.slice.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s:slice:len=%d', pkg, 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..4583740bc0b0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:some', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::this_context:some', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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..8042e6870c27 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.some.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:some:len=%d', pkg, 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..343353336cbc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:sort', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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..56f6e14d9091 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.sort.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ] = i; + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s:sort:len=%d', pkg, 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..14713fcd87be --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:subarray', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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..ebe5ef5ea171 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.subarray.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s:subarray:len=%d', pkg, 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..aeb8e36488c4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:toLocaleString', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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..6025417c1ffb --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_locale_string.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:toLocaleString:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.js new file mode 100644 index 000000000000..6a3102101e64 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:toReversed', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.length.js new file mode 100644 index 000000000000..80b8f755fa38 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_reversed.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s:toReversed:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.js new file mode 100644 index 000000000000..8fb15729f9e2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:toSorted', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toSorted(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.length.js new file mode 100644 index 000000000000..74a3d66a910e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_sorted.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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 ] = i; + out = arr.toSorted(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a isFloat16Array' ); + } + 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( format( '%s:toSorted:len=%d', pkg, 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..9839b2e6bce8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:toString', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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..d36d2b6acc47 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.to_string.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s:toString:len=%d', pkg, 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..2b2ed7642e0e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:values', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/benchmark/benchmark.values.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.length.js new file mode 100644 index 000000000000..a2b4c0e4299a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.values.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var iter; + var i; + + 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 ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + 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( format( '%s:values:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.js new file mode 100644 index 000000000000..219e975c11f5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Float16Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:with', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = uniform( 2, 0.0, 1.0 ); + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.with( i%arr.length, values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.length.js new file mode 100644 index 000000000000..c507a053f825 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/benchmark.with.length.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +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( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var values; + var out; + var i; + + values = uniform( 2, 0.0, 1.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.with( i%len, values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s:with:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.at.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.at.js new file mode 100644 index 000000000000..59ff43e39ee2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.at.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill::nonnegative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 0.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.at( i%N ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::negative_indices:at', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 1.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr.at( -(i%N)-1 ); + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.js new file mode 100644 index 000000000000..65f474fd0bf3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:copyWithin', pkg ), function benchmark( b ) { + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.length.js new file mode 100644 index 000000000000..1bef96d9a163 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.copy_within.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.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[ 0 ] = i; + arr = arr.copyWithin( 1, 0 ); + if ( arr[ 0 ] !== arr[ 0 ] ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( arr[ 0 ] !== arr[ 0 ] ) { + 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( format( '%s::polyfill:copyWithin:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.entries.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.entries.js new file mode 100644 index 000000000000..739ef42377c7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.entries.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:entries', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.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/polyfill/benchmark.every.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.every.js new file mode 100644 index 000000000000..dd04b2c9965e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.every.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::polyfill::this_context:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.every.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.every.length.js new file mode 100644 index 000000000000..c1dffabd7717 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.every.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:every:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.js new file mode 100644 index 000000000000..ade4f7b24ee0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:fill', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = [ 1.0, 2.0, 3.0 ]; + arr = new Float16Array( 2 ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.length.js new file mode 100644 index 000000000000..541d369697fe --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.fill.length.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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 ]; + + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:fill:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.filter.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.filter.js new file mode 100644 index 000000000000..75191e0fd2a6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.filter.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return v >= 0.0; + } +}); + +bench( format( '%s::polyfill::this_context:filter', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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/polyfill/benchmark.filter.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.filter.length.js new file mode 100644 index 000000000000..7967a701ed89 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.filter.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:filter:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find.js new file mode 100644 index 000000000000..7629e698c5ca --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:find', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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( format( '%s::polyfill::this_context:find', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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/polyfill/benchmark.find.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find.length.js new file mode 100644 index 000000000000..4f3bbc1d1364 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:find:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_index.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_index.js new file mode 100644 index 000000000000..f07b271b6626 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_index.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:findIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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( format( '%s::polyfill::this_context:findIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // 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/polyfill/benchmark.find_index.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_index.length.js new file mode 100644 index 000000000000..ad499fef9989 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_index.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:findIndex:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last.js new file mode 100644 index 000000000000..5c9e74d1bb0c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:findLast', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( 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( format( '%s::polyfill::this_context:findLast', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLast( 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/polyfill/benchmark.find_last.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last.length.js new file mode 100644 index 000000000000..43d981b79adf --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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.findLast( 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( format( '%s::polyfill:findLast:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last_index.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last_index.js new file mode 100644 index 000000000000..2cd0587c3d4a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last_index.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:findLastIndex', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( 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( format( '%s::polyfill::this_context:findLastIndex', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.findLastIndex( 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/polyfill/benchmark.find_last_index.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last_index.length.js new file mode 100644 index 000000000000..10b779b36ff6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.find_last_index.length.js @@ -0,0 +1,110 @@ +/** + * @license Apache-2.0 +* +* Copyright (c) 2026 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 stdlib/jsdoc-typedef-typos */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {boolean} value - array element +* @param {NonNegativeInteger} idx - array element index +* @param {Float16Array} arr - array instance +* @returns {boolean} boolean indicating whether a value 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( uniform( len, 0.0, 10.0 ) ); + 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.findLastIndex( 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( format( '%s::polyfill:findLastIndex:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.for_each.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.for_each.js new file mode 100644 index 000000000000..3132b1571e98 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.for_each.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + 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( format( '%s::polyfill::this_context:forEach', pkg ), function benchmark( b ) { + var count; + var arr; + var N; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + 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/polyfill/benchmark.for_each.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.for_each.length.js new file mode 100644 index 000000000000..fd96656d42ae --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.for_each.length.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:forEach:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.from.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.from.js new file mode 100644 index 000000000000..02acdcf6185a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.from.js @@ -0,0 +1,238 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::polyfill::typed_array:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( uniform( 2, 0.0, 10.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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::typed_array,clbk:from', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Float16Array( uniform( 2, 0.0, 10.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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::polyfill::array:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::array,clbk:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function clbk( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::polyfill::iterable:from', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + 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( format( '%s::polyfill::iterable,clbk:from:', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + 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/polyfill/benchmark.get.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.get.js new file mode 100644 index 000000000000..cc3392e71e0d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.get.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:get', pkg ), function benchmark( b ) { + var arr; + var N; + var v; + var i; + + arr = new Float16Array( uniform( 10, 0.0, 10.0 ) ); + N = arr.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = arr[ i%N ]; + if ( typeof v !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.includes.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.includes.js new file mode 100644 index 000000000000..e30d6d313a43 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.includes.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:includes', pkg ), 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/polyfill/benchmark.includes.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.includes.length.js new file mode 100644 index 000000000000..3dbcb511c59c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.includes.length.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( format( '%s::polyfill:includes:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.js new file mode 100644 index 000000000000..8c8977d72b51 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:indexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.indexOf( 11.0 ); + if ( typeof out !== 'number' ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.length.js new file mode 100644 index 000000000000..620fa2a4e4e5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.index_of.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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.indexOf( 11.0 ); + if ( typeof out !== 'number' ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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( format( '%s::polyfill:indexOf:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.join.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.join.js new file mode 100644 index 000000000000..ec6e3e152764 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.join.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:join', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.join.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.join.length.js new file mode 100644 index 000000000000..49ba40bdf5b3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.join.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:join:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.js new file mode 100644 index 000000000000..fe20e4c20fbd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.js @@ -0,0 +1,338 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// VARIABLES // + +var opts = { + 'skip': ( ITERATOR_SYMBOL === null ) +}; + + +// MAIN // + +bench( format( '%s::polyfill::instantiation,new', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,no_new', pkg ), function benchmark( b ) { + var ctor; + var arr; + var i; + + ctor = Float16Array; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = ctor(); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,length', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,typed_array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new Uint16Array( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,array', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = []; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,iterable', pkg ), opts, function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( createIterable() ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function createIterable() { + var out = {}; + out[ ITERATOR_SYMBOL ] = iterator; + return out; + + function iterator() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +bench( format( '%s::polyfill::instantiation,arraybuffer', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,arraybuffer,byte_offset', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf, 8 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::instantiation,arraybuffer,byte_offset,length', pkg ), function benchmark( b ) { + var buf; + var arr; + var i; + + buf = new ArrayBuffer( 8 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = new Float16Array( buf, 8, 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !(arr instanceof Float16Array) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::polyfill::get:buffer', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::polyfill::get:byteLength', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::polyfill::get:byteOffset', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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( format( '%s::polyfill::get:length', pkg ), function benchmark( b ) { + var arr; + var v; + var i; + + arr = new Float16Array(); + + 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/polyfill/benchmark.keys.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.keys.js new file mode 100644 index 000000000000..47c222a9f6b5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.keys.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:keys', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.keys.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.keys.length.js new file mode 100644 index 000000000000..93ada4392b3d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.keys.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var iter; + var i; + + 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 ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + 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( format( '%s::polyfill:keys:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.last_index_of.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.last_index_of.js new file mode 100644 index 000000000000..b1aace73ebd7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.last_index_of.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:lastIndexOf', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + // Benchmark worst case scenario... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.lastIndexOf( 11.0 ); + 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/polyfill/benchmark.last_index_of.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.last_index_of.length.js new file mode 100644 index 000000000000..e7629503b698 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.last_index_of.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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.lastIndexOf( 11.0 ); + 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( format( '%s::polyfill:lastIndexOf:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.length.js new file mode 100644 index 000000000000..569c2d65999a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.length.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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 Float16Array( len ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( typeof arr !== 'object' ) { + 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( format( '%s::polyfill:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.map.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.map.js new file mode 100644 index 000000000000..79cfceebae80 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.map.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:map', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function fcn( v ) { + return v + 1.0; + } +}); + +bench( format( '%s::polyfill::this_context:map', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + 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/polyfill/benchmark.map.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.map.length.js new file mode 100644 index 000000000000..84882bb41c70 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.map.length.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:map:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.of.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.of.js new file mode 100644 index 000000000000..09e373c43de5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.of.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:of', pkg ), 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 ( typeof arr !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce.js new file mode 100644 index 000000000000..32763c0921f7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::polyfill::initial_value:reduce', pkg ), 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/polyfill/benchmark.reduce.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce.length.js new file mode 100644 index 000000000000..9441805ac6de --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:reduce:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce_right.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce_right.js new file mode 100644 index 000000000000..0de3eecf637f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce_right.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:reduceRight', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::polyfill::initial_value:reduceRight', pkg ), 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/polyfill/benchmark.reduce_right.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce_right.length.js new file mode 100644 index 000000000000..82ac40b5cc1a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reduce_right.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:reduceRight:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.js new file mode 100644 index 000000000000..50ee5364f5b4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:reverse', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.length.js new file mode 100644 index 000000000000..2eb7672b2a89 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.reverse.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:reverse:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.set.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.set.js new file mode 100644 index 000000000000..71659cb3a045 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.set.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill::array:set', pkg ), 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( format( '%s::polyfill::typed_array:set', pkg ), 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/polyfill/benchmark.set.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.set.length.js new file mode 100644 index 000000000000..5f4c82d57f7e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.set.length.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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; + + arr1 = uniform( len, 0.0, 10.0 ); + arr2 = uniform( len, 0.0, 10.0 ); + 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( format( '%s::polyfill:set:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.js new file mode 100644 index 000000000000..369fa9f34524 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:slice', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.length.js new file mode 100644 index 000000000000..d538325cf4af --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.slice.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:slice:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.some.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.some.js new file mode 100644 index 000000000000..0b982f4f37a0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.some.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:some', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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( format( '%s::polyfill::this_context:some', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.some.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.some.length.js new file mode 100644 index 000000000000..4a601fa42695 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.some.length.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// 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( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:some:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.js new file mode 100644 index 000000000000..fd6e177ade41 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:sort', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.length.js new file mode 100644 index 000000000000..323d197198de --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.sort.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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 ] = i; + out = arr.sort(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:sort:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.js new file mode 100644 index 000000000000..27008c088442 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:subarray', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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 ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.length.js new file mode 100644 index 000000000000..33a57eee67a0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.subarray.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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 ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:subarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_locale_string.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_locale_string.js new file mode 100644 index 000000000000..b4caf76cb508 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_locale_string.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:toLocaleString', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.to_locale_string.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_locale_string.length.js new file mode 100644 index 000000000000..1e4e341ef3ef --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_locale_string.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:toLocaleString:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.js new file mode 100644 index 000000000000..2b8f17f0d7d9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:toReversed', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.length.js new file mode 100644 index 000000000000..453ca4ac90de --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_reversed.length.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:toReversed:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.js new file mode 100644 index 000000000000..099e32714ee4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:toSorted', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 0 ] = i; + out = arr.toSorted(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.length.js new file mode 100644 index 000000000000..b9badf469c3b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_sorted.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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 ] = i; + out = arr.toSorted(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a isFloat16Array' ); + } + 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( format( '%s::polyfill:toSorted:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_string.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_string.js new file mode 100644 index 000000000000..d434fa081724 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_string.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:toString', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/polyfill/benchmark.to_string.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_string.length.js new file mode 100644 index 000000000000..a4d6ee77a157 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.to_string.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + 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( format( '%s::polyfill:toString:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.values.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.values.js new file mode 100644 index 000000000000..f5de94b540c5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.values.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:values', pkg ), function benchmark( b ) { + var iter; + var arr; + var i; + + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + 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/benchmark/polyfill/benchmark.values.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.values.length.js new file mode 100644 index 000000000000..1b72ec5166d2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.values.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var iter; + var i; + + 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 ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + 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( format( '%s::polyfill:values:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.js new file mode 100644 index 000000000000..9d02db03f64e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// MAIN // + +bench( format( '%s::polyfill:with', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = uniform( 2, 0.0, 1.0 ); + arr = new Float16Array( uniform( 2, 0.0, 10.0 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.with( i%arr.length, values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return a Float16Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.length.js b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.length.js new file mode 100644 index 000000000000..e678e9deec5e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/benchmark/polyfill/benchmark.with.length.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../../package.json' ).name; +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float16Array( uniform( len, 0.0, 10.0 ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var values; + var out; + var i; + + values = uniform( 2, 0.0, 1.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.with( i%len, values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + 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( format( '%s::polyfill:with:len=%d', pkg, len ), f ); + } +} + +main(); 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..e3117420348b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/repl.txt @@ -0,0 +1,1222 @@ + +{{alias}}() + A 16-bit half-precision floating-point number array. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}() + + + +{{alias}}( length ) + Creates a half-precision floating-point number array having a specified + length. + + Parameters + ---------- + length: integer + Typed array length. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + + > var len = arr.length + 5 + + +{{alias}}( typedarray ) + Creates a half-precision floating-point number array from a typed array. + + Parameters + ---------- + typedarray: TypedArray + Typed array from which to generate a half-precision floating-point + number array. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var buf = new {{alias:@stdlib/array/float64}}( [ 0.5, 0.5, 0.5 ] ) + + > var arr = new {{alias}}( buf ) + + > var len = arr.length + 3 + + +{{alias}}( obj ) + Creates a half-precision floating-point number array from an array-like + object or iterable. + + Parameters + ---------- + obj: Object + Array-like object or iterable from which to generate a half-precision + floating-point number array. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > var arr = new {{alias}}( [ 0.5, 0.5, 0.5 ] ) + + > var len = arr.length + 3 + + +{{alias}}( buffer[, byteOffset[, length]] ) + Returns a half-precision floating-point number 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}}( 8 ); + > var arr1 = new {{alias}}( buf ) + + > var len = arr1.length + 4 + > var arr2 = new {{alias}}( buf, 2 ) + + > len = arr2.length + 3 + > var arr3 = new {{alias}}( buf, 2, 2 ) + + > len = arr3.length + 2 + + +{{alias}}.from( src[, clbk[, thisArg]] ) + Creates a new half-precision floating-point number array from an array-like + object or an iterable. + + A callback function is provided two arguments: + + - value: source value. + - index: source index. + + Parameters + ---------- + src: ArrayLike|Iterable + Source of array elements. + + clbk: Function (optional) + Callback to invoke for each source element. + + thisArg: Any (optional) + Callback execution context. + + Returns + ------- + out: Float16Array + A typed array. + + Examples + -------- + > function clbkFcn( v ) { return v * 2.0 }; + > var arr = {{alias}}.from( [ 1.0, -1.0 ], clbkFcn ) + + > var len = arr.length + 2 + > var v = arr[ 0 ] + 2.0 + > v = arr[ 1 ] + -2.0 + + +{{alias}}.of( element0[, element1[, ...elementN]] ) + Creates a new half-precision floating-point number 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( 1.0, -1.0 ) + + > var len = arr.length + 2 + > var v = arr[ 0 ] + 1.0 + > v = arr[ 1 ] + -1.0 + + +{{alias}}.BYTES_PER_ELEMENT + The size of each array element in bytes. + + Examples + -------- + > var nbytes = {{alias}}.BYTES_PER_ELEMENT + 2 + + +{{alias}}.name + Typed array constructor name. + + Examples + -------- + > var str = {{alias}}.name + 'Float16Array' + + +{{alias}}.prototype.buffer + Pointer to the underlying data buffer. + + Examples + -------- + > var arr = new {{alias}}( 2 ) + + > var buf = arr.buffer + + + +{{alias}}.prototype.byteLength + Length of the array in bytes. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + + > var nbytes = arr.byteLength + 10 + + +{{alias}}.prototype.byteOffset + Offset (in bytes) of the array from the start of its underlying ArrayBuffer. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + + > var offset = arr.byteOffset + 0 + > var buf = new {{alias:@stdlib/array/buffer}}( 20 ); + > arr = new {{alias}}( buf, 10 ) + + > offset = arr.byteOffset + 10 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Size (in bytes) of each array element. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + + > arr.BYTES_PER_ELEMENT + 2 + + +{{alias}}.prototype.length + The number of array elements. + + Examples + -------- + > var arr = new {{alias}}( 5 ) + + > var len = arr.length + 5 + + +{{alias}}.prototype.at( i ) + Returns an array element located at integer position (index) `i`, with + support for both nonnegative and negative integer positions. + + If provided an index outside the array index range, the method returns + `undefined`. + + Parameters + ---------- + i: integer + Element index. + + Returns + ------- + out: float|void + An array element. + + Examples + -------- + > var arr = new {{alias}}( [ 10.0, 20.0, 30.0 ] ) + + > var v = arr.at( 0 ) + 10.0 + > v = arr.at( -1 ) + 30.0 + + +{{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}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) + + > arr.copyWithin( 0, 3 ) + + > var v = arr[ 0 ] + 4.0 + > v = arr[ 1 ] + 5.0 + + +{{alias}}.prototype.entries() + Returns an iterator for iterating over array key-value pairs. + + Returns + ------- + iterator: Iterator + Iterator for iterating over array key-value pairs. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var it = arr.entries(); + > var v = it.next().value + [ 0, 1.0 ] + > v = it.next().value + [ 1, 2.0 ] + > v = it.next().value + [ 2, 3.0 ] + > var bool = it.next().done + true + + +{{alias}}.prototype.every( predicate[, thisArg] ) + Returns a boolean indicating whether all elements in the array pass a test. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether all elements pass the test. + + Examples + -------- + > function predicate( v ) { return ( v > 0.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0 ] ) + + > var bool = arr.every( predicate ) + true + + +{{alias}}.prototype.fill( value[, start[, end]] ) + Returns a modified typed array filled with a fill 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}}( 3 ) + + > arr.fill( 2.0 ); + > var v = arr[ 0 ] + 2.0 + > v = arr[ 1 ] + 2.0 + > v = arr[ 2 ] + 2.0 + + +{{alias}}.prototype.filter( predicate[, thisArg] ) + Returns a new array containing the elements of an array which pass a test + implemented by a predicate function. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + The returned array has the same data type as the host array. + + 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) + Execution context. + + Returns + ------- + out: Float16Array + A new typed array. + + Examples + -------- + > function predicate( v ) { return ( v > 1.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var out = arr.filter( predicate ) + + > var len = out.length + 2 + > var v = out[ 0 ] + 2.0 + > v = out[ 1 ] + 3.0 + + +{{alias}}.prototype.find( predicate[, thisArg] ) + Returns the first element in an array for which a predicate function + returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + out: number|void + Array element or `undefined`. + + Examples + -------- + > function predicate( v ) { return ( v > 1.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var v = arr.find( predicate ) + 2.0 + + +{{alias}}.prototype.findIndex( predicate[, thisArg] ) + Returns the index of the first element in an array for which a predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > function predicate( v ) { return ( v > 2.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var idx = arr.findIndex( predicate ) + 2 + + +{{alias}}.prototype.findLast( predicate[, thisArg] ) + Returns the last element in an array for which a predicate function returns + a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + out: number|void + Array element or `undefined`. + + Examples + -------- + > function predicate( v ) { return ( v > 1.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var v = arr.findLast( predicate ) + 3.0 + + +{{alias}}.prototype.findLastIndex( predicate[, thisArg] ) + Returns the index of the last element in an array for which a predicate + function returns a truthy value. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > function predicate( v ) { return ( v > 1.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var idx = arr.findLastIndex( predicate ) + 2 + + +{{alias}}.prototype.forEach( clbk[, thisArg] ) + Invokes a function once for each array element. + + A callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + Parameters + ---------- + clbk: Function + Function to invoke for each array element. + + thisArg: Any (optional) + Execution context. + + Examples + -------- + > var str = '%'; + > function clbk( v ) { str += v.toString() + '%'; }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > arr.forEach( clbk ); + > str + '%1%2%3%' + + +{{alias}}.prototype.includes( searchElement[, fromIndex] ) + Returns a boolean indicating whether an array includes a provided value. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index at which to start the search. 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, 2.0, 3.0 ] ) + + > var bool = arr.includes( 3.0 ) + true + > bool = arr.includes( 3.0, 3 ) + false + + +{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) + Returns the first index at which a given element can be found. + + If method does not find a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index at which to start the search. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: 0. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var idx = arr.indexOf( 2.0 ) + 1 + > idx = arr.indexOf( 2.0, 2 ) + -1 + + +{{alias}}.prototype.join( [separator] ) + Returns a new string by concatenating all array elements separated by a + separator string. + + Parameters + ---------- + separator: string (optional) + Separator string. Default: ','. + + Returns + ------- + out: string + Array serialized as a string. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var str = arr.join() + '1,2,3' + > str = arr.join( '|' ) + '1|2|3' + + +{{alias}}.prototype.keys() + Returns an iterator for iterating over each index key in a typed array. + + Returns + ------- + iterator: Iterator + Iterator for iterating over array index keys. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0 ] ) + + > var it = arr.keys(); + > var v = it.next().value + 0 + > v = it.next().value + 1 + > v = it.next().done + true + + +{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) + Returns the last index at which a given element can be found. + + If method does not find a search element, the method returns `-1`. + + Parameters + ---------- + searchElement: number + Search element. + + fromIndex: integer (optional) + Array index at which to start the search. If provided a negative value, + the method resolves the start index relative to the last array element. + Default: out.length-1. + + Returns + ------- + out: integer + Array index or `-1`. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0, 1.0 ] ) + + > var idx = arr.lastIndexOf( 1.0 ) + 3 + > idx = arr.lastIndexOf( 1.0, 2 ) + 0 + + +{{alias}}.prototype.map( clbk[, thisArg] ) + Returns a new array with each element being the result of a provided + callback function. + + A callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + The returned array has the same data type as the host array. + + Parameters + ---------- + clbk: Function + Function which maps array elements to elements in the new array. + + thisArg: Any (optional) + Execution context. + + Returns + ------- + out: Float16Array + A new typed array. + + Examples + -------- + > function clbk( v ) { return v * 2.0; }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var out = arr.map( clbk ) + + > var v = out[ 0 ] + 2.0 + > v = out[ 1 ] + 4.0 + > v = out[ 2 ] + 6.0 + + +{{alias}}.prototype.reduce( reducerFn[, initialValue] ) + Applies a provided 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. + + A reducer function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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 + ---------- + reducerFn: Function + Function to apply to each array element. + + initialValue: any (optional) + Initial accumulation value. + + Returns + ------- + out: any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > function reducerFn( acc, v ) { return acc + v; }; + > var v = arr.reduce( reducerFn, 0.0 ) + 6.0 + + +{{alias}}.prototype.reduceRight( reducerFn[, initialValue] ) + Applies a provided 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. + + A reducer function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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 + ---------- + reducerFn: Function + Function to apply to each array element. + + initialValue: any (optional) + Initial accumulation value. + + Returns + ------- + out: any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > function reducerFn( acc, v ) { return acc + v; }; + > var v = arr.reduceRight( reducerFn, 0.0 ) + 6.0 + + +{{alias}}.prototype.reverse() + Reverses the 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, 2.0, 3.0 ] ) + + > arr.reverse(); + > var v = arr[ 0 ] + 3.0 + > v = arr[ 1 ] + 2.0 + > v = arr[ 2 ] + 1.0 + + +{{alias}}.prototype.set( arr[, offset] ) + Sets one or more array elements. + + If provided a single argument, the method sets array elements starting at + position (index) `i = 0`. To set elements starting elsewhere in the array, + provide an offset argument. + + 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, 2.0, 3.0 ] ) + + > arr.set( [ 4.0, 5.0 ], 1 ); + > var v = arr[ 0 ] + 1.0 + > v = arr[ 1 ] + 4.0 + > v = arr[ 2 ] + 5.0 + + +{{alias}}.prototype.slice( [start[, end]] ) + Copies a portion of a typed array to a new typed array. + + Parameters + ---------- + 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 + New typed array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var out = arr.slice( 1 ) + + > var len = out.length + 2 + > var v = out[ 0 ] + 2.0 + > v = out[ 1 ] + 3.0 + + +{{alias}}.prototype.some( predicate[, thisArg] ) + Returns a boolean indicating whether at least one element passes a test. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + 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) + Execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether at least one element passes the test. + + Examples + -------- + > function predicate( v ) { return ( v > 2.0 ); }; + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var bool = arr.some( predicate ) + true + + +{{alias}}.prototype.sort( [compareFunction] ) + Sorts an array in-place. + + A comparison function determines the order of the array elements. The + function is provided two arguments: + + - a: first element for comparison. + - b: second element for comparison. + + The function should return a value less than zero if `a` comes before `b`, + a value greater than zero if `a` comes after `b`, and zero if `a` and `b` + are equivalent. + + Parameters + ---------- + compareFunction: Function (optional) + Comparison function. + + Returns + ------- + out: Float16Array + Modified array. + + Examples + -------- + > function compare( a, b ) { return a - b; }; + > var arr = new {{alias}}( [ 2.0, 3.0, 1.0 ] ) + + > arr.sort( compare ); + > var v = arr[ 0 ] + 1.0 + > v = arr[ 1 ] + 2.0 + > v = arr[ 2 ] + 3.0 + + +{{alias}}.prototype.subarray( [begin[, end]] ) + Creates a new typed array view over the same underlying `ArrayBuffer` and + with the same underlying data type as the host array. + + Parameters + ---------- + begin: 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 + New typed array view. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) + + > var out = arr.subarray( 1, 3 ) + + > var len = out.length + 2 + > var v = out[ 0 ] + 2.0 + > v = out[ 1 ] + 3.0 + + +{{alias}}.prototype.toLocaleString( [locales[, options]] ) + Serializes an array as a locale-specific string. + + Parameters + ---------- + locales: string|Array (optional) + Locale identifier(s). + + options: Object (optional) + An object containing serialization options. + + Returns + ------- + str: string + Local-specific string. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var str = arr.toLocaleString() + '1,2,3' + + +{{alias}}.prototype.toReversed() + Returns a new typed array containing the elements in reversed order. + + Returns + ------- + out: Float16Array + New typed array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var out = arr.toReversed() + + > var v = out[ 0 ] + 3.0 + > v = out[ 1 ] + 2.0 + > v = out[ 2 ] + 1.0 + + +{{alias}}.prototype.toSorted( [compareFcn] ) + Returns a new typed array containing the elements in sorted order. + + A comparison function determines the order of the array elements. The + function is provided two arguments: + + - a: first element for comparison. + - b: second element for comparison. + + The function should return a value less than zero if `a` comes before `b`, + a value greater than zero if `a` comes after `b`, and zero if `a` and `b` + are equivalent. + + Parameters + ---------- + compareFcn: Function (optional) + Comparison function. + + Returns + ------- + out: Float16Array + New typed array. + + Examples + -------- + > function compare( a, b ) { return a - b; }; + > var arr = new {{alias}}( [ 2.0, 3.0, 1.0 ] ) + + > var out = arr.toSorted( compare ); + > var v = out[ 0 ] + 1.0 + > v = out[ 1 ] + 2.0 + > v = out[ 2 ] + 3.0 + + +{{alias}}.prototype.toString() + Serializes an array as a string. + + Returns + ------- + str: string + String serialization of the array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var str = arr.toString() + '1,2,3' + + +{{alias}}.prototype.values() + Returns an iterator for iterating over each value in a typed array. + + Returns + ------- + iterator: Iterator + Iterator for iterating over array values. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0 ] ) + + > var it = arr.values(); + > var v = it.next().value + 1.0 + > v = it.next().value + 2.0 + > var bool = it.next().done + true + + +{{alias}}.prototype.with( index, value ) + Returns a new typed array with the element at a provided index replaced with + a provided value. + + Parameters + ---------- + index: integer + Element index. + + value: number + Element value. + + Returns + ------- + out: Float16Array + New typed array. + + Examples + -------- + > var arr = new {{alias}}( [ 1.0, 2.0, 3.0 ] ) + + > var out = arr.with( 1, 4.0 ) + + > var v = out[ 1 ] + 4.0 + + + 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..dde3e0aecc35 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/types/index.d.ts @@ -0,0 +1,1312 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 max-lines */ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator, TypedIterator } from '@stdlib/types/iter'; +import { ArrayLike } from '@stdlib/types/array'; +import ArrayBuffer = require( '@stdlib/array/buffer' ); + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Locale-specific configuration options. +*/ +interface LocaleOptions { + /** + * Configuration property. + */ + [ key: string | symbol | number ]: T | undefined; +} + +/** +* Callback invoked for each element in a source object. +* +* @returns transformed value +*/ +type FromNullary = ( this: U ) => number; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @returns transformed value +*/ +type FromUnary = ( this: U, value: number ) => number; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @param index - source element index +* @returns transformed value +*/ +type FromBinary = ( this: U, value: number, index: number ) => number; + +/** +* Callback invoked for each element in a source object. +* +* @param value - source element +* @param index - source element index +* @returns transformed value +*/ +type FromCallback = FromNullary | FromUnary | FromBinary; + +/** +* Checks whether an element in an array passes a test. +* +* @returns boolean indicating whether an element in an array passes a test +*/ +type NullaryPredicate = ( this: U ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element in an array passes a test +*/ +type UnaryPredicate = ( this: U, value: number ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @returns boolean indicating whether an element in an array passes a test +*/ +type BinaryPredicate = ( this: U, value: number, index: number ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns boolean indicating whether an element in an array passes a test +*/ +type TernaryPredicate = ( this: U, value: number, index: number, arr: Float16Array ) => boolean; + +/** +* Checks whether an element in an array passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns boolean indicating whether an element in an array passes a test +*/ +type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; + +/** +* Callback invoked for each element in an array. +* +* @returns undefined +*/ +type NullaryCallback = ( this: U ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @returns undefined +*/ +type UnaryCallback = ( this: U, value: number ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @returns undefined +*/ +type BinaryCallback = ( this: U, value: number, index: number ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns undefined +*/ +type TernaryCallback = ( this: U, value: number, index: number, arr: Float16Array ) => void; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns undefined +*/ +type Callback = NullaryCallback | UnaryCallback | BinaryCallback | TernaryCallback; + +/** +* Callback invoked for each element in an array. +* +* @returns returned value +*/ +type NullaryMapFcn = ( this: U ) => number; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @returns returned value +*/ +type UnaryMapFcn = ( this: U, value: number ) => number; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @returns returned value +*/ +type BinaryMapFcn = ( this: U, value: number, index: number ) => number; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns returned value +*/ +type TernaryMapFcn = ( this: U, value: number, index: number, arr: Float16Array ) => number; + +/** +* Callback invoked for each element in an array. +* +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns returned value +*/ +type MapFcn = NullaryMapFcn | UnaryMapFcn | BinaryMapFcn | TernaryMapFcn; + +/** +* Reducer function invoked for each element in an array. +* +* @returns accumulated result +*/ +type NullaryReducer = () => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @returns accumulated result +*/ +type UnaryReducer = ( acc: U ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @returns accumulated result +*/ +type BinaryReducer = ( acc: U, value: number ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @returns accumulated result +*/ +type TernaryReducer = ( acc: U, value: number, index: number ) => U; + +/** +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns accumulated result +*/ +type QuaternaryReducer = ( acc: U, value: number, index: number, arr: Float16Array ) => U; + +/** +* Reducer function invoked for each element in an array. +* +* @param acc - accumulated result +* @param value - current array element +* @param index - current array element index +* @param arr - array on which the method was called +* @returns accumulated result +*/ +type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; + +/** +* Comparator function. +* +* @param a - first number for comparison +* @param b - second number for comparison +* @returns number indicating comparison result +*/ +type CompareFcn = ( a: number, b: number ) => number; + +/** +* Class for creating a half-precision floating-point number array. +*/ +declare class Float16Array { + /** + * Half-precision floating-point number array constructor. + * + * @param arg - length, typed array, array-like object, or buffer + * @param byteOffset - byte offset (default: 0) + * @param length - view length + * @throws ArrayBuffer byte length must be a multiple of `2` + * @throws if provided only a single argument, must provide a valid argument + * @throws byte offset must be a nonnegative integer + * @throws view length must be a positive multiple of `2` + * @throws must provide sufficient memory to accommodate byte offset and view length requirements + * @returns half-precision floating-point number array + * + * @example + * var arr = new Float16Array(); + * // returns + * + * var len = arr.length; + * // returns 0 + * + * @example + * var arr = new Float16Array( 2 ); + * // returns + * + * var len = arr.length; + * // returns 2 + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0 ] ); + * // returns + * + * var len = arr.length; + * // returns 2 + * + * @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 + */ + constructor( arg?: number | ArrayLike | ArrayBuffer | Iterable, byteOffset?: number, length?: number ); + + /** + * Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. + * + * @param i - element index + * @throws index argument must be an integer + * @returns array element + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var v = arr.at( 0 ); + * // returns 1.0 + * + * v = arr.at( -1 ); + * // returns 3.0 + * + * v = arr.at( 100 ); + * // returns undefined + */ + at( i: number ): number | void; + + /** + * Pointer to the underlying data buffer. + * + * @example + * var arr = new Float16Array( 10 ); + * + * var buf = arr.buffer; + * // returns + */ + readonly buffer: ArrayBuffer; + + /** + * Length (in bytes) of the array. + * + * @example + * var arr = new Float16Array( 10 ); + * + * var byteLength = arr.byteLength; + * // returns 20 + */ + readonly byteLength: number; + + /** + * Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. + * + * @example + * var arr = new Float16Array( 10 ); + * + * var byteOffset = arr.byteOffset; + * // returns 0 + */ + readonly byteOffset: number; + + /** + * Size (in bytes) of each array element. + * + * @example + * var arr = new Float16Array( 10 ); + * + * var nbytes = arr.BYTES_PER_ELEMENT; + * // returns 2 + */ + readonly BYTES_PER_ELEMENT: 2; + + /** + * Number of array elements. + * + * @example + * var arr = new Float16Array( 10 ); + * + * var len = arr.length; + * // returns 10 + */ + readonly length: number; + + /** + * Copies a sequence of elements within the array to the position starting at `target`. + * + * @param target - index at which to start copying elements + * @param start - source index at which to copy elements from + * @param end - source index at which to stop copying elements from + * @returns modified array + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * // Copy the first two elements to the last two elements: + * arr.copyWithin( 2, 0, 2 ); + * + * var v = arr[ 2 ]; + * // returns 1.0 + * + * v = arr[ 3 ]; + * // returns 2.0 + */ + copyWithin( target: number, start: number, end?: number ): Float16Array; + + /** + * Returns an iterator for iterating over array key-value pairs. + * + * @returns iterator + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * 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 + */ + entries(): TypedIterator<[number, number]>; + + /** + * Tests whether all elements in an array pass a test implemented by a predicate function. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns boolean indicating whether all elements pass a test + * + * @example + * function predicate( v ) { + * return v >= 0.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var bool = arr.every( predicate ); + * // returns true + */ + every( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + + /** + * Returns a modified typed array filled with a fill value. + * + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @returns modified typed array + * + * @example + * var arr = new Float16Array( 3 ); + * + * arr.fill( 1.0, 1 ); + * + * var v = arr[ 0 ]; + * // returns 0.0 + * + * v = arr[ 1 ]; + * // returns 1.0 + * + * v = arr[ 2 ]; + * // returns 1.0 + */ + fill( value: number, start?: number, end?: number ): Float16Array; + + /** + * Returns a new array containing the elements of an array which pass a test implemented by a predicate function. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns new array containing elements which pass a test implemented by a predicate function + * + * @example + * function predicate( v ) { + * return ( v >= 2.0 ); + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.filter( predicate ); + * // returns + * + * var len = out.length; + * // returns 2 + * + * var v = out[ 0 ]; + * // returns 2.0 + * + * v = out[ 1 ]; + * // returns 3.0 + */ + filter( predicate: Predicate, thisArg?: ThisParameterType> ): Float16Array; + + /** + * Returns the first element in an array for which a predicate function returns a truthy value. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns array element or undefined + * + * @example + * function predicate( v ) { + * return v > 1.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var v = arr.find( predicate ); + * // returns 2.0 + */ + find( predicate: Predicate, thisArg?: ThisParameterType> ): number | void; + + /** + * Returns the index of the first element in an array for which a predicate function returns a truthy value. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns array index or -1 + * + * @example + * function predicate( v ) { + * return v > 1.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var v = arr.findIndex( predicate ); + * // returns 1 + */ + findIndex( predicate: Predicate, thisArg?: ThisParameterType> ): number; + + /** + * Returns the last element in an array for which a predicate function returns a truthy value. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns array element or undefined + * + * @example + * function predicate( v ) { + * return v > 1.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var v = arr.findLast( predicate ); + * // returns 3.0 + */ + findLast( predicate: Predicate, thisArg?: ThisParameterType> ): number | void; + + /** + * Returns the index of the last element in an array for which a predicate function returns a truthy value. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns array index or -1 + * + * @example + * function predicate( v ) { + * return v > 1.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var v = arr.findLastIndex( predicate ); + * // returns 2 + */ + findLastIndex( predicate: Predicate, thisArg?: ThisParameterType> ): number; + + /** + * Invokes a function once for each array element. + * + * @param fcn - function to invoke + * @param thisArg - execution context + * @returns undefined + * + * @example + * function log( v, i ) { + * console.log( '%s: %s', i, v.toString() ); + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * arr.forEach( log ); + */ + forEach( fcn: Callback, thisArg?: ThisParameterType> ): void; + + /** + * Returns a boolean indicating whether an array includes a provided value. + * + * @param searchElement - element to search for + * @param fromIndex - starting index (inclusive) + * @returns boolean indicating whether an array includes a value + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var bool = arr.includes( 3.0 ); + * // returns true + * + * bool = arr.includes( 3.0, 3 ); + * // returns false + */ + includes( searchElement: number, fromIndex?: number ): boolean; + + /** + * Returns the first index at which a given element can be found. + * + * @param searchElement - element to find + * @param fromIndex - starting index (inclusive) + * @returns index or -1 + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var idx = arr.indexOf( 3.0 ); + * // returns 2 + * + * idx = arr.indexOf( 3.0, 3 ); + * // returns -1 + * + * idx = arr.indexOf( 6.0 ); + * // returns -1 + */ + indexOf( searchElement: number, fromIndex?: number ): number; + + /** + * Returns a new string by concatenating all array elements. + * + * @param separator - value separator (default: ',') + * @returns string + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var str = arr.join(); + * // returns '1,2,3' + * + * str = arr.join( '|' ); + * // returns '1|2|3' + */ + join( separator?: string ): string; + + /** + * Returns an iterator for iterating over each index key in a typed array. + * + * @returns iterator + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0 ] ); + * + * var iter = arr.keys(); + * + * var v = iter.next().value; + * // returns 0 + * + * v = iter.next().value; + * // returns 1 + * + * var bool = iter.next().done; + * // returns true + */ + keys(): TypedIterator; + + /** + * Returns the last index at which a given element can be found. + * + * @param searchElement - element to find + * @param fromIndex - index at which to start searching backward (inclusive) + * @returns index or -1 + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 2.0, 1.0 ] ); + * + * var idx = arr.lastIndexOf( 2.0 ); + * // returns 3 + * + * idx = arr.lastIndexOf( 2.0, 2 ); + * // returns 1 + * + * idx = arr.lastIndexOf( 5.0 ); + * // returns -1 + */ + lastIndexOf( searchElement: number, fromIndex?: number ): number; + + /** + * Returns a new array with each element being the result of a provided callback function. + * + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns new half-precision floating-point number array + * + * @example + * function scale( v ) { + * return v * 2.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.map( scale ); + * // returns + * + * var v = out[ 0 ]; + * // returns 2.0 + * + * v = out[ 1 ]; + * // returns 4.0 + * + * v = out[ 2 ]; + * // returns 6.0 + */ + map( fcn: MapFcn, thisArg?: ThisParameterType> ): Float16Array; + + /** + * 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. + * + * @param reducer - callback function + * @param initialValue - initial value + * @returns accumulated result + * + * @example + * function reducer( acc, v ) { + * return acc + v; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.reduce( reducer, 0.0 ); + * // returns 6.0 + */ + reduce( reducer: Reducer, initialValue?: U ): U; + + /** + * Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. + * + * @param reducer - callback function + * @param initialValue - initial value + * @returns accumulated result + * + * @example + * function reducer( acc, v ) { + * return acc + v; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.reduceRight( reducer, 0.0 ); + * // returns 6.0 + */ + reduceRight( reducer: Reducer, initialValue?: U ): U; + + /** + * Reverses an array in-place. + * + * @returns reversed array + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.reverse(); + * // returns + * + * var v = out[ 0 ]; + * // returns 3.0 + * + * v = out[ 1 ]; + * // returns 2.0 + * + * v = out[ 2 ]; + * // returns 1.0 + */ + reverse(): Float16Array; + + /** + * Sets one or more array elements. + * + * ## 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. + * + * + * @param value - value(s) + * @param i - element index at which to start writing values (default: 0) + * @throws index argument must be a nonnegative integer + * @throws index argument is out-of-bounds + * @throws target array lacks sufficient storage to accommodate source values + * + * @example + * var arr = new Float16Array( 10 ); + * + * var v = arr[ 0 ]; + * // returns 0.0 + * + * arr.set( [ 1.0 ], 0 ); + * + * v = arr[ 0 ]; + * // returns 1.0 + */ + set( value: ArrayLike, i?: number ): void; + + /** + * Copies a portion of a typed array to a new typed array. + * + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @throws indices must be integers + * @returns output array + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var out = arr.slice(); + * // returns + * + * var len = out.length; + * // returns 5 + * + * var v = out[ 0 ]; + * // returns 1.0 + * + * v = out[ len-1 ]; + * // returns 5.0 + * + * out = arr.slice( 1, -2 ); + * // returns + * + * len = out.length; + * // returns 2 + * + * v = out[ 0 ]; + * // returns 2.0 + * + * v = out[ len-1 ]; + * // returns 3.0 + */ + slice( start?: number, end?: number ): Float16Array; + + /** + * Tests whether at least one element in an array passes a test implemented by a predicate function. + * + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns boolean indicating whether at least one element passes a test + * + * @example + * function predicate( v ) { + * return v > 2.0; + * } + * + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var bool = arr.some( predicate ); + * // returns true + */ + some( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + + /** + * Sorts an array in-place. + * + * @param compareFcn - comparison function + * @returns sorted array + * + * @example + * function compare( a, b ) { + * if ( a < b ) { + * return -1; + * } + * if ( a > b ) { + * return 1; + * } + * return 0; + * } + * + * var arr = new Float16Array( [ 3.0, 1.0, 2.0 ] ); + * + * arr.sort( compare ); + * + * var v = arr[ 0 ]; + * // returns 1.0 + * + * v = arr[ 1 ]; + * // returns 2.0 + * + * v = arr[ 2 ]; + * // returns 3.0 + */ + sort( compareFcn?: CompareFcn ): Float16Array; + + /** + * Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array. + * + * @param begin - starting index (inclusive) + * @param end - ending index (exclusive) + * @throws indices must be integers + * @returns subarray + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var subarr = arr.subarray(); + * // returns + * + * var len = subarr.length; + * // returns 5 + * + * var v = subarr[ 0 ]; + * // returns 1.0 + * + * v = subarr[ len-1 ]; + * // returns 5.0 + * + * subarr = arr.subarray( 1, -2 ); + * // returns + * + * len = subarr.length; + * // returns 2 + * + * v = subarr[ 0 ]; + * // returns 2.0 + * + * v = subarr[ len-1 ]; + * // returns 3.0 + */ + subarray( begin?: number, end?: number ): Float16Array; + + /** + * Serializes an array as a locale-specific string. + * + * @param locales - locale identifier(s) + * @param options - configuration options + * @returns string + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var str = arr.toLocaleString(); + * // returns '1,2,3' + */ + toLocaleString( locales?: string | Array, options?: LocaleOptions ): string; + + /** + * Returns a new typed array containing the elements in reversed order. + * + * @returns reversed array + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.toReversed(); + * // returns + * + * var v = out[ 0 ]; + * // returns 3.0 + * + * v = out[ 1 ]; + * // returns 2.0 + * + * v = out[ 2 ]; + * // returns 1.0 + */ + toReversed(): Float16Array; + + /** + * Returns a new typed array containing the elements in sorted order. + * + * @param compareFcn - comparison function + * @returns sorted array + * + * @example + * function compare( a, b ) { + * if ( a < b ) { + * return -1; + * } + * if ( a > b ) { + * return 1; + * } + * return 0; + * } + * + * var arr = new Float16Array( [ 3.0, 1.0, 2.0 ] ); + * + * var out = arr.toSorted( compare ); + * // returns + * + * var v = out[ 0 ]; + * // returns 1.0 + * + * v = out[ 1 ]; + * // returns 2.0 + * + * v = out[ 2 ]; + * // returns 3.0 + */ + toSorted( compareFcn?: CompareFcn ): Float16Array; + + /** + * Serializes an array as a string. + * + * @returns string + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var str = arr.toString(); + * // returns '1,2,3' + */ + toString(): string; + + /** + * Returns an iterator for iterating over each value in a typed array. + * + * @returns iterator + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0 ] ); + * + * var iter = arr.values(); + * + * var v = iter.next().value; + * // returns 1.0 + * + * v = iter.next().value; + * // returns 2.0 + * + * var bool = iter.next().done; + * // returns true + */ + values(): TypedIterator; + + /** + * Returns a new typed array with the element at a provided index replaced with a provided value. + * + * @param index - element index + * @param value - new value + * @throws first argument must be an integer + * @throws second argument must be a number + * @throws index argument is out-of-bounds + * @returns modified typed array + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + * + * var out = arr.with( 0, 4.0 ); + * // returns + * + * var v = out[ 0 ]; + * // returns 4.0 + */ + with( index: number, value: number ): Float16Array; +} + +/** +* Interface defining a Float16Array constructor which is both "newable" and "callable". +*/ +interface Float16ArrayConstructor { + /** + * Half-precision floating-point number array constructor. + * + * @param arg - length, typed array, array-like object, or buffer + * @param byteOffset - byte offset (default: 0) + * @param length - view length + * @throws ArrayBuffer byte length must be a multiple of `2` + * @throws if provided only a single argument, must provide a valid argument + * @throws byte offset must be a nonnegative integer + * @throws byte offset must be a multiple of `2` + * @throws view length must be a positive multiple of `2` + * @throws must provide sufficient memory to accommodate byte offset and view length requirements + * @returns half-precision floating-point number array + * + * @example + * var arr = new Float16Array(); + * // returns + * + * var len = arr.length; + * // returns 0 + * + * @example + * var arr = new Float16Array( 2 ); + * // returns + * + * var len = arr.length; + * // returns 2 + * + * @example + * var arr = new Float16Array( [ 1.0, 2.0 ] ); + * // returns + * + * var len = arr.length; + * // returns 2 + * + * @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 + */ + new( arg?: number | ArrayLike | ArrayBuffer | Iterable, byteOffset?: number, length?: number ): Float16Array; + + /** + * Constructor name. + * + * @example + * var str = Float16Array.name; + * // returns 'Float16Array' + */ + readonly name: 'Float16Array'; + + /** + * Size (in bytes) of each array element. + * + * @example + * var nbytes = Float16Array.BYTES_PER_ELEMENT; + * // returns 2 + */ + readonly BYTES_PER_ELEMENT: 2; + + /** + * Creates a new half-precision floating-point number array from an array-like object or an iterable. + * + * @param src - array-like object or iterable + * @param clbk - callback to invoke for each source element + * @param thisArg - context + * @returns half-precision floating-point number array + * + * @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 + */ + from( src: ArrayLike | Iterable, clbk?: FromCallback, thisArg?: ThisParameterType> ): Float16Array; + + /** + * Creates a new half-precision floating-point number array from a variable number of arguments. + * + * @param elements - array elements + * @returns half-precision floating-point number array + * + * @example + * var arr = Float16Array.of( 1.0, 2.0, 3.0, 4.0 ); + * // returns + * + * var len = arr.length; + * // returns 4 + */ + of( ...elements: Array ): Float16Array; +} + +/** +* Half-precision floating-point number array constructor. +* +* @param arg - length, typed array, array-like object, or buffer +* @param byteOffset - byte offset (default: 0) +* @param length - view length +* @throws ArrayBuffer byte length must be a multiple of `2` +* @throws if provided only a single argument, must provide a valid argument +* @throws byte offset must be a nonnegative integer +* @throws byte offset must be a multiple of `2` +* @throws view length must be a positive multiple of `2` +* @throws must provide sufficient memory to accommodate byte offset and view length requirements +* @returns half-precision floating-point number array +* +* @example +* var arr = new Float16Array(); +* // returns +* +* var len = arr.length; +* // returns 0 +* +* @example +* var arr = new Float16Array( 2 ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @example +* var arr = new Float16Array( [ 1.0, 2.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 2 +* +* @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 +*/ +declare var ctor: Float16ArrayConstructor; + + +// EXPORTS // + +export = ctor; + +// eslint-doctest-alias: 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..9c7b84d4b7d7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/docs/types/test.ts @@ -0,0 +1,129 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ArrayBuffer = require( '@stdlib/array/buffer' ); +import Float16Array = require( './index' ); + +/** +* Callback function. +* +* @param v - value +* @returns input value +*/ +function clbk( v: number ): number { + return v; +} + + +// TESTS // + +// The function returns a half-precision floating-point number array... +{ + new Float16Array(); // $ExpectType Float16Array + new Float16Array( 2 ); // $ExpectType Float16Array + new Float16Array( [ 1.0, -1.0 ] ); // $ExpectType Float16Array + + const buf = new ArrayBuffer( 16 ); + new Float16Array( buf ); // $ExpectType Float16Array + new Float16Array( buf, 8 ); // $ExpectType Float16Array + new Float16Array( buf, 8, 2 ); // $ExpectType Float16Array +} + +// The compiler throws an error if the function is provided a first argument that is not a number, typed array, array-like object, or array buffer... +{ + new Float16Array( true ); // $ExpectError + new Float16Array( false ); // $ExpectError + new Float16Array( null ); // $ExpectError + new Float16Array( 'abc' ); // $ExpectError + new Float16Array( {} ); // $ExpectError + new Float16Array( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + const buf = new ArrayBuffer( 16 ); + new Float16Array( buf, true ); // $ExpectError + new Float16Array( buf, false ); // $ExpectError + new Float16Array( buf, null ); // $ExpectError + new Float16Array( buf, 'abc' ); // $ExpectError + new Float16Array( buf, {} ); // $ExpectError + new Float16Array( buf, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a number... +{ + const buf = new ArrayBuffer( 16 ); + new Float16Array( buf, 8, true ); // $ExpectError + new Float16Array( buf, 8, false ); // $ExpectError + new Float16Array( buf, 8, null ); // $ExpectError + new Float16Array( buf, 8, 'abc' ); // $ExpectError + new Float16Array( buf, 8, {} ); // $ExpectError + new Float16Array( buf, 8, ( x: number ): number => x ); // $ExpectError +} + +// The `from` method returns a half-precision floating-point number array... +{ + Float16Array.from( [ 1.0, 1.0 ] ); // $ExpectType Float16Array + Float16Array.from( [ 1.0, 1.0 ], ( x: number ): number => x * x ); // $ExpectType Float16Array + Float16Array.from( [ 1.0 ], clbk, {} ); // $ExpectType Float16Array +} + +// The compiler throws an error if the `from` method is provided a first argument which is not array-like or iterable... +{ + Float16Array.from( true ); // $ExpectError + Float16Array.from( false ); // $ExpectError + Float16Array.from( 123 ); // $ExpectError + Float16Array.from( null ); // $ExpectError + Float16Array.from( {} ); // $ExpectError + + Float16Array.from( true, clbk ); // $ExpectError + Float16Array.from( false, clbk ); // $ExpectError + Float16Array.from( 123, clbk ); // $ExpectError + Float16Array.from( null, clbk ); // $ExpectError + Float16Array.from( {}, clbk ); // $ExpectError + + Float16Array.from( true, clbk, {} ); // $ExpectError + Float16Array.from( false, clbk, {} ); // $ExpectError + Float16Array.from( 123, clbk, {} ); // $ExpectError + Float16Array.from( null, clbk, {} ); // $ExpectError + Float16Array.from( {}, clbk, {} ); // $ExpectError +} + +// The compiler throws an error if the `from` method is provided a second argument which is not a function with a supported signature... +{ + Float16Array.from( [ 1.0, 1.0 ], true ); // $ExpectError + Float16Array.from( [ 1.0, 1.0 ], false ); // $ExpectError + Float16Array.from( [ 1.0, 1.0 ], 123 ); // $ExpectError + Float16Array.from( [ 1.0, 1.0 ], null ); // $ExpectError + Float16Array.from( [ 1.0, 1.0 ], {} ); // $ExpectError +} + +// The `of` method returns a half-precision floating-point number array... +{ + Float16Array.of( 1.0, 1.0, 1.0, 1.0 ); // $ExpectType Float16Array +} + +// The compiler throws an error if the `of` method is provided arguments that are not numbers... +{ + Float16Array.of( 'abc', 'def' ); // $ExpectError + Float16Array.of( true, false ); // $ExpectError + Float16Array.of( {}, [] ); // $ExpectError + Float16Array.of( null, null ); // $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..283028e9ada8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Uint16Array = require( '@stdlib/array/uint16' ); +var logEach = require( '@stdlib/console/log-each' ); +var Float16Array = require( './../lib' ); + +// Create a half-precision floating-point number array by specifying a length: +var out = new Float16Array( 3 ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array of numbers: +var arr = [ 1.05, 2.05, 3.05 ]; +out = new Float16Array( arr ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array buffer: +arr = new Uint16Array( [ 1000, 2000, 3000, 4000 ] ); +out = new Float16Array( arr.buffer ); +logEach( '%s', out ); + +// Create a half-precision floating-point number array from an array buffer view: +arr = new Uint16Array( [ 1000, 2000, 3000, 4000 ] ); +out = new Float16Array( arr.buffer, 2, 2 ); +logEach( '%s', out ); 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..e5cfbc984f8a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/index.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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( [ 1.0, 2.0 ] ); +* // 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 hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' ); +var polyfill = require( './polyfill' ); +var builtin = require( './main.js' ); + + +// MAIN // + +var ctor; +if ( hasFloat16ArraySupport() ) { + ctor = builtin; +} else { + ctor = polyfill; +} + + +// EXPORTS // + +module.exports = ctor; diff --git a/lib/node_modules/@stdlib/array/float16/lib/main.js b/lib/node_modules/@stdlib/array/float16/lib/main.js new file mode 100644 index 000000000000..90c992487755 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/main.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +var ctor = ( typeof Float16Array === 'function' ) ? Float16Array : void 0; // eslint-disable-line no-undef, stdlib/require-globals + + +// EXPORTS // + +module.exports = ctor; diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_array.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_array.js new file mode 100644 index 000000000000..b3d7135d1e15 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_array.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 f16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); + + +// MAIN // + +/** +* Fills an output array with unsigned 16-bit integers corresponding to the IEEE 754 binary representation of respective half-precision floating-point numbers. +* +* @private +* @param {Uint16Array} buf - output array +* @param {Array} arr - input array +* @returns {Uint16Array} output array +*/ +function fromArray( buf, arr ) { + var len; + var i; + + len = arr.length; + for ( i = 0; i < len; i++ ) { + buf[ i ] = toWord( f16( arr[ i ] ) ); + } + return buf; +} + + +// EXPORTS // + +module.exports = fromArray; diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator.js new file mode 100644 index 000000000000..da83598fb6e9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 f16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); + + +// 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( toWord( f16( v.value ) ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIterator; diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator_map.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator_map.js new file mode 100644 index 000000000000..0ea70933cdf6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill/from_iterator_map.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 f16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); + + +// 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( toWord( f16( clbk.call( thisArg, v.value, i ) ) ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = fromIteratorMap; diff --git a/lib/node_modules/@stdlib/array/float16/lib/polyfill/index.js b/lib/node_modules/@stdlib/array/float16/lib/polyfill/index.js new file mode 100644 index 000000000000..43769005284a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/lib/polyfill/index.js @@ -0,0 +1,2410 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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, stdlib/jsdoc-typedef-typos, max-lines */ + +'use strict'; + +// MODULES // + +var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isObject = require( '@stdlib/assert/is-object' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var format = require( '@stdlib/string/format' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var f16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var fromWord = require( '@stdlib/number/float16/base/from-word' ); +var gcopy = require( '@stdlib/blas/base/gcopy' ); +var fromArray = require( './from_array.js' ); +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 ) { // eslint-disable-line id-length + return ( value === Float16Array ); +} + +/** +* Returns a getter. +* +* @private +* @param {Float16Array} ctx - typed array instance +* @param {NonNegativeInteger} idx - element index +* @returns {Function} getter +*/ +function getter( ctx, idx ) { + return get; + + /** + * Returns an array element. + * + * @private + * @returns {(number|void)} array element + */ + function get() { + return ctx._get( idx ); // eslint-disable-line no-underscore-dangle + } +} + +/** +* Returns a setter. +* +* @private +* @param {Float16Array} ctx - typed array instance +* @param {NonNegativeInteger} idx - element index +* @returns {Function} setter +*/ +function setter( ctx, idx ) { + return set; + + /** + * Sets an array element. + * + * @private + * @param {number} value - value to set + */ + function set( value ) { + ctx.set( [ value ], idx ); + } +} + + +// 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} half-precision 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, 5.0 ] ); +* // returns +* +* var len = arr.length; +* // returns 5 +* +* @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; + var arg; + var i; + + 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 ) { + arg = arguments[ 0 ]; + if ( isNonNegativeInteger( arg ) ) { + buf = new Uint16Array( arg ); + } else if ( isCollection( arg ) ) { + if ( isFloat16Array( arg ) ) { + buf = new Uint16Array( arg.length ); + gcopy.ndarray( arg.length, new Uint16Array( arg.buffer, arg.byteOffset, arg.length ), 1, 0, buf, 1, 0 ); // eslint-disable-line max-len + } else { + buf = fromArray( new Uint16Array( arg.length ), arg ); + } + } else if ( isArrayBuffer( arg ) ) { + if ( !isInteger( arg.byteLength/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, arg.byteLength ) ); + } + buf = new Uint16Array( arg ); + } else if ( isObject( arg ) ) { + 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`.', arg ) ); + } + if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { + throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + } + buf = arg[ 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`.', arg ) ); + } + 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`.', arg ) ); + } + } 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 ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) ); + } + if ( nargs === 2 ) { + len = buf.byteLength - byteOffset; + if ( !isInteger( len/BYTES_PER_ELEMENT ) ) { + throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) ); + } + 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 ); + for ( i = 0; i < buf.length; i++ ) { + setReadWriteAccessor( this, i, getter( this, i ), setter( this, i ) ); + } + 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} half-precision floating-point number array +* +* @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 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 ( isCollection( src ) ) { + if ( clbk ) { + len = src.length; + out = new this( len ); + buf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + buf[ i ] = toWord( f16( clbk.call( thisArg, 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 ); + } + if ( tmp instanceof Error ) { + throw tmp; + } + 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} half-precision floating-point number array +* +* @example +* var arr = Float16Array.of( 1.0, 1.0, 1.0, 1.0 ); +* // returns +* +* var x = arr[ 0 ]; +* // returns 1.0 +* +* 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 {(number|void)} array element +* +* @example +* var arr = new Float16Array( [ 10.0, 20.0, 30.0 ] ); +* +* var v = arr.at( 0 ); +* // returns 10.0 +* +* v = arr.at( -1 ); +* // returns 30.0 +* +* 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 fromWord( 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( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* // Copy the first two elements to the last two elements: +* arr.copyWithin( 2, 0, 2 ); +* +* var v = arr[ 2 ]; +* // returns 1.0 +* +* v = arr[ 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( [ 1.0, 2.0, 3.0 ] ); +* +* 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, fromWord( 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 ); +* +* 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, fromWord( 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[ 0 ]; +* // returns 0.0 +* +* v = arr[ 1 ]; +* // returns 1.0 +* +* v = arr[ 2 ]; +* // returns 1.0 +*/ +setReadOnly( Float16Array.prototype, 'fill', function fill( value, start, end ) { + var buf; + var len; + var i; + var v; + + 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; + } + v = toWord( value ); + for ( i = start; i < end; i++ ) { + buf[ i ] = v; + } + 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( [ 0.0, 1.0, 0.0 ] ); +* +* var out = arr.filter( predicate ); +* // returns +* +* var len = out.length; +* // returns 2 +* +* var v = out[ 0 ]; +* // returns 0.0 +* +* v = out[ 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 = fromWord( 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( [ 0.0, 1.0, 0.0 ] ); +* +* var v = arr.find( predicate ); +* // returns 1.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 = fromWord( 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( [ 0.0, 1.0, 2.0 ] ); +* +* var v = arr.findIndex( predicate ); +* // returns 1 +*/ +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 = fromWord( 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( [ 0.0, 1.0, 0.0 ] ); +* +* var v = arr.findLast( predicate ); +* // returns 1.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 = fromWord( 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( [ 0.0, 1.0, 0.0 ] ); +* +* var v = arr.findLastIndex( predicate ); +* // returns 1 +*/ +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 = fromWord( 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( [ 0.0, 1.0, 2.0 ] ); +* +* 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, fromWord( buf[ i ] ), i, this ); + } +}); + +/** +* Returns an array element. +* +* @private +* @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 {(number|void)} array element +*/ +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 fromWord( 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( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +* +* 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; + var v; + + 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; + v = toWord( searchElement ); + for ( i = fromIndex; i < this._length; i++ ) { + if ( v === 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( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +* +* 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; + var v; + + 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; + v = toWord( searchElement ); + for ( i = fromIndex; i < this._length; i++ ) { + if ( v === 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( [ 0.0, 1.0, 2.0 ] ); +* +* 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( fromWord( 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( [ 1.0, 2.0 ] ); +* +* 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 floating-point number +* @throws {TypeError} first argument must be a numeric value +* @throws {TypeError} second argument must be an integer +* @returns {integer} index or -1 +* +* @example +* var arr = new Float16Array( [ 0.0, 1.0, 2.0, 3.0, 2.0 ] ); +* +* 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; + var v; + + 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; + v = toWord( searchElement ); + for ( i = fromIndex; i >= 0; i-- ) { + if ( v === 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( [ 0.0, 1.0, 2.0 ] ); +* +* var out = arr.map( scale ); +* // returns +* +* var z = out[ 0 ]; +* // returns 0.0 +* +* z = out[ 1 ]; +* // returns 2.0 +* +* z = out[ 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 ] = toWord( fcn.call( thisArg, fromWord( buf[ i ] ), i, this ) ); // eslint-disable-line max-len + } + 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( [ 1.0, 2.0, 3.0 ] ); +* +* 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 = fromWord( buf[ 0 ] ); + i = 1; + } + for ( ; i < len; i++ ) { + acc = reducer( acc, fromWord( 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( [ 1.0, 2.0, 3.0 ] ); +* +* 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 = fromWord( buf[ len-1 ] ); + i = len - 2; + } + for ( ; i >= 0; i-- ) { + acc = reducer( acc, fromWord( 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( [ 0.0, 1.0, 2.0 ] ); +* +* var out = arr.reverse(); +* // returns +* +* var v = out[ 0 ]; +* // returns 2.0 +* +* v = out[ 1 ]; +* // returns 1.0 +* +* v = out[ 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 one or more array elements. +* +* ## 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} first argument must be a collection +* @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[ 0 ]; +* // returns 0.0 +* +* arr.set( [ 1.0, 2.0 ], 0 ); +* +* v = arr[ 0 ]; +* // returns 1.0 +*/ +setReadOnly( Float16Array.prototype, 'set', function set( value ) { + var sbuf; + var idx; + var buf; + var tmp; + var flg; + var N; + var i; + var j; + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + if ( !isCollection( value ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', value ) ); + } + 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; + } + 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 + flg = true; + } else { + sbuf = value; + flg = false; + } + // 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 ]; + } + sbuf = tmp; + } + if ( flg ) { + for ( i = 0; i < N; idx++, i++ ) { + buf[ idx ] = sbuf[ i ]; + } + } else { + for ( i = 0; i < N; idx++, i++ ) { + buf[ idx ] = toWord( sbuf[ i ] ); + } + } +}); + +/** +* 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( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = arr.slice(); +* // returns +* +* var len = out.length; +* // returns 5 +* +* var v = out[ 0 ]; +* // returns 0.0 +* +* v = out[ len-1 ]; +* // returns 4.0 +* +* out = arr.slice( 1, -2 ); +* // returns +* +* len = out.length; +* // returns 2 +* +* v = out[ 0 ]; +* // returns 1.0 +* +* v = out[ 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( [ 0.0, 1.0, 2.0 ] ); +* +* 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, fromWord( 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( [ 1.0, 0.0, 2.0 ] ); +* +* arr.sort( compare ); +* +* var v = arr[ 0 ]; +* // returns 0.0 +* +* v = arr[ 1 ]; +* // returns 1.0 +* +* v = arr[ 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( defaultCompare ); + 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; + + /** + * Default comparison function for float16 values. + * + * @private + * @param {unsigned16} a - unsigned 16-bit integer for comparison + * @param {unsigned16} b - unsigned 16-bit integer for comparison + * @returns {number} comparison result + */ + function defaultCompare( a, b ) { // eslint-disable-line stdlib/no-unnecessary-nested-functions + var x = fromWord( a ); + var y = fromWord( b ); + + // Handle NaN... + if ( isnan( x ) && isnan( y ) ) { + return 0; + } + if ( isnan( x ) ) { + return 1; + } + if ( isnan( y ) ) { + return -1; + } + // Normal comparison + if ( x < y ) { + return -1; + } + if ( x > y ) { + return 1; + } + return 0; + } + + /** + * Comparison function wrapper. + * + * @private + * @param {unsigned16} a - unsigned 16-bit integer for comparison + * @param {unsigned16} b - unsigned 16-bit integer for comparison + * @returns {number} comparison result + */ + function compare( a, b ) { + return compareFcn( fromWord( a ), fromWord( 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( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); +* +* var subarr = arr.subarray(); +* // returns +* +* var len = subarr.length; +* // returns 5 +* +* var bool = subarr[ 0 ]; +* // returns 0.0 +* +* bool = subarr[ len-1 ]; +* // returns 4.0 +* +* subarr = arr.subarray( 1, -2 ); +* // returns +* +* len = subarr.length; +* // returns 2 +* +* bool = subarr[ 0 ]; +* // returns 1.0 +* +* bool = subarr[ 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( [ 0.0, 1.0, 2.0 ] ); +* +* 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( fromWord( buf[ i ] ) ); + } + return out.toLocaleString( loc, opts ); +}); + +/** +* 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( [ 0.0, 1.0, 2.0 ] ); +* +* var out = arr.toReversed(); +* // returns +* +* var v = out[ 0 ]; +* // returns 2.0 +* +* v = out[ 1 ]; +* // returns 1.0 +* +* v = out[ 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( [ 2.0, 0.0, 1.0 ] ); +* +* var out = arr.toSorted( compare ); +* // returns +* +* var v = out[ 0 ]; +* // returns 0.0 +* +* v = out[ 1 ]; +* // returns 1.0 +* +* v = out[ 2 ]; +* // returns 2.0 +*/ +setReadOnly( Float16Array.prototype, 'toSorted', function toSorted( compareFcn ) { + var out; + + if ( !isFloat16Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a floating-point number array.' ); + } + out = new this.constructor( this ); + if ( arguments.length === 0 ) { + return out.sort(); + } + return out.sort( compareFcn ); +}); + +/** +* 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( [ 0.0, 1.0, 2.0 ] ); +* +* 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.' ); + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + out.push( fromWord( 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( [ 0.0, 1.0 ] ); +* +* 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': fromWord( 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( [ 0.0, 1.0, 2.0 ] ); +* +* var out = arr.with( 0, 3.0 ); +* // returns +* +* var v = out[ 0 ]; +* // returns 3.0 +*/ +setReadOnly( Float16Array.prototype, 'with', function copyWith( index, value ) { + 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 ); + out[ 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/polyfill/test.at.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.at.js new file mode 100644 index 000000000000..36ec5fc7ec7b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.at.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `at` method for returning an array element', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'at' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.at ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.at.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.at( value ); + }; + } +}); + +tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { + var arr; + var v; + var i; + + arr = new Float16Array( 10 ); + for ( i = -arr.length; i < arr.length; i++ ) { + if ( i < 0 ) { + v = arr.at( i-arr.length ); + t.strictEqual( v, void 0, 'returns expected value for index '+(i-arr.length) ); + } else { + v = arr.at( arr.length+i ); + t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) ); + } + } + t.end(); +}); + +tape( 'the method returns an array element', function test( t ) { + var arr; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i+0.05 ); + } + + arr = new Float16Array( arr ); + + for ( i = -arr.length; i < arr.length; i++ ) { + v = arr.at( i ); + if ( i < 0 ) { + t.strictEqual( v, float64ToFloat16( arr.length + i + 0.05 ), 'returns expected value for index '+i ); + } else { + t.strictEqual( v, float64ToFloat16( i + 0.05 ), 'returns expected value for index '+i ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.copy_within.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.copy_within.js new file mode 100644 index 000000000000..3ae692acd874 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.copy_within.js @@ -0,0 +1,281 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a floating-point number array', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'copyWithin' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.copyWithin ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.copyWithin.call( value, 3, 0 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance (end)', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.copyWithin.call( value, 3, 0, 5 ); + }; + } +}); + +tape( 'the method copies a sequence of elements within an array', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( -arr.length, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, -2 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, 3, arr.length ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0, 2 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0, -3 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( arr.length, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 2.05 ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.entries.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.entries.js new file mode 100644 index 000000000000..b39a5e864155 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.entries.js @@ -0,0 +1,238 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'entries' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.entries ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.entries.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var buf; + var arr; + var it; + var v; + var i; + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.entries(); + t.strictEqual( it.next.length, 0, 'has zero arity' ); + + for ( i = 0; i < arr.length; i++ ) { + v = it.next(); + t.strictEqual( isArray( v.value ), true, 'returns expected value' ); + t.strictEqual( v.value[ 0 ], i, 'returns expected value' ); + t.strictEqual( isNumber( v.value[ 1 ] ), true, 'returns expected value' ); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ i ] ), 'returns expected value' ); + t.strictEqual( typeof v.done, 'boolean', 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns an iterator which has a `return` method for closing an iterator (no argument)', function test( t ) { + var buf; + var arr; + var it; + var v; + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.entries(); + + v = it.next(); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns an iterator which has a `return` method for closing an iterator (argument)', function test( t ) { + var buf; + var arr; + var it; + var v; + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.entries(); + + v = it.next(); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return( 'finished' ); + t.strictEqual( v.value, 'finished', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { + var Float16Array; + var arr; + var buf; + var it1; + var it2; + var v1; + var v2; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it1 = arr.entries(); + t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.strictEqual( typeof it2, 'object', 'returns expected value' ); + t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); + t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); + + for ( i = 0; i < arr.length; i++ ) { + v1 = it1.next().value; + v2 = it2.next().value; + t.strictEqual( v1[ 0 ], v2[ 0 ], 'returns expected value' ); + t.strictEqual( v1[ 1 ], v2[ 1 ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { + var Float16Array; + var arr; + var buf; + var it; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': false + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.entries(); + t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.every.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.every.js new file mode 100644 index 000000000000..a450373ab7c8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.every.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'every' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.every ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every.call( value, predicate ); + }; + } + + function predicate( v ) { + return v === 0.0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every( value ); + }; + } +}); + +tape( 'the method returns `true` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 1.05, 0.05, 1.05 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + bool = arr.every( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 1.05 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.fill.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.fill.js new file mode 100644 index 000000000000..8cc623eca861 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.fill.js @@ -0,0 +1,305 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'fill' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.fill ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill.call( value, 1.0 ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a floating-point number', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( 1.0, value ); + }; + } +}); + +tape( 'the method throws an error if provided a third argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( 1.0, 0, value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.fill( 1.05 ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.fill( 1.05 ); + + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + arr.fill( 1.05 ); + + buf = new Uint16Array( arr.buffer ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 1 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 1.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 0, 2 ); + + t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, -3, -1 ); + + t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, -10 ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 1, 10 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + for ( i = 1; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.0, 2, 1 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.filter.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.filter.js new file mode 100644 index 000000000000..ada81ba54805 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.filter.js @@ -0,0 +1,226 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `filter` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'filter' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.filter ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.filter.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.filter( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.filter( predicate ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method returns a new floating-point number array containing only those elements which satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 1.05, 2.05 ] ); + expected = new Uint16Array( [ toWord( 1.05 ), toWord( 1.05 ) ] ); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v === float64ToFloat16( 1.05 ) ); + } +}); + +tape( 'the method copies all elements to a new array if all elements satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v > 1.0 ); + } +}); + +tape( 'the method returns an empty array if no elements satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 1.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var buf; + var ctx; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ) + ]); + ctx = { + 'count': 0 + }; + actual = arr.filter( predicate, ctx ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v === float64ToFloat16( 1.05 ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find.js new file mode 100644 index 000000000000..10388e247937 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `find` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'find' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.find ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.find.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.find( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.find( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the first element which passes a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + v = arr.find( predicate ); + + t.strictEqual( v, float64ToFloat16( -2.05 ), 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + v = arr.find( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var v; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + v = arr.find( predicate, ctx ); + + t.strictEqual( v, float64ToFloat16( 3.05 ), 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_index.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_index.js new file mode 100644 index 000000000000..5eedcd748008 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_index.js @@ -0,0 +1,173 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findIndex` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'findIndex' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.findIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the first element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, 1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + idx = arr.findIndex( predicate, ctx ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last.js new file mode 100644 index 000000000000..151f25feedea --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLast` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'findLast' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.findLast ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLast.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 0.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLast( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.findLast( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the last element which passes a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + v = arr.findLast( predicate ); + + t.strictEqual( v, float64ToFloat16( -4.05 ), 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + v = arr.findLast( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var v; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + v = arr.findLast( predicate, ctx ); + + t.strictEqual( v, float64ToFloat16( 5.05 ), 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last_index.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last_index.js new file mode 100644 index 000000000000..bfcd0eb5a69f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.find_last_index.js @@ -0,0 +1,173 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLastIndex` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'findLastIndex' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.findLastIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLastIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLastIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the last element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + idx = arr.findLastIndex( predicate, ctx ); + + t.strictEqual( idx, 4, 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.for_each.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.for_each.js new file mode 100644 index 000000000000..ba37de71e847 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.for_each.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `forEach` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'forEach' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.forEach ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.forEach.call( value, fcn ); + }; + } + + function fcn( v ) { + if ( !isNumber( v ) ) { + t.fail( 'should be a number' ); + } + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.forEach( value ); + }; + } +}); + +tape( 'the method should not invoke a provided callback function if operating on an empty floating-point array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + arr.forEach( fcn ); + + t.end(); + + function fcn() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `undefined`', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + out = arr.forEach( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + if ( !isNumber( v ) ) { + t.fail( 'should be a number' ); + } + } +}); + +tape( 'the method invokes a provided function for each element in an array', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var arr; + + indices = []; + values = []; + arrays = []; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + arr.forEach( fcn ); + + expected = [ + float64ToFloat16( 1.05 ), + float64ToFloat16( 2.05 ), + float64ToFloat16( 3.05 ), + float64ToFloat16( 4.05 ) + ]; + + t.deepEqual( values, expected, 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2, 3 ], 'returns expected value' ); + t.strictEqual( arrays[ 0 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 1 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 2 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 3 ], arr, 'returns expected value' ); + + t.end(); + + function fcn( v, i, arr ) { + values.push( v ); + indices.push( i ); + arrays.push( arr ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + arr.forEach( fcn, ctx ); + + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.from.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.from.js new file mode 100644 index 000000000000..aff5b30bd22e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.from.js @@ -0,0 +1,654 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Uint16Array = require( '@stdlib/array/uint16' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a `from` method for creating a 16-bit floating-point number array from an array-like object or an iterable', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Float16Array, 'from' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.from ), true, 'has method' ); + + arr = Float16Array.from( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array constructor', function test( t ) { + var values; + var i; + + values = [ + {}, + null, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( value, clbk ); + }; + } + + function clbk() { + return 1.0; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( value, clbk, {} ); + }; + } + + function clbk() { + return 1.0; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( [], value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( [], value, {} ); + }; + } +}); + +tape( 'the method returns a floating-point number array', function test( t ) { + var arr; + var v; + + // Generic array: + arr = Float16Array.from( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing non-numeric values: + arr = Float16Array.from( [ 'beep' ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ null, 4 ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + arr = Float16Array.from( [ true, {}, '' ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 3, 'returns expected value' ); + + // Typed array: + arr = Float16Array.from( new Uint16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Floating-point number typed array: + arr = Float16Array.from( new Float16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Float16Array( [ 1.0, 2.0 ] ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method returns a floating-point number array (iterable)', function test( t ) { + var Float16Array; + var iter; + var arr; + var v; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter = { + 'next': next, + 'i': 0, + 'N': 4 + }; + arr = Float16Array.from( createIterable( iter ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter.N, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next() { + iter.i += 1; + if ( iter.i <= iter.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } +}); + +tape( 'the method supports providing a "map" function which is invoked for each source element', function test( t ) { + var arr; + var v; + + // Generic array: + arr = Float16Array.from( [], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing non-numeric values: + arr = Float16Array.from( [ 'beep' ], clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ null ], clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ [], {} ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + arr = Float16Array.from( [ 4, 5 ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Typed array: + arr = Float16Array.from( new Uint16Array( 0 ), clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ), clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Floating-point number typed array: + arr = Float16Array.from( new Float16Array( 0 ), clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Float16Array( [ true, true ] ), clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v; + } + + function clbk2() { + return true; + } +}); + +tape( 'the method supports providing a "map" function which is invoked for each iterated value', function test( t ) { + var Float16Array; + var iter; + var arr; + var v; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter = { + 'next': next, + 'i': 0, + 'N': 4 + }; + arr = Float16Array.from( createIterable( iter ), clbk ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, iter.N, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next() { + iter.i += 1; + if ( iter.i <= iter.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + + function clbk( v ) { + return !v; + } +}); + +tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { + var arr; + var ctx; + + ctx = { + 'count': 0 + }; + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1, ctx ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); + +tape( 'the method supports providing a `this` context for a provided map function (iterable)', function test( t ) { + var Float16Array; + var iter; + var ctx; + var arr; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter = { + 'next': next, + 'i': 0, + 'N': 4 + }; + ctx = { + 'count': 0 + }; + + arr = Float16Array.from( createIterable( iter ), clbk, ctx ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next() { + iter.i += 1; + if ( iter.i <= iter.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } + + function clbk( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); + +tape( 'the method throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { + var Float16Array; + var values; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( value ); + }; + } + + function hasSupport() { + return false; + } +}); + +tape( 'the method throws an error if provided a non-iterable object (ES2015+)', function test( t ) { + var Float16Array; + var values; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + }, + { + '__SYMBOL_ITERATOR__': null + }, + { + '__SYMBOL_ITERATOR__': 'beep' + }, + { + '__SYMBOL_ITERATOR__': nonIterable1 + }, + { + '__SYMBOL_ITERATOR__': nonIterable2 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( value ); + }; + } + + function hasSupport() { + return true; + } + + function nonIterable1() { + return null; + } + + function nonIterable2() { + return {}; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.includes.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.includes.js new file mode 100644 index 000000000000..5c2af642f45e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.includes.js @@ -0,0 +1,222 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `includes` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'includes' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.includes ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.includes.call( value, true ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.includes( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.includes( true, value ); + }; + } +}); + +tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.includes( 1.0 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if a floating-point number is not found', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 10 ); + bool = arr.includes( 1.0 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `true` if an array contains a specified floating-point number', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05] ); + bool = arr.includes( float64ToFloat16( 1.05 ) ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if provided a second argument which exceeds the input array length', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 10 ); + bool = arr.includes( 0.0, 20 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), 0 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), 3 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), -5 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), -2 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), -10 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), -10 ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.index_of.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.index_of.js new file mode 100644 index 000000000000..0487e012572a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.index_of.js @@ -0,0 +1,222 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `indexOf` method for returning the index of an array element', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'indexOf' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.indexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.indexOf.call( value, 1.0 ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.indexOf( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.indexOf( 1.0, value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array(); + idx = arr.indexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.indexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match if a numeric value is found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.indexOf( float64ToFloat16( 2.05 ) ); + + t.strictEqual( idx, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if provided a second argument which exceeds the input array length', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.indexOf( 1.0, 20 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 4 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -5 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -10 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 1.05 ), -10 ); + t.strictEqual( idx, 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.join.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.join.js new file mode 100644 index 000000000000..c7387bd42421 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.join.js @@ -0,0 +1,173 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'join' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.join ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.join.call( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `separator` argument which is not a string', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.join( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.join(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator', function test( t ) { + var expected; + var str; + var arr; + var i; + + arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); + + expected = float64ToFloat16( 0.05 ); + for ( i = 1; i < arr.length; i++ ) { + expected += '@' + float64ToFloat16( i + 0.05 ); + } + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator (single element)', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.05 ] ); + expected = '' + float64ToFloat16( 1.05 ); + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + + arr = new Float16Array( [ 1.05 ] ); + expected = '' + float64ToFloat16( 1.05 ); + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the method is invoked without a separator argument, the method returns a string representation of a floating-point number array with elements separated by a comma', function test( t ) { + var expected; + var str; + var arr; + var i; + + arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); + + expected = float64ToFloat16( 0.05 ); + for ( i = 1; i < arr.length; i++ ) { + expected += ',' + float64ToFloat16( i + 0.05 ); + } + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.js new file mode 100644 index 000000000000..0c672bb32234 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.js @@ -0,0 +1,740 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var arr = new Float16Array( 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (no argument)', function test( t ) { + var arr = new Float16Array(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (no argument, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (length)', function test( t ) { + var arr = new Float16Array( 10 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( 10 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (array)', function test( t ) { + var arr = new Float16Array( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (typed array)', function test( t ) { + var arr = new Float16Array( new Uint16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (typed array, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( new Uint16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (iterable)', function test( t ) { + var Float16Array; + var arr; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = new Float16Array( createIterable() ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 16-bit floating-point number array (iterable, no new)', function test( t ) { + var ctor; + var arr; + + ctor = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + arr = ctor( createIterable() ); + t.strictEqual( arr instanceof ctor, true, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable() { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return { + 'next': next + }; + } + + function next() { + return { + 'done': true + }; + } + } +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 8 ), 8 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( new ArrayBuffer( 8 ), 8 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 8 ), 8, 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = Float16Array; + + arr = ctor( new ArrayBuffer( 8 ), 8, 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16Array.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array, 'name' ), true, 'has property' ); + t.strictEqual( Float16Array.name, 'Float16Array', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Float16Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16Array.prototype.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + + arr = new Float16Array( 0 ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 0 ); + buf = arr.buffer; + t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 8 ); + v = arr.byteLength; + t.strictEqual( v, 56, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.byteOffset; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); + v = arr.byteOffset; + t.strictEqual( v, 32, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.byteOffset; + t.strictEqual( v, 64, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { + var arr; + var v; + + // No arguments: + arr = new Float16Array(); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Explicit array length: + arr = new Float16Array( 0 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( 10 ); + v = arr.length; + t.strictEqual( v, 10, 'returns expected value' ); + + // Generic array: + arr = new Float16Array( [] ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Typed array: + arr = new Float16Array( new Uint16Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new Uint16Array( [ 1.0, 1.0 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Float16 typed array: + arr = new Float16Array( new Float16Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new Float16Array( [ 1.0, 2.0 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // ArrayBuffer: + arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); + v = arr.length; + t.strictEqual( v, 16, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 32, 2 ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements (iterable)', function test( t ) { + var Float16Array; + var iter; + var arr; + var v; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + iter = { + 'next': next, + 'i': 0, + 'N': 4 + }; + arr = new Float16Array( createIterable( iter ) ); + v = arr.length; + t.strictEqual( v, iter.N, 'returns expected value' ); + + t.end(); + + function hasSupport() { + return true; + } + + function createIterable( iterator ) { + var it = {}; + it[ '__SYMBOL_ITERATOR__' ] = iterable; + return it; + + function iterable() { + return iterator; + } + } + + function next() { + iter.i += 1; + if ( iter.i <= iter.N ) { + return { + 'value': 1.0 + }; + } + return { + 'done': true + }; + } +}); + +tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 2', function test( t ) { + var values; + var i; + + values = [ + 1, + 3, + 5, + 7, + 9, + 11, + 101, + 1001 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( value ) ); + }; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (non-ES2015+)', function test( t ) { + var Float16Array; + var values; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( value ); + }; + } + + function hasSupport() { + return false; + } +}); + +tape( 'the constructor throws an error if provided a non-iterable object (ES2015+)', function test( t ) { + var Float16Array; + var values; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/assert/has-iterator-symbol-support': hasSupport, + '@stdlib/symbol/iterator': '__SYMBOL_ITERATOR__' + }); + + values = [ + {}, + { + '0': 1, + '1': 2, + '2': 3 + }, + { + '__SYMBOL_ITERATOR__': null + }, + { + '__SYMBOL_ITERATOR__': 'beep' + }, + { + '__SYMBOL_ITERATOR__': nonIterable1 + }, + { + '__SYMBOL_ITERATOR__': nonIterable2 + } + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( value ); + }; + } + + function hasSupport() { + return true; + } + + function nonIterable1() { + return null; + } + + function nonIterable2() { + return {}; + } +}); + +tape( 'the constructor throws an error if not provided a length, iterable, array-like object, or ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + -1, + NaN, + true, + false, + null, + void 0, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( value ); + }; + } +}); + +tape( 'the constructor throws an error if provided more than one argument and the first argument is not an ArrayBuffer', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( value, 0 ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a nonnegative integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 64 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 2', function test( t ) { + var values; + var i; + + values = [ + 1, + 3, + 5, + 7, + 9, + 11, + 101, + 1001 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 1e3 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 2, + 4, + 6, + 8, + 10, + 12, + 14, + 16, + 18, + 20 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 101 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a length argument which is not a nonnegative integer (ArrayBuffer)', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 64 ), 0, value ); + }; + } +}); + +tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { + var values; + var i; + + values = [ + 8, + 16, + 24, + 32 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 100 ), value, 1e3 ); + }; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.keys.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.keys.js new file mode 100644 index 000000000000..b255383027f9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.keys.js @@ -0,0 +1,261 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `keys` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'keys' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.keys ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.keys.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var expected; + var arr; + var it; + var i; + var r; + var e; + + arr = new Float16Array( [ 1.05, 2.05 ] ); + expected = [ + { + 'value': 0, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + r = it.next(); + e = expected[ i ]; + if ( e.value === void 0 ) { + t.deepEqual( r, e, 'returns expected value' ); + } else { + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { + var expected; + var arr; + var it; + var i; + var v; + + arr = new Float16Array( [] ); + expected = [ + { + 'done': true + }, + { + 'done': true + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + v = it.next(); + t.deepEqual( v, expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + it = arr.keys(); + + v = it.next(); + t.strictEqual( v.value, 0, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 1, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + it = arr.keys(); + + v = it.next(); + t.strictEqual( v.value, 0, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, 1, 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return( 'beep' ); + t.strictEqual( v.value, 'beep', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { + var Float16Array; + var arr; + var buf; + var it1; + var it2; + var v1; + var v2; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it1 = arr.keys(); + t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.strictEqual( typeof it2, 'object', 'returns expected value' ); + t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); + t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); + + for ( i = 0; i < arr.length; i++ ) { + v1 = it1.next().value; + v2 = it2.next().value; + t.strictEqual( v1, v2, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { + var Float16Array; + var arr; + var buf; + var it; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': false + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.keys(); + t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.last_index_of.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.last_index_of.js new file mode 100644 index 000000000000..3a4db7f7d55a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.last_index_of.js @@ -0,0 +1,211 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `lastIndexOf` method for returning the index of an array element', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'lastIndexOf' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.lastIndexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf.call( value, true ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a numeric value', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf( true, value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.lastIndexOf( 0.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.lastIndexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 2.05 ] ); + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ) ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 4 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), -3 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 10 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 10 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.map.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.map.js new file mode 100644 index 000000000000..bc321f61b24f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.map.js @@ -0,0 +1,178 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var identity = require( '@stdlib/utils/identity-function' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `map` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'map' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.map ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.map.call( value, identity ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.map( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.map( identity ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.end(); +}); + +tape( 'the method returns a new floating-point number array containing elements which are the result of a provided callback function', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( -1.05 ), + toWord( -2.05 ), + toWord( -3.05 ), + toWord( -4.05 ) + ]); + actual = arr.map( invert ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function invert( v ) { + return -v; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var buf; + var ctx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( -1.05 ), + toWord( -2.05 ), + toWord( -3.05 ), + toWord( -4.05 ) + ]); + ctx = { + 'count': 0 + }; + actual = arr.map( invert, ctx ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 6, 'returns expected value' ); + t.end(); + + function invert( v, i ) { + this.count += i; // eslint-disable-line no-invalid-this + return -v; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.of.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.of.js new file mode 100644 index 000000000000..ef1c105a6b1c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.of.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `of` method for creating a 16-bit floating-point number array from a variable number of arguments', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Float16Array, 'of' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.of ), true, 'has method' ); + + arr = Float16Array.of(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.of.call( value, true, true ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point array constructor', function test( t ) { + var values; + var i; + + values = [ + {}, + null, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.of.call( value, true, true ); + }; + } +}); + +tape( 'the method returns a floating-point number array', function test( t ) { + var arr; + var v; + + // No arguments: + arr = Float16Array.of(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Numeric arguments: + arr = Float16Array.of( 1.0, 2.0, 3.0, 4.0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Non-numeric arguments: + arr = Float16Array.of( 1, {}, 0, null, 'beep' ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 5, 'returns expected value' ); + + // Mixed arguments: + arr = Float16Array.of( true, 1, false, 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce.js new file mode 100644 index 000000000000..27733ef199be --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce.js @@ -0,0 +1,189 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reduce` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'reduce' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.reduce ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduce.call( value, reducer ); + }; + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduce( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduce( reducer ); + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var ind; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + accArray = [ 1.0, 3.0 ]; + valueArray = [ 2.0, 3.0 ]; + expected = float64ToFloat16( 6.0 ); + actual = arr.reduce( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + ind = index-1; + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + accArray = [ 2.0, 3.0, 5.0 ]; + valueArray = [ 1.0, 2.0, 3.0 ]; + expected = 8.0; + actual = arr.reduce( reducer, 2.0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + t.strictEqual( acc, float64ToFloat16( accArray[ index ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ index ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = float64ToFloat16( 10.20 ); + actual = arr.reduce( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce_right.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce_right.js new file mode 100644 index 000000000000..987a35274231 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reduce_right.js @@ -0,0 +1,192 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reduceRight` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'reduceRight' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.reduceRight ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduceRight.call( value, reducer ); + }; + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduceRight( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduceRight( reducer ); + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method uses the last element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + len = arr.length; + accArray = [ 3.0, 5.0 ]; + valueArray = [ 2.0, 1.0 ]; + expected = float64ToFloat16( 6.0 ); + actual = arr.reduceRight( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + var ind = (len-index-2); + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + len = arr.length; + accArray = [ 2.0, 5.0, 7.0 ]; + valueArray = [ 3.0, 2.0, 1.0 ]; + expected = 8.0; + actual = arr.reduceRight( reducer, 2.0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + var ind = (len-index-1); + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = float64ToFloat16( 10.20 ); + actual = arr.reduceRight( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reverse.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reverse.js new file mode 100644 index 000000000000..6c2d3a9f1969 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.reverse.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reverse` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'reverse' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.reverse ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reverse.call( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.reverse(); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method reverses elements of a floating-point number array in-place', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); + expected = new Uint16Array([ + toWord( 5.05 ), + toWord( 4.05 ), + toWord( 3.05 ), + toWord( 2.05 ), + toWord( 1.05 ) + ]); + out = arr.reverse(); + buf = new Uint16Array( arr.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.reverse(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.set.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.set.js new file mode 100644 index 000000000000..901301833cfd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.set.js @@ -0,0 +1,259 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `set` method for setting one or more array elements', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'set' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.set ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set( [ 1.0 ], value ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds', function test( t ) { + var values; + var arr1; + var arr2; + var i; + + arr1 = new Float16Array( 10 ); + arr2 = []; + for ( i = 0; i < arr1.length; i++ ) { + arr2.push( 1.0 ); + } + + values = [ + 1, + 2, + 3, + 4, + 5 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr1.set( arr2, value ); + }; + } +}); + +tape( 'the method sets one or more array elements', function test( t ) { + var arr; + var v; + var i; + + arr = new Float16Array( 10 ); + + v = arr[ 0 ]; + t.strictEqual( v, 0.0, 'returns expected value' ); + + // No index argument: + arr.set( [ 1.0 ] ); + + v = arr[ 0 ]; + t.strictEqual( v, 1.0, 'returns expected value' ); + + arr.set( [ 0.0 ] ); + + // Index argument: + for ( i = 0; i < arr.length; i++ ) { + v = arr[ i ]; + t.strictEqual( v, 0.0, 'returns expected value' ); + + arr.set( [ 1.05 ], i ); + + v = arr[ i ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + } + + // Multiple values, no index argument: + arr.set( [ 1.05, 2.05 ] ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); + + // Multiple values, index argument: + arr.set( [ 1.05, 2.05 ], 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method sets an array element (floating-point number array; shared buffer)', function test( t ) { + var byteOffset; + var arr; + var src; + var buf; + var ab; + var v; + var i; + + byteOffset = 112; + + ab = new ArrayBuffer( 240 ); + arr = new Float16Array( ab, byteOffset, 10 ); + + // Overlapping (requires copy), multiple values, no index argument: + buf = [ 1.05, 2.05 ]; + src = new Float16Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (requires copy), multiple values, index argument: + buf = [ -1.05, -2.05 ]; + src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src, 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (no copy), multiple values, no index argument: + buf = [ 3.05, 4.05 ]; + src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (no copy), multiple values, index argument: + buf = [ -3.05, -4.05 ]; + src = new Float16Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src, 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.slice.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.slice.js new file mode 100644 index 000000000000..463a37d8760b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.slice.js @@ -0,0 +1,311 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `slice` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'slice' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.slice ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.slice.call( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.slice( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.slice( 0, value ); + }; + } +}); + +tape( 'the method returns an empty typed array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.slice(); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'if called without arguments, the method returns a typed array containing the same elements as the original array', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice(); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method returns a typed array containing elements starting from a specified beginning index (inclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice( 1 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a typed array containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( 1, 3 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice( 1, 30 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method resolves negative indices relative to the last element', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( -3, -1 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( -30, -2 ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 2, 0 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved beginning index exceeds the maximum array index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 5 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved ending index is less than or equal to zero', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 2, -8 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = arr.slice( 1, 0 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.some.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.some.js new file mode 100644 index 000000000000..ffb35c173e49 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.some.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `some` method for returning boolean indicating whether at least one element passes a test', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'some' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.some ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.some.call( value, predicate ); + }; + } + + function predicate( v ) { + return v === 1.0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.some( value ); + }; + } +}); + +tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.some( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if at least one element passes a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method returns `false` if all elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 5.05 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 4.05 ); + } +}); + +tape( 'the method stops executing upon encountering the first element which passes a test', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 1.05 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.sort.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.sort.js new file mode 100644 index 000000000000..c4a205b8d80a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.sort.js @@ -0,0 +1,189 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Comparison function. +* +* @private +* @param {boolean} a - first value for comparison +* @param {boolean} b - second value for comparison +* @returns {number} comparison result +*/ +function compareFcn( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `sort` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'sort' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.sort ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.sort.call( value, compareFcn ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.sort( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.sort( compareFcn ); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method sorts elements of a floating-point number array in-place', function test( t ) { + var expected; + var arr; + var out; + var buf; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ), + toWord( 5.05 ) + ]); + out = arr.sort( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + arr = new Float16Array( [ 2.05, 1.05, -1.05, 0.05, -2.05 ] ); + expected = new Uint16Array([ + toWord( -2.05 ), + toWord( -1.05 ), + toWord( 0.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.sort( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + out = arr.sort( compareFcn ); + + t.strictEqual( out.length, arr.length, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.subarray.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.subarray.js new file mode 100644 index 000000000000..ca2a8c231cb6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.subarray.js @@ -0,0 +1,308 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `subarray` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'subarray' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.subarray ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.subarray.call( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.subarray( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.subarray( 0, value ); + }; + } +}); + +tape( 'the method returns empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.subarray(); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'if called without arguments, the method returns a view containing the same elements as the original array', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.subarray(); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method returns a view containing elements starting from a specified beginning index (inclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.subarray( 1 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a view containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.subarray( 1, 3 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method resolves negative indices relative to the last element', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.subarray( -3, -1 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ) + ]); + actual = arr.subarray( -30, -2 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 2, 0 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved beginning index exceeds the maximum array index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 5 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved ending index is less than or equal to zero', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 2, -8 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = arr.subarray( 1, 0 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_locale_string.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_locale_string.js new file mode 100644 index 000000000000..5b241bd8d6dc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_locale_string.js @@ -0,0 +1,187 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toLocaleString` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'toLocaleString' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.toLocaleString ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toLocaleString.call( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a string or an array of strings', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 0 ); + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [ 1, 2, 3 ], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toLocaleString( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a string or an array of strings (options)', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 0 ); + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [ 1, 2, 3 ], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toLocaleString( value, {} ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array(); + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + 'beep', + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toLocaleString( 'en-GB', value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.toLocaleString(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + expected = '1,2,3'; + + str = arr.toLocaleString(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_reversed.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_reversed.js new file mode 100644 index 000000000000..b35f5ca0f2d5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_reversed.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toReversed` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'toReversed' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.toReversed ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toReversed.call( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.toReversed(); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new typed array containing elements in reverse order', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); + expected = new Uint16Array([ + toWord( 5.05 ), + toWord( 4.05 ), + toWord( 3.05 ), + toWord( 2.05 ), + toWord( 1.05 ) + ]); + out = arr.toReversed(); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.toReversed(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_sorted.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_sorted.js new file mode 100644 index 000000000000..ed7ec6ea1966 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_sorted.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// FUNCTIONS // + +/** +* Comparison function. +* +* @private +* @param {boolean} a - first value for comparison +* @param {boolean} b - second value for comparison +* @returns {number} comparison result +*/ +function compareFcn( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toSorted` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'toSorted' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.toSorted ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toSorted.call( value, compareFcn ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toSorted( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.toSorted( compareFcn ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new typed array containing elements in sorted order', function test( t ) { + var expected; + var arr; + var out; + var buf; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ), + toWord( 5.05 ) + ]); + out = arr.toSorted( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + out = arr.toSorted( compareFcn ); + + t.strictEqual( out.length, arr.length, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_string.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_string.js new file mode 100644 index 000000000000..235e42f4c0cc --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.to_string.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'toString' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.toString ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toString.call( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.toString(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = '1,2,3,4'; + + str = arr.toString(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.values.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.values.js new file mode 100644 index 000000000000..12f332c747e1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.values.js @@ -0,0 +1,264 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `values` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'values' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.values ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.values.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var expected; + var arr; + var it; + var i; + var r; + var e; + + arr = new Float16Array( [ 1.05, 2.05 ] ); + expected = [ + { + 'value': float64ToFloat16( 1.05 ), + 'done': false + }, + { + 'value': float64ToFloat16( 2.05 ), + 'done': false + }, + { + 'done': true + } + ]; + it = arr.values(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + r = it.next(); + e = expected[ i ]; + if ( e.value === void 0 ) { + t.deepEqual( r, e, 'returns expected value' ); + } else { + t.strictEqual( isNumber( r.value ), true, 'returns expected value' ); + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { + var expected; + var arr; + var it; + var i; + var v; + + arr = new Float16Array( [] ); + expected = [ + { + 'done': true + }, + { + 'done': true + }, + { + 'done': true + } + ]; + it = arr.values(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + v = it.next(); + t.deepEqual( v, expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05 ] ); + it = arr.values(); + + v = it.next(); + t.strictEqual( v.value, float64ToFloat16( 1.05 ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, float64ToFloat16( 2.05 ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var arr; + var it; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05 ] ); + it = arr.values(); + + v = it.next(); + t.strictEqual( v.value, float64ToFloat16( 1.05 ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, float64ToFloat16( 2.05 ), 'returns expected value' ); + t.strictEqual( v.done, false, 'returns expected value' ); + + v = it.return( 'beep' ); + t.strictEqual( v.value, 'beep', 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + v = it.next(); + t.strictEqual( v.value, void 0, 'returns expected value' ); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator`, the method returns an iterable', function test( t ) { + var Float16Array; + var arr; + var buf; + var it1; + var it2; + var v1; + var v2; + var i; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it1 = arr.values(); + t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.strictEqual( typeof it2, 'object', 'returns expected value' ); + t.strictEqual( typeof it2.next, 'function', 'has `next` method' ); + t.strictEqual( typeof it2.return, 'function', 'has `return` method' ); + + for ( i = 0; i < arr.length; i++ ) { + v1 = it1.next().value; + v2 = it2.next().value; + t.strictEqual( v1, v2, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if an environment does not support `Symbol.iterator`, the method does not return an "iterable"', function test( t ) { + var Float16Array; + var arr; + var buf; + var it; + + Float16Array = proxyquire( './../../lib/polyfill', { + '@stdlib/symbol/iterator': false + }); + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.values(); + t.strictEqual( it[ ITERATOR_SYMBOL ], void 0, 'does not have property' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/polyfill/test.with.js b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.with.js new file mode 100644 index 000000000000..250c4b2e726e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/polyfill/test.with.js @@ -0,0 +1,213 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../../lib/polyfill' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `with` method', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array.prototype, 'with' ), true, 'has property' ); + t.strictEqual( isFunction( Float16Array.prototype.with ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with.call( value, 0, true ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with( value, true ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not in bounds', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + -11, + -12, + 11, + 12 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with( value, 1.0 ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a numeric value', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with( 0, value ); + }; + } +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.with( 5, 1.0 ); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new floating-point number array with the element at a provided index replaced with a provided value', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.with( 3, 2.05 ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.notEqual( out, arr, 'returns new instance' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.with( -1, 2.05 ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.at.js b/lib/node_modules/@stdlib/array/float16/test/test.at.js new file mode 100644 index 000000000000..b897ea60ffa5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.at.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `at` method for returning an array element', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.at ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.at.call( value, 0 ); + }; + } +}); + +tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) { + var arr; + var v; + var i; + + arr = new Float16Array( 10 ); + for ( i = -arr.length; i < arr.length; i++ ) { + if ( i < 0 ) { + v = arr.at( i-arr.length ); + t.strictEqual( v, void 0, 'returns expected value for index '+(i-arr.length) ); + } else { + v = arr.at( arr.length+i ); + t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) ); + } + } + t.end(); +}); + +tape( 'the method returns an array element', function test( t ) { + var arr; + var v; + var i; + + arr = []; + for ( i = 0; i < 10; i++ ) { + arr.push( i+0.05 ); + } + + arr = new Float16Array( arr ); + + for ( i = -arr.length; i < arr.length; i++ ) { + v = arr.at( i ); + if ( i < 0 ) { + t.strictEqual( v, float64ToFloat16( arr.length + i + 0.05 ), 'returns expected value for index '+i ); + } else { + t.strictEqual( v, float64ToFloat16( i + 0.05 ), 'returns expected value for index '+i ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.copy_within.js b/lib/node_modules/@stdlib/array/float16/test/test.copy_within.js new file mode 100644 index 000000000000..431058427857 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.copy_within.js @@ -0,0 +1,279 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a floating-point number array', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.copyWithin ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.copyWithin.call( value, 3, 0 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance (end)', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.copyWithin.call( value, 3, 0, 5 ); + }; + } +}); + +tape( 'the method copies a sequence of elements within an array', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative target)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( -arr.length, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative start)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, -2 ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (end=length)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 0, 3, arr.length ); + buf = new Uint16Array( arr.buffer ); + + // Overwritten: + t.strictEqual( buf[ 0 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 4.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (non-inclusive end)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0, 2 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (negative end)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0, -3 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + + // Remain the same: + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target >= length)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( arr.length, 3 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 2.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 3.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 4.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method copies a sequence of elements within an array (target > start)', function test( t ) { + var arr; + var buf; + + arr = [ 0.05, 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( arr ); + + arr.copyWithin( 2, 0 ); + buf = new Uint16Array( arr.buffer ); + + // Remain the same: + t.strictEqual( buf[ 0 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + + // Overwritten: + t.strictEqual( buf[ 2 ], toWord( 0.05 ), 'returns expected value' ); + t.strictEqual( buf[ 3 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 4 ], toWord( 2.05 ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.entries.js b/lib/node_modules/@stdlib/array/float16/test/test.entries.js new file mode 100644 index 000000000000..ebe44ae4cc86 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.entries.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.entries ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.entries.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var buf; + var arr; + var it; + var v; + var i; + + buf = [ 1.05, 2.05, 3.05, 4.05 ]; + arr = new Float16Array( buf ); + + it = arr.entries(); + t.strictEqual( it.next.length, 0, 'has zero arity' ); + + for ( i = 0; i < arr.length; i++ ) { + v = it.next(); + t.strictEqual( isArray( v.value ), true, 'returns expected value' ); + t.strictEqual( v.value[ 0 ], i, 'returns expected value' ); + t.strictEqual( isNumber( v.value[ 1 ] ), true, 'returns expected value' ); + t.strictEqual( v.value[ 1 ], float64ToFloat16( buf[ i ] ), 'returns expected value' ); + t.strictEqual( typeof v.done, 'boolean', 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.every.js b/lib/node_modules/@stdlib/array/float16/test/test.every.js new file mode 100644 index 000000000000..200fa31a8ce8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.every.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.every ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every.call( value, predicate ); + }; + } + + function predicate( v ) { + return v === 0.0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every( value ); + }; + } +}); + +tape( 'the method returns `true` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 1.05, 0.05, 1.05 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + bool = arr.every( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 1.05 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.fill.js b/lib/node_modules/@stdlib/array/float16/test/test.fill.js new file mode 100644 index 000000000000..32e1ed39423a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.fill.js @@ -0,0 +1,212 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.fill ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill.call( value, 1.0 ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.fill( 1.05 ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.fill( 1.05 ); + + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + arr.fill( 1.05 ); + + buf = new Uint16Array( arr.buffer ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 1 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 1.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 0, 2 ); + + t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, -3, -1 ); + + t.strictEqual( buf[ 0 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 1.05 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, -10 ); + + for ( i = 0; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { + var arr; + var buf; + var i; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.05, 1, 10 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + for ( i = 1; i < arr.length; i++ ) { + t.strictEqual( buf[ i ], toWord( 1.05 ), 'returns expected value' ); + } + + t.end(); +}); + +tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 3 ); + buf = new Uint16Array( arr.buffer ); + + arr.fill( 1.0, 2, 1 ); + + t.strictEqual( buf[ 0 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 1 ], toWord( 0.0 ), 'returns expected value' ); + t.strictEqual( buf[ 2 ], toWord( 0.0 ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.filter.js b/lib/node_modules/@stdlib/array/float16/test/test.filter.js new file mode 100644 index 000000000000..fca6e7ca69c9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.filter.js @@ -0,0 +1,224 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `filter` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.filter ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.filter.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.filter( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.filter( predicate ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method returns a new floating-point number array containing only those elements which satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 1.05, 2.05 ] ); + expected = new Uint16Array( [ toWord( 1.05 ), toWord( 1.05 ) ] ); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v === float64ToFloat16( 1.05 ) ); + } +}); + +tape( 'the method copies all elements to a new array if all elements satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v > 1.0 ); + } +}); + +tape( 'the method returns an empty array if no elements satisfy a test condition', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.filter( predicate ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 1.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var buf; + var ctx; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ) + ]); + ctx = { + 'count': 0 + }; + actual = arr.filter( predicate, ctx ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v === float64ToFloat16( 1.05 ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.find.js b/lib/node_modules/@stdlib/array/float16/test/test.find.js new file mode 100644 index 000000000000..819bb913baf3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.find.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `find` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.find ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.find.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.find( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.find( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the first element which passes a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + v = arr.find( predicate ); + + t.strictEqual( v, float64ToFloat16( -2.05 ), 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + v = arr.find( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var v; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + v = arr.find( predicate, ctx ); + + t.strictEqual( v, float64ToFloat16( 3.05 ), 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.find_index.js b/lib/node_modules/@stdlib/array/float16/test/test.find_index.js new file mode 100644 index 000000000000..db975626f30e --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.find_index.js @@ -0,0 +1,171 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findIndex` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.findIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the first element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, 1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.findIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + idx = arr.findIndex( predicate, ctx ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.find_last.js b/lib/node_modules/@stdlib/array/float16/test/test.find_last.js new file mode 100644 index 000000000000..9270d701c028 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.find_last.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLast` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.findLast ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLast.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 0.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLast( value ); + }; + } +}); + +tape( 'the method returns `undefined` if operating on an empty floating-point number array', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.findLast( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the last element which passes a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + v = arr.findLast( predicate ); + + t.strictEqual( v, float64ToFloat16( -4.05 ), 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `undefined` if all elements fail a test', function test( t ) { + var arr; + var v; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + v = arr.findLast( predicate ); + + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var v; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + v = arr.findLast( predicate, ctx ); + + t.strictEqual( v, float64ToFloat16( 5.05 ), 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.find_last_index.js b/lib/node_modules/@stdlib/array/float16/test/test.find_last_index.js new file mode 100644 index 000000000000..81f8e538d7f1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.find_last_index.js @@ -0,0 +1,171 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `findLastIndex` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.findLastIndex ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLastIndex.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( v === 1.0 ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.findLastIndex( value ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns the index of the last element which passes a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, -2.05, 3.05, -4.05 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method returns `-1` if all elements fail a test', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.findLastIndex( predicate ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( v < 0.0 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + var idx; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ -1.05, -2.05, 3.05, 4.05, 5.05 ] ); + idx = arr.findLastIndex( predicate, ctx ); + + t.strictEqual( idx, 4, 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0.0 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.for_each.js b/lib/node_modules/@stdlib/array/float16/test/test.for_each.js new file mode 100644 index 000000000000..e7527884880c --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.for_each.js @@ -0,0 +1,194 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `forEach` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.forEach ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.forEach.call( value, fcn ); + }; + } + + function fcn( v ) { + if ( !isNumber( v ) ) { + t.fail( 'should be a number' ); + } + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.forEach( value ); + }; + } +}); + +tape( 'the method should not invoke a provided callback function if operating on an empty floating-point array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + arr.forEach( fcn ); + + t.end(); + + function fcn() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `undefined`', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + out = arr.forEach( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + if ( !isNumber( v ) ) { + t.fail( 'should be a number' ); + } + } +}); + +tape( 'the method invokes a provided function for each element in an array', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var arr; + + indices = []; + values = []; + arrays = []; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + arr.forEach( fcn ); + + expected = [ + float64ToFloat16( 1.05 ), + float64ToFloat16( 2.05 ), + float64ToFloat16( 3.05 ), + float64ToFloat16( 4.05 ) + ]; + + t.deepEqual( values, expected, 'returns expected value' ); + t.deepEqual( indices, [ 0, 1, 2, 3 ], 'returns expected value' ); + t.strictEqual( arrays[ 0 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 1 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 2 ], arr, 'returns expected value' ); + t.strictEqual( arrays[ 3 ], arr, 'returns expected value' ); + + t.end(); + + function fcn( v, i, arr ) { + values.push( v ); + indices.push( i ); + arrays.push( arr ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + arr.forEach( fcn, ctx ); + + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.from.js b/lib/node_modules/@stdlib/array/float16/test/test.from.js new file mode 100644 index 000000000000..65420212117d --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.from.js @@ -0,0 +1,309 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Uint16Array = require( '@stdlib/array/uint16' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a `from` method for creating a 16-bit floating-point number array from an array-like object or an iterable', function test( t ) { + var arr; + + t.strictEqual( isFunction( Float16Array.from ), true, 'has method' ); + + arr = Float16Array.from( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array constructor', function test( t ) { + var values; + var i; + + values = [ + {}, + null, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from.call( value, [] ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( [], value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not a function (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.from( [], value, {} ); + }; + } +}); + +tape( 'the method returns a floating-point number array', function test( t ) { + var arr; + var v; + + // Generic array: + arr = Float16Array.from( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing non-numeric values: + arr = Float16Array.from( [ 'beep' ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ null, 4 ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + arr = Float16Array.from( [ true, {}, '' ] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 3, 'returns expected value' ); + + // Typed array: + arr = Float16Array.from( new Uint16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Floating-point number typed array: + arr = Float16Array.from( new Float16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Float16Array( [ 1.0, 2.0 ] ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method supports providing a "map" function which is invoked for each source element', function test( t ) { + var arr; + var v; + + // Generic array: + arr = Float16Array.from( [], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Generic array containing non-numeric values: + arr = Float16Array.from( [ 'beep' ], clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ null ], clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 1, 'returns expected value' ); + + arr = Float16Array.from( [ [], {} ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + arr = Float16Array.from( [ 4, 5 ], clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Typed array: + arr = Float16Array.from( new Uint16Array( 0 ), clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Uint16Array( [ 1, 1 ] ), clbk1 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Floating-point number typed array: + arr = Float16Array.from( new Float16Array( 0 ), clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = Float16Array.from( new Float16Array( [ true, true ] ), clbk2 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + return v; + } + + function clbk2() { + return true; + } +}); + +tape( 'the method supports providing a `this` context for a provided map function', function test( t ) { + var arr; + var ctx; + + ctx = { + 'count': 0 + }; + arr = Float16Array.from( [ 1.0, 2.0, 3.0, 4.0 ], clbk1, ctx ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function clbk1( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.includes.js b/lib/node_modules/@stdlib/array/float16/test/test.includes.js new file mode 100644 index 000000000000..b08ab983540a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.includes.js @@ -0,0 +1,160 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `includes` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.includes ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.includes.call( value, true ); + }; + } +}); + +tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.includes( 1.0 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if a floating-point number is not found', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 10 ); + bool = arr.includes( 1.0 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `true` if an array contains a specified floating-point number', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05] ); + bool = arr.includes( float64ToFloat16( 1.05 ) ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `false` if provided a second argument which exceeds the input array length', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 10 ); + bool = arr.includes( 0.0, 20 ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), 0 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), 3 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), -5 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), -2 ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 1.05, 1.05 ] ); + + bool = arr.includes( float64ToFloat16( 1.05 ), -10 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = arr.includes( float64ToFloat16( 2.05 ), -10 ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.index_of.js b/lib/node_modules/@stdlib/array/float16/test/test.index_of.js new file mode 100644 index 000000000000..8bf4a5523de3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.index_of.js @@ -0,0 +1,160 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `indexOf` method for returning the index of an array element', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.indexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.indexOf.call( value, 1.0 ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array(); + idx = arr.indexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.indexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match if a numeric value is found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + idx = arr.indexOf( float64ToFloat16( 2.05 ) ); + + t.strictEqual( idx, 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if provided a second argument which exceeds the input array length', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.indexOf( 1.0, 20 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 2 ); + t.strictEqual( idx, 3, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), 4 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -5 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'when provided a starting index which resolves to an index which is less than zero, the method searches from the first array element', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 2.05, 5.05 ] ); + + idx = arr.indexOf( float64ToFloat16( 2.05 ), -10 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = arr.indexOf( float64ToFloat16( 1.05 ), -10 ); + t.strictEqual( idx, 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.join.js b/lib/node_modules/@stdlib/array/float16/test/test.join.js new file mode 100644 index 000000000000..3db307d0e971 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.join.js @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.join ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.join.call( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.join(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator', function test( t ) { + var expected; + var str; + var arr; + var i; + + arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); + + expected = float64ToFloat16( 0.05 ); + for ( i = 1; i < arr.length; i++ ) { + expected += '@' + float64ToFloat16( i + 0.05 ); + } + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array with elements separated by a separator (single element)', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.05 ] ); + expected = '' + float64ToFloat16( 1.05 ); + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + + arr = new Float16Array( [ 1.05 ] ); + expected = '' + float64ToFloat16( 1.05 ); + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the method is invoked without a separator argument, the method returns a string representation of a floating-point number array with elements separated by a comma', function test( t ) { + var expected; + var str; + var arr; + var i; + + arr = new Float16Array( [ 0.05, 1.05, 2.05, 3.05, 4.05 ] ); + + expected = float64ToFloat16( 0.05 ); + for ( i = 1; i < arr.length; i++ ) { + expected += ',' + float64ToFloat16( i + 0.05 ); + } + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); 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..3887cf8a19fd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.js @@ -0,0 +1,320 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ArrayBuffer = require( '@stdlib/array/buffer' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var arr = new Float16Array( 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (no argument)', function test( t ) { + var arr = new Float16Array(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (length)', function test( t ) { + var arr = new Float16Array( 10 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (array)', function test( t ) { + var arr = new Float16Array( [] ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (typed array)', function test( t ) { + var arr = new Float16Array( new Uint16Array( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 0 ) ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 8 ), 8 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns a 16-bit floating-point number array (ArrayBuffer, byte offset, length)', function test( t ) { + var arr = new Float16Array( new ArrayBuffer( 8 ), 8, 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the constructor is a property returning the number of bytes per array element', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16Array.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the constructor is a property returning the constructor name', function test( t ) { + t.strictEqual( hasOwnProp( Float16Array, 'name' ), true, 'has property' ); + t.strictEqual( Float16Array.name, 'Float16Array', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `BYTES_PER_ELEMENT` property returning the number of bytes per array element', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( Float16Array.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Float16Array.prototype.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + + arr = new Float16Array( 0 ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `buffer` property for returning the underlying memory (i.e., ArrayBuffer)', function test( t ) { + var arr; + var buf; + + arr = new Float16Array( 0 ); + buf = arr.buffer; + t.strictEqual( isArrayBuffer( buf ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteLength` property for returning the number of bytes belonging to the array view', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 8 ); + v = arr.byteLength; + t.strictEqual( v, 56, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.byteLength; + t.strictEqual( v, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `byteOffset` property for returning the byte offset pointing to the first array element in the underlying memory', function test( t ) { + var arr; + var v; + + arr = new Float16Array( 0 ); + v = arr.byteOffset; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); + v = arr.byteOffset; + t.strictEqual( v, 32, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.byteOffset; + t.strictEqual( v, 64, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `length` property for returning the number of array elements', function test( t ) { + var arr; + var v; + + // No arguments: + arr = new Float16Array(); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Explicit array length: + arr = new Float16Array( 0 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( 10 ); + v = arr.length; + t.strictEqual( v, 10, 'returns expected value' ); + + // Generic array: + arr = new Float16Array( [] ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Typed array: + arr = new Float16Array( new Uint16Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new Uint16Array( [ 1.0, 1.0 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // Float16 typed array: + arr = new Float16Array( new Float16Array( 0 ) ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new Float16Array( [ 1.0, 2.0 ] ) ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + // ArrayBuffer: + arr = new Float16Array( new ArrayBuffer( 64 ), 32 ); + v = arr.length; + t.strictEqual( v, 16, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 64 ); + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + arr = new Float16Array( new ArrayBuffer( 64 ), 32, 2 ); + v = arr.length; + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor throws an error if provided an ArrayBuffer which is not a multiple of 2', function test( t ) { + var values; + var i; + + values = [ + 1, + 3, + 5, + 7, + 9, + 11, + 101, + 1001 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided an ArrayBuffer having a byte length equal to '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( value ) ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument which is not a multiple of 2', function test( t ) { + var values; + var i; + + values = [ + 1, + 3, + 5, + 7, + 9, + 11, + 101, + 1001 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 1e3 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided a byte offset argument such that the view byte length is not a multiple of 8', function test( t ) { + var values; + var i; + + values = [ + 2, + 4, + 6, + 8, + 10, + 12, + 14, + 16, + 18, + 20 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 101 ), value ); + }; + } +}); + +tape( 'the constructor throws an error if provided insufficient memory to accommodate byte offset and length arguments', function test( t ) { + var values; + var i; + + values = [ + 8, + 16, + 24, + 32 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Float16Array( new ArrayBuffer( 100 ), value, 1e3 ); + }; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.keys.js b/lib/node_modules/@stdlib/array/float16/test/test.keys.js new file mode 100644 index 000000000000..d0e1e5d6f0a2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.keys.js @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `keys` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.keys ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.keys.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var expected; + var arr; + var it; + var i; + var r; + var e; + + arr = new Float16Array( [ 1.05, 2.05 ] ); + expected = [ + { + 'value': 0, + 'done': false + }, + { + 'value': 1, + 'done': false + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + r = it.next(); + e = expected[ i ]; + if ( e.value === void 0 ) { + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } else { + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { + var expected; + var arr; + var it; + var i; + var v; + + arr = new Float16Array( [] ); + expected = [ + { + 'done': true + }, + { + 'done': true + }, + { + 'done': true + } + ]; + it = arr.keys(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + v = it.next(); + t.strictEqual( v.value, expected[ i ].value, 'returns expected value' ); + t.strictEqual( v.done, expected[ i ].done, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.last_index_of.js b/lib/node_modules/@stdlib/array/float16/test/test.last_index_of.js new file mode 100644 index 000000000000..ce2663dd2753 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.last_index_of.js @@ -0,0 +1,149 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `lastIndexOf` method for returning the index of an array element', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.lastIndexOf ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.lastIndexOf.call( value, true ); + }; + } +}); + +tape( 'the method returns `-1` if operating on an empty floating-point number array', function test( t ) { + var arr; + var idx; + + arr = new Float16Array( 0 ); + idx = arr.lastIndexOf( 0.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns `-1` if a numeric value is not found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( 10 ); + idx = arr.lastIndexOf( 1.0 ); + + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns the index of the first match when searching from the end of the array if a search element is found', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 1.05, 2.05 ] ); + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ) ); + + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 4 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports specifying a starting search index (negative)', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), -3 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'when the method is provided a starting index which resolves to an index which exceeds the maximum array index, the method searches from the last array element', function test( t ) { + var idx; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 2.05, 1.05, 1.05 ] ); + + idx = arr.lastIndexOf( float64ToFloat16( 1.05 ), 10 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + idx = arr.lastIndexOf( float64ToFloat16( 2.05 ), 10 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.map.js b/lib/node_modules/@stdlib/array/float16/test/test.map.js new file mode 100644 index 000000000000..fd50e1ff166a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.map.js @@ -0,0 +1,176 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var identity = require( '@stdlib/utils/identity-function' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `map` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.map ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.map.call( value, identity ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.map( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.map( identity ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.end(); +}); + +tape( 'the method returns a new floating-point number array containing elements which are the result of a provided callback function', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( -1.05 ), + toWord( -2.05 ), + toWord( -3.05 ), + toWord( -4.05 ) + ]); + actual = arr.map( invert ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); + + function invert( v ) { + return -v; + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var expected; + var actual; + var arr; + var buf; + var ctx; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( -1.05 ), + toWord( -2.05 ), + toWord( -3.05 ), + toWord( -4.05 ) + ]); + ctx = { + 'count': 0 + }; + actual = arr.map( invert, ctx ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 6, 'returns expected value' ); + t.end(); + + function invert( v, i ) { + this.count += i; // eslint-disable-line no-invalid-this + return -v; + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.of.js b/lib/node_modules/@stdlib/array/float16/test/test.of.js new file mode 100644 index 000000000000..90b95f971efd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.of.js @@ -0,0 +1,128 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `of` method for creating a 16-bit floating-point number array from a variable number of arguments', function test( t ) { + var arr; + + t.strictEqual( isFunction( Float16Array.of ), true, 'has method' ); + + arr = Float16Array.of(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a constructor', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.of.call( value, true, true ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point array constructor', function test( t ) { + var values; + var i; + + values = [ + {}, + null, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Float16Array.of.call( value, true, true ); + }; + } +}); + +tape( 'the method returns a floating-point number array', function test( t ) { + var arr; + var v; + + // No arguments: + arr = Float16Array.of(); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 0, 'returns expected value' ); + + // Numeric arguments: + arr = Float16Array.of( 1.0, 2.0, 3.0, 4.0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + // Non-numeric arguments: + arr = Float16Array.of( 1, {}, 0, null, 'beep' ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 5, 'returns expected value' ); + + // Mixed arguments: + arr = Float16Array.of( true, 1, false, 0 ); + t.strictEqual( arr instanceof Float16Array, true, 'returns expected value' ); + + v = arr.length; + t.strictEqual( v, 4, 'returns expected value' ); + + t.end(); +}); 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..8ec3cbe9cb9a --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.polyfill.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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' ); +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, no-undef + } + + 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.reduce.js b/lib/node_modules/@stdlib/array/float16/test/test.reduce.js new file mode 100644 index 000000000000..2e590f7ae2c4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.reduce.js @@ -0,0 +1,187 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reduce` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.reduce ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduce.call( value, reducer ); + }; + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduce( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduce( reducer ); + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var ind; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + accArray = [ 1.0, 3.0 ]; + valueArray = [ 2.0, 3.0 ]; + expected = float64ToFloat16( 6.0 ); + actual = arr.reduce( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + ind = index-1; + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + accArray = [ 2.0, 3.0, 5.0 ]; + valueArray = [ 1.0, 2.0, 3.0 ]; + expected = 8.0; + actual = arr.reduce( reducer, 2.0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + t.strictEqual( acc, float64ToFloat16( accArray[ index ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ index ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = float64ToFloat16( 10.20 ); + actual = arr.reduce( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.reduce_right.js b/lib/node_modules/@stdlib/array/float16/test/test.reduce_right.js new file mode 100644 index 000000000000..6a52c28722c5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.reduce_right.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reduceRight` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.reduceRight ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduceRight.call( value, reducer ); + }; + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reduceRight( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty floating-point number array', function test( t ) { + var arr; + + arr = new Float16Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduceRight( reducer ); + } + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method uses the last element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + len = arr.length; + accArray = [ 3.0, 5.0 ]; + valueArray = [ 2.0, 1.0 ]; + expected = float64ToFloat16( 6.0 ); + actual = arr.reduceRight( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + var ind = (len-index-2); + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + len = arr.length; + accArray = [ 2.0, 5.0, 7.0 ]; + valueArray = [ 3.0, 2.0, 1.0 ]; + expected = 8.0; + actual = arr.reduceRight( reducer, 2.0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value, index ) { + var ind = (len-index-1); + t.strictEqual( acc, float64ToFloat16( accArray[ ind ] ), 'returns expected value' ); + t.strictEqual( value, float64ToFloat16( valueArray[ ind ] ), 'returns expected value' ); + return float64ToFloat16( acc + value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = float64ToFloat16( 10.20 ); + actual = arr.reduceRight( reducer ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return float64ToFloat16( acc + value ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.reverse.js b/lib/node_modules/@stdlib/array/float16/test/test.reverse.js new file mode 100644 index 000000000000..6c66031f7257 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.reverse.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `reverse` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.reverse ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.reverse.call( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.reverse(); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method reverses elements of a floating-point number array in-place', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); + expected = new Uint16Array([ + toWord( 5.05 ), + toWord( 4.05 ), + toWord( 3.05 ), + toWord( 2.05 ), + toWord( 1.05 ) + ]); + out = arr.reverse(); + buf = new Uint16Array( arr.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.reverse(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.set.js b/lib/node_modules/@stdlib/array/float16/test/test.set.js new file mode 100644 index 000000000000..fd7cda137ace --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.set.js @@ -0,0 +1,225 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `set` method for setting one or more array elements', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.set ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.set.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if provided an index argument which is out-of-bounds', function test( t ) { + var values; + var arr1; + var arr2; + var i; + + arr1 = new Float16Array( 10 ); + arr2 = []; + for ( i = 0; i < arr1.length; i++ ) { + arr2.push( 1.0 ); + } + + values = [ + 1, + 2, + 3, + 4, + 5 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr1.set( arr2, value ); + }; + } +}); + +tape( 'the method sets one or more array elements', function test( t ) { + var arr; + var v; + var i; + + arr = new Float16Array( 10 ); + + v = arr[ 0 ]; + t.strictEqual( v, 0.0, 'returns expected value' ); + + // No index argument: + arr.set( [ 1.0 ] ); + + v = arr[ 0 ]; + t.strictEqual( v, 1.0, 'returns expected value' ); + + arr.set( [ 0.0 ] ); + + // Index argument: + for ( i = 0; i < arr.length; i++ ) { + v = arr[ i ]; + t.strictEqual( v, 0.0, 'returns expected value' ); + + arr.set( [ 1.05 ], i ); + + v = arr[ i ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + } + + // Multiple values, no index argument: + arr.set( [ 1.05, 2.05 ] ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); + + // Multiple values, index argument: + arr.set( [ 1.05, 2.05 ], 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( 1.05 ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( 2.05 ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the method sets an array element (floating-point number array; shared buffer)', function test( t ) { + var byteOffset; + var arr; + var src; + var buf; + var ab; + var v; + var i; + + byteOffset = 112; + + ab = new ArrayBuffer( 240 ); + arr = new Float16Array( ab, byteOffset, 10 ); + + // Overlapping (requires copy), multiple values, no index argument: + buf = [ 1.05, 2.05 ]; + src = new Float16Array( ab, byteOffset-(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (requires copy), multiple values, index argument: + buf = [ -1.05, -2.05 ]; + src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src, 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (no copy), multiple values, no index argument: + buf = [ 3.05, 4.05 ]; + src = new Float16Array( ab, byteOffset+(1*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src ); + + v = arr[ 0 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 1 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + // Overlapping (no copy), multiple values, index argument: + buf = [ -3.05, -4.05 ]; + src = new Float16Array( ab, byteOffset+(3*arr.BYTES_PER_ELEMENT), 2 ); + for ( i = 0; i < buf.length; i++ ) { + src[ i ] = buf[ i ]; + } + arr.set( src, 2 ); + + v = arr[ 2 ]; + t.strictEqual( v, float64ToFloat16( buf[ 0 ] ), 'returns expected value' ); + + v = arr[ 3 ]; + t.strictEqual( v, float64ToFloat16( buf[ 1 ] ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.slice.js b/lib/node_modules/@stdlib/array/float16/test/test.slice.js new file mode 100644 index 000000000000..eff999474fb8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.slice.js @@ -0,0 +1,249 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `slice` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.slice ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.slice.call( value ); + }; + } +}); + +tape( 'the method returns an empty typed array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.slice(); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'if called without arguments, the method returns a typed array containing the same elements as the original array', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice(); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.notEqual( actual, arr, 'returns a new instance' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method returns a typed array containing elements starting from a specified beginning index (inclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice( 1 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a typed array containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( 1, 3 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.slice( 1, 30 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method resolves negative indices relative to the last element', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( -3, -1 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.slice( -30, -2 ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 2, 0 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved beginning index exceeds the maximum array index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 5 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty typed array if a resolved ending index is less than or equal to zero', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 ] ); + expected = new Uint16Array( [] ); + actual = arr.slice( 2, -8 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = arr.slice( 1, 0 ); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length/2, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.some.js b/lib/node_modules/@stdlib/array/float16/test/test.some.js new file mode 100644 index 000000000000..0792e009b28b --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.some.js @@ -0,0 +1,194 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `some` method for returning boolean indicating whether at least one element passes a test', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.some ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.some.call( value, predicate ); + }; + } + + function predicate( v ) { + return v === 1.0; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.some( value ); + }; + } +}); + +tape( 'the method returns `false` if operating on an empty floating-point number array', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( 0 ); + bool = arr.some( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if at least one element passes a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 1.05 ); + } +}); + +tape( 'the method returns `false` if all elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return v === float64ToFloat16( 5.05 ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 4.05 ); + } +}); + +tape( 'the method stops executing upon encountering the first element which passes a test', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + bool = arr.some( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 1, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v === float64ToFloat16( 1.05 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.sort.js b/lib/node_modules/@stdlib/array/float16/test/test.sort.js new file mode 100644 index 000000000000..24d6ef7e23a8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.sort.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Comparison function. +* +* @private +* @param {boolean} a - first value for comparison +* @param {boolean} b - second value for comparison +* @returns {number} comparison result +*/ +function compareFcn( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `sort` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.sort ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.sort.call( value, compareFcn ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.sort( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.sort( compareFcn ); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method sorts elements of a floating-point number array in-place', function test( t ) { + var expected; + var arr; + var out; + var buf; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ), + toWord( 5.05 ) + ]); + out = arr.sort( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + arr = new Float16Array( [ 2.05, 1.05, -1.05, 0.05, -2.05 ] ); + expected = new Uint16Array([ + toWord( -2.05 ), + toWord( -1.05 ), + toWord( 0.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.sort( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + out = arr.sort( compareFcn ); + + t.strictEqual( out.length, arr.length, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.subarray.js b/lib/node_modules/@stdlib/array/float16/test/test.subarray.js new file mode 100644 index 000000000000..15de204d468f --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.subarray.js @@ -0,0 +1,246 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `subarray` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.subarray ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.subarray.call( value ); + }; + } +}); + +tape( 'the method returns empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.subarray(); + + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'if called without arguments, the method returns a view containing the same elements as the original array', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.subarray(); + buf = new Uint16Array( actual.buffer ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method returns a view containing elements starting from a specified beginning index (inclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ) + ]); + actual = arr.subarray( 1 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a view containing elements starting from a specified beginning index (inclusive) and ending at a specified stop index (exclusive)', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.subarray( 1, 3 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method resolves negative indices relative to the last element', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array([ + toWord( 2.05 ), + toWord( 3.05 ) + ]); + actual = arr.subarray( -3, -1 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ) + ]); + actual = arr.subarray( -30, -2 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 2, 0 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved beginning index exceeds the maximum array index', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 5 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty view if a resolved ending index is less than or equal to zero', function test( t ) { + var expected; + var actual; + var arr; + var buf; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05 ] ); + expected = new Uint16Array( [] ); + actual = arr.subarray( 2, -8 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + + actual = arr.subarray( 1, 0 ); + buf = new Uint16Array( actual.buffer, actual.byteOffset, actual.length ); + + t.strictEqual( actual.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( instanceOf( actual, Float16Array ), true, 'returns expected value' ); + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.to_locale_string.js b/lib/node_modules/@stdlib/array/float16/test/test.to_locale_string.js new file mode 100644 index 000000000000..034634e10451 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.to_locale_string.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toLocaleString` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.toLocaleString ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toLocaleString.call( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.toLocaleString(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + expected = '1,2,3'; + + str = arr.toLocaleString(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.to_reversed.js b/lib/node_modules/@stdlib/array/float16/test/test.to_reversed.js new file mode 100644 index 000000000000..70086434cc30 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.to_reversed.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toReversed` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.toReversed ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toReversed.call( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.toReversed(); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new typed array containing elements in reverse order', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 2.05, 3.05, 4.05, 5.05 ] ); + expected = new Uint16Array([ + toWord( 5.05 ), + toWord( 4.05 ), + toWord( 3.05 ), + toWord( 2.05 ), + toWord( 1.05 ) + ]); + out = arr.toReversed(); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.toReversed(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.to_sorted.js b/lib/node_modules/@stdlib/array/float16/test/test.to_sorted.js new file mode 100644 index 000000000000..409a224f9926 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.to_sorted.js @@ -0,0 +1,169 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Comparison function. +* +* @private +* @param {boolean} a - first value for comparison +* @param {boolean} b - second value for comparison +* @returns {number} comparison result +*/ +function compareFcn( a, b ) { + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toSorted` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.toSorted ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toSorted.call( value, compareFcn ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toSorted( value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty floating-point number array', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 0 ); + out = arr.toSorted( compareFcn ); + + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new typed array containing elements in sorted order', function test( t ) { + var expected; + var arr; + var out; + var buf; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 2.05 ), + toWord( 3.05 ), + toWord( 4.05 ), + toWord( 5.05 ) + ]); + out = arr.toSorted( compareFcn ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( [ 4.05, 3.05, 1.05, 5.05, 2.05 ] ); + out = arr.toSorted( compareFcn ); + + t.strictEqual( out.length, arr.length, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.to_string.js b/lib/node_modules/@stdlib/array/float16/test/test.to_string.js new file mode 100644 index 000000000000..21ec4bc57942 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.to_string.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.toString ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with an invalid `this` context', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toString.call( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new Float16Array( 0 ); + str = arr.toString(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a floating-point number array', function test( t ) { + var expected; + var str; + var arr; + + arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + expected = '1,2,3,4'; + + str = arr.toString(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.values.js b/lib/node_modules/@stdlib/array/float16/test/test.values.js new file mode 100644 index 000000000000..160e2cf119dd --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.values.js @@ -0,0 +1,147 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var isNumber = require( '@stdlib/assert/is-number' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `values` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.values ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.values.call( value ); + }; + } +}); + +tape( 'the method returns an iterator protocol-compliant object', function test( t ) { + var expected; + var arr; + var it; + var i; + var r; + var e; + + arr = new Float16Array( [ 1.05, 2.05 ] ); + expected = [ + { + 'value': float64ToFloat16( 1.05 ), + 'done': false + }, + { + 'value': float64ToFloat16( 2.05 ), + 'done': false + }, + { + 'done': true + } + ]; + it = arr.values(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + r = it.next(); + e = expected[ i ]; + if ( e.value === void 0 ) { + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } else { + t.strictEqual( isNumber( r.value ), true, 'returns expected value' ); + t.strictEqual( r.value, e.value, 'returns expected value' ); + t.strictEqual( r.done, e.done, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the method returns an iterator which does not iterate over empty arrays', function test( t ) { + var expected; + var arr; + var it; + var i; + var v; + + arr = new Float16Array( [] ); + expected = [ + { + 'done': true + }, + { + 'done': true + }, + { + 'done': true + } + ]; + it = arr.values(); + + t.strictEqual( typeof it, 'object', 'returns expected value' ); + t.strictEqual( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < expected.length; i++ ) { + v = it.next(); + t.strictEqual( v.value, expected[ i ].value, 'returns expected value' ); + t.strictEqual( v.done, expected[ i ].done, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/float16/test/test.with.js b/lib/node_modules/@stdlib/array/float16/test/test.with.js new file mode 100644 index 000000000000..e2bd1176cac8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/float16/test/test.with.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isFunction = require( '@stdlib/assert/is-function' ); +var toWord = require( '@stdlib/number/float16/base/to-word' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Float16Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float16Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `with` method', function test( t ) { + t.strictEqual( isFunction( Float16Array.prototype.with ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a floating-point number array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with.call( value, 0, true ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not in bounds', function test( t ) { + var values; + var arr; + var i; + + arr = new Float16Array( 10 ); + + values = [ + -11, + -12, + 11, + 12 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.with( value, 1.0 ); + }; + } +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Float16Array( 10 ); + out = arr.with( 5, 1.0 ); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a new floating-point number array with the element at a provided index replaced with a provided value', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.with( 3, 2.05 ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.notEqual( out, arr, 'returns new instance' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var expected; + var arr; + var buf; + var out; + + arr = new Float16Array( [ 1.05, 1.05, 1.05, 1.05 ] ); + expected = new Uint16Array([ + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 1.05 ), + toWord( 2.05 ) + ]); + out = arr.with( -1, 2.05 ); + buf = new Uint16Array( out.buffer ); + + t.strictEqual( out instanceof Float16Array, true, 'returns expected value' ); + t.deepEqual( buf, expected, 'returns expected value' ); + t.end(); +});