diff --git a/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/index.d.ts b/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/index.d.ts index a64c5bc8d781..1a6449f741c8 100644 --- a/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/index.d.ts @@ -22,7 +22,7 @@ /// -import { Collection, Complex64Array, Complex128Array, AccessorArrayLike } from '@stdlib/types/array'; +import { Collection, Complex64Array, Complex128Array, Float16Array, AccessorArrayLike } from '@stdlib/types/array'; import { Complex64, Complex128, ComplexLike } from '@stdlib/types/complex'; /** @@ -43,6 +43,15 @@ type GetFloat64 = ( arr: Float64Array, idx: number ) => number | void; */ type GetFloat32 = ( arr: Float32Array, idx: number ) => number | void; +/** +* Returns an element from a `Float16Array`. +* +* @param arr - input array +* @param idx - element index +* @returns element value +*/ +type GetFloat16 = ( arr: Float16Array, idx: number ) => number | void; + /** * Returns an element from an `Int32Array`. * @@ -169,6 +178,15 @@ type SetFloat64 = ( arr: Float64Array, idx: number, value: number ) => void; */ type SetFloat32 = ( arr: Float32Array, idx: number, value: number ) => void; +/** +* Sets an element in a `Float16Array`. +* +* @param arr - input array +* @param idx - element index +* @param value - value to set +*/ +type SetFloat16 = ( arr: Float16Array, idx: number, value: number ) => void; + /** * Sets an element in an `Int32Array`. * @@ -347,6 +365,31 @@ interface Float32AccessorObject extends OutputObject { accessors: [ GetFloat32, SetFloat32 ]; } +/** +* Interface describing the output object for a `Float16Array`. +*/ +interface Float16AccessorObject extends OutputObject { + /** + * Reference to the original array-like object. + */ + data: Float16Array; + + /** + * Data type. + */ + dtype: 'float16'; + + /** + * Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements). + */ + accessorProtocol: false; + + /** + * Two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element. + */ + accessors: [ GetFloat16, SetFloat16 ]; +} + /** * Interface describing the output object for an `Int32Array`. */ @@ -683,7 +726,7 @@ interface GetSetAccessorObject extends OutputObject { * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Float64Array, stride: number, offset: number ): Float64AccessorObject; @@ -724,11 +767,52 @@ declare function strided2object( N: number, x: Float64Array, stride: number, off * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Float32Array, stride: number, offset: number ): Float32AccessorObject; +/** +* Converts a strided array and associated metadata to an object likely to have the same "shape". +* +* ## Notes +* +* - This function is intended as a potential performance optimization. In V8, for example, even if two objects share common properties, if those properties were added in different orders or if one object has additional properties not shared by the other object, then those objects will have different "hidden" classes. If a function is provided many objects having different "shapes", some JavaScript VMs (e.g., V8) will consider the function "megamorphic" and fail to perform various runtime optimizations. Accordingly, the intent of this function is to standardize the "shape" of the object holding strided array metadata to ensure that internal functions operating on strided arrays are provided consistent argument "shapes". +* +* - The returned object has the following properties: +* +* - **data**: reference to the input array. +* - **dtype**: array data type. +* - **length**: number of indexed elements. +* - **stride**: index increment. +* - **offset**: starting index. +* - **accessorProtocol**: boolean indicating whether the input array uses accessors for getting and setting elements. +* - **accessors**: a two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element. +* +* @param N - number of indexed elements +* @param x - input array +* @param stride - index increment +* @param offset - index offset +* @returns object containing strided array data +* +* @example +* var Float16Array = require( '@stdlib/array/float16' ); +* +* var x = new Float16Array( [ 1, 2, 3, 4 ] ); +* var obj = strided2object( 4, x, 1, 0 ); +* // returns {...} +* +* var bool = obj.accessorProtocol; +* // returns false +* +* var fcns = obj.accessors; +* // returns [ , ] +* +* var v = fcns[ 0 ]( x, 2 ); +* // returns 3 +*/ +declare function strided2object( N: number, x: Float16Array, stride: number, offset: number ): Float16AccessorObject; + /** * Converts a strided array and associated metadata to an object likely to have the same "shape". * @@ -765,7 +849,7 @@ declare function strided2object( N: number, x: Float32Array, stride: number, off * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Int32Array, stride: number, offset: number ): Int32AccessorObject; @@ -806,7 +890,7 @@ declare function strided2object( N: number, x: Int32Array, stride: number, offse * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Int16Array, stride: number, offset: number ): Int16AccessorObject; @@ -847,7 +931,7 @@ declare function strided2object( N: number, x: Int16Array, stride: number, offse * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Int8Array, stride: number, offset: number ): Int8AccessorObject; @@ -888,7 +972,7 @@ declare function strided2object( N: number, x: Int8Array, stride: number, offset * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Uint32Array, stride: number, offset: number ): Uint32AccessorObject; @@ -929,7 +1013,7 @@ declare function strided2object( N: number, x: Uint32Array, stride: number, offs * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Uint16Array, stride: number, offset: number ): Uint16AccessorObject; @@ -970,7 +1054,7 @@ declare function strided2object( N: number, x: Uint16Array, stride: number, offs * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Uint8Array, stride: number, offset: number ): Uint8AccessorObject; @@ -1011,7 +1095,7 @@ declare function strided2object( N: number, x: Uint8Array, stride: number, offse * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Uint8ClampedArray, stride: number, offset: number ): Uint8cAccessorObject; @@ -1144,7 +1228,7 @@ declare function strided2object( N: number, x: Complex64Array, stride: number, o * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: AccessorArrayLike, stride: number, offset: number ): GetSetAccessorObject; @@ -1183,7 +1267,7 @@ declare function strided2object( N: number, x: AccessorArrayLike * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Array, stride: number, offset: number ): GenericAccessorObject; @@ -1228,7 +1312,7 @@ declare function strided2object( N: number, x: Array, stride: nu * var fcns = obj.accessors; * // returns [ , ] * -* var v = fcns[ 0 ]( x.data, 2 ); +* var v = fcns[ 0 ]( x, 2 ); * // returns 3 */ declare function strided2object( N: number, x: Collection, stride: number, offset: number ): IndexedAccessorObject; diff --git a/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/test.ts b/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/test.ts index 859a323f900c..ac2410e05ba3 100644 --- a/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/test.ts +++ b/lib/node_modules/@stdlib/strided/base/strided2object/docs/types/test.ts @@ -21,6 +21,7 @@ import { AccessorArrayLike, ArrayLike } from '@stdlib/types/array'; import Complex128Array = require( '@stdlib/array/complex128' ); import Complex64Array = require( '@stdlib/array/complex64' ); +import Float16Array = require( '@stdlib/array/float16' ); import strided2object = require( './index' ); /** @@ -79,38 +80,41 @@ function arrayLike(): ArrayLike { const x3 = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ); strided2object( 6, x3, 1, 0 ); // $ExpectType Float32AccessorObject - const x4 = new Int32Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x4, 1, 0 ); // $ExpectType Int32AccessorObject + const x4 = new Float16Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x4, 1, 0 ); // $ExpectType Float16AccessorObject - const x5 = new Int16Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x5, 1, 0 ); // $ExpectType Int16AccessorObject + const x5 = new Int32Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x5, 1, 0 ); // $ExpectType Int32AccessorObject - const x6 = new Int8Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x6, 1, 0 ); // $ExpectType Int8AccessorObject + const x6 = new Int16Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x6, 1, 0 ); // $ExpectType Int16AccessorObject - const x7 = new Uint32Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x7, 1, 0 ); // $ExpectType Uint32AccessorObject + const x7 = new Int8Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x7, 1, 0 ); // $ExpectType Int8AccessorObject - const x8 = new Uint16Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x8, 1, 0 ); // $ExpectType Uint16AccessorObject + const x8 = new Uint32Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x8, 1, 0 ); // $ExpectType Uint32AccessorObject - const x9 = new Uint8Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x9, 1, 0 ); // $ExpectType Uint8AccessorObject + const x9 = new Uint16Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x9, 1, 0 ); // $ExpectType Uint16AccessorObject - const x10 = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x10, 1, 0 ); // $ExpectType Uint8cAccessorObject + const x10 = new Uint8Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x10, 1, 0 ); // $ExpectType Uint8AccessorObject - const x11 = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x11, 1, 0 ); // $ExpectType Complex128AccessorObject + const x11 = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x11, 1, 0 ); // $ExpectType Uint8cAccessorObject - const x12 = new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ); - strided2object( 6, x12, 1, 0 ); // $ExpectType Complex64AccessorObject + const x12 = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x12, 1, 0 ); // $ExpectType Complex128AccessorObject - const x13 = accessorArray(); - strided2object( 6, x13, 1, 0 ); // $ExpectType GetSetAccessorObject + const x13 = new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ); + strided2object( 6, x13, 1, 0 ); // $ExpectType Complex64AccessorObject - const x14 = arrayLike(); - strided2object( 6, x14, 1, 0 ); // $ExpectType IndexedAccessorObject + const x14 = accessorArray(); + strided2object( 6, x14, 1, 0 ); // $ExpectType GetSetAccessorObject + + const x15 = arrayLike(); + strided2object( 6, x15, 1, 0 ); // $ExpectType IndexedAccessorObject } // The compiler throws an error if the function is provided a first argument which is not a number...