Skip to content

Commit f6efb5e

Browse files
authored
feat: add support for float16 array types
PR-URL: stdlib-js#9806 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent bcac5a8 commit f6efb5e

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

lib/node_modules/@stdlib/types/index.d.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare module '@stdlib/types/array' {
5555
/**
5656
* Data type for floating-point typed arrays.
5757
*/
58-
type RealFloatingPointDataType = 'float64' | 'float32'; // "real_floating_point"
58+
type RealFloatingPointDataType = 'float64' | 'float32' | 'float16'; // "real_floating_point"
5959

6060
/**
6161
* Data type for floating-point typed arrays.
@@ -464,8 +464,9 @@ declare module '@stdlib/types/array' {
464464
* @example
465465
* const x: FloatTypedArray = new Float64Array( 10 );
466466
* const y: FloatTypedArray = new Float32Array( 10 );
467+
* const z: FloatTypedArray = new Float16Array( 10 );
467468
*/
468-
type FloatTypedArray = Float32Array | Float64Array;
469+
type FloatTypedArray = Float16Array | Float32Array | Float64Array;
469470

470471
/**
471472
* A complex number typed array.
@@ -790,6 +791,7 @@ declare module '@stdlib/types/array' {
790791
type RealFloatingPointDataTypeMap = { // eslint-disable-line @typescript-eslint/consistent-type-definitions
791792
'float64': Float64Array;
792793
'float32': Float32Array;
794+
'float16': Float16Array;
793795
};
794796

795797
/**
@@ -1462,7 +1464,7 @@ declare module '@stdlib/types/ndarray' {
14621464
/**
14631465
* Data type string for floating-point ndarrays.
14641466
*/
1465-
type RealFloatingPointDataTypeString = 'float64' | 'float32'; // "real_floating_point"
1467+
type RealFloatingPointDataTypeString = 'float64' | 'float32' | 'float16'; // "real_floating_point"
14661468

14671469
/**
14681470
* Data type string for floating-point ndarrays.
@@ -2157,7 +2159,7 @@ declare module '@stdlib/types/ndarray' {
21572159
/**
21582160
* Data type object for floating-point ndarrays.
21592161
*/
2160-
type RealFloatingPointDataTypeObject = Float64DataTypeObject | Float32DataTypeObject; // "real_floating_point"
2162+
type RealFloatingPointDataTypeObject = Float64DataTypeObject | Float32DataTypeObject | Float16DataTypeObject; // "real_floating_point"
21612163

21622164
/**
21632165
* Data type object for floating-point ndarrays.
@@ -3150,6 +3152,63 @@ declare module '@stdlib/types/ndarray' {
31503152
set( ...args: Array<number> ): float32ndarray;
31513153
}
31523154

3155+
/**
3156+
* Interface describing an ndarray having a half-precision floating-point data type.
3157+
*
3158+
* @example
3159+
* const arr: float16ndarray = {
3160+
* 'byteLength': 6,
3161+
* 'BYTES_PER_ELEMENT': 2,
3162+
* 'data': new Float16Array( [ 1, 2, 3 ] ),
3163+
* 'dtype': 'float16',
3164+
* 'flags': {
3165+
* 'ROW_MAJOR_CONTIGUOUS': true,
3166+
* 'COLUMN_MAJOR_CONTIGUOUS': false
3167+
* },
3168+
* 'length': 3,
3169+
* 'ndims': 1,
3170+
* 'offset': 0,
3171+
* 'order': 'row-major',
3172+
* 'shape': [ 3 ],
3173+
* 'strides': [ 1 ],
3174+
* 'get': function get( i ) {
3175+
* return this.data[ i ];
3176+
* },
3177+
* 'set': function set( i, v ) {
3178+
* this.data[ i ] = v;
3179+
* return this;
3180+
* }
3181+
* };
3182+
*/
3183+
interface float16ndarray extends floatndarray {
3184+
/**
3185+
* Size (in bytes) of each array element.
3186+
*/
3187+
BYTES_PER_ELEMENT: 2;
3188+
3189+
/**
3190+
* A reference to the underlying data buffer.
3191+
*/
3192+
data: Float16Array;
3193+
3194+
/**
3195+
* Underlying data type.
3196+
*/
3197+
dtype: Float16DataType;
3198+
3199+
/**
3200+
* Sets an array element specified according to provided subscripts.
3201+
*
3202+
* ## Notes
3203+
*
3204+
* - The number of provided subscripts should equal the number of dimensions.
3205+
*
3206+
* @param args - subscripts and value to set
3207+
* @returns ndarray instance
3208+
*/
3209+
set( ...args: Array<number> ): float16ndarray;
3210+
}
3211+
31533212
/**
31543213
* Interface describing an ndarray having an integer data type.
31553214
*
@@ -4400,6 +4459,7 @@ declare module '@stdlib/types/ndarray' {
44004459
type RealFloatingPointDataTypeMap = { // eslint-disable-line @typescript-eslint/consistent-type-definitions
44014460
'float64': float64ndarray;
44024461
'float32': float32ndarray;
4462+
'float16': float16ndarray;
44034463
};
44044464

44054465
/**

0 commit comments

Comments
 (0)