Skip to content

Commit b9502d5

Browse files
committed
feat: add complex32 type definitions and add Float16Array stub
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7a39426 commit b9502d5

1 file changed

Lines changed: 149 additions & 6 deletions

File tree

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

Lines changed: 149 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@
3434
* const x: ArrayLike<number> = [ 1, 2, 3 ];
3535
*/
3636
declare module '@stdlib/types/array' {
37-
import { ComplexLike, Complex64, Complex128 } from '@stdlib/types/complex';
37+
import { ComplexLike, Complex32, Complex64, Complex128 } from '@stdlib/types/complex';
3838
import { Remap } from '@stdlib/types/utilities';
3939

40+
/**
41+
* Half-precision floating-point typed array.
42+
*/
43+
type Float16Array = ArrayLike<number>; // FIXME: revisit once we upgrade TS to a version which natively supports Float16Array
44+
4045
/**
4146
* Data type.
4247
*/
@@ -95,7 +100,7 @@ declare module '@stdlib/types/array' {
95100
/**
96101
* Data type for complex number typed arrays.
97102
*/
98-
type ComplexFloatingPointDataType = 'complex64' | 'complex128'; // "complex_floating_point"
103+
type ComplexFloatingPointDataType = 'complex32' | 'complex64' | 'complex128'; // "complex_floating_point"
99104

100105
/**
101106
* Data type for complex number typed arrays.
@@ -474,7 +479,7 @@ declare module '@stdlib/types/array' {
474479
* @example
475480
* const x: ComplexTypedArray = new Complex64Array( 10 );
476481
*/
477-
type ComplexTypedArray = Complex64Array | Complex128Array;
482+
type ComplexTypedArray = Complex32Array | Complex64Array | Complex128Array;
478483

479484
/**
480485
* A real or complex array.
@@ -659,6 +664,50 @@ declare module '@stdlib/types/array' {
659664
set( value: ArrayLike<number | ComplexLike> | ComplexArrayLike | ComplexLike, i?: number ): void;
660665
}
661666

667+
/**
668+
* 32-bit complex number array.
669+
*
670+
* @example
671+
* const buf = new Float16Array( 8 );
672+
*
673+
* const z: Complex64Array = {
674+
* 'byteLength': 16,
675+
* 'byteOffset': 0,
676+
* 'BYTES_PER_ELEMENT': 2,
677+
* 'length': 4
678+
* 'get': ( i: number ): obj.Complex32 => {
679+
* return {
680+
* 're': i * 10,
681+
* 'im': i * 10,
682+
* 'byteLength': 4,
683+
* 'BYTES_PER_ELEMENT': 2
684+
* };
685+
* },
686+
* 'set': ( value: obj.ComplexLike, i?: number ) => {
687+
* i = ( i ) ? i : 0;
688+
* buf[ i ] = value.re;
689+
* buf[ i + 1 ] = value.im;
690+
* }
691+
* };
692+
*/
693+
interface Complex32Array extends ComplexArrayLike {
694+
/**
695+
* Returns an array element.
696+
*
697+
* @param i - element index
698+
* @returns array element
699+
*/
700+
get( i: number ): Complex32 | void;
701+
702+
/**
703+
* Sets an array element.
704+
*
705+
* @param value - value(s)
706+
* @param i - element index at which to start writing values (default: 0)
707+
*/
708+
set( value: ArrayLike<number | ComplexLike> | Complex32Array | ComplexLike, i?: number ): void;
709+
}
710+
662711
/**
663712
* 64-bit complex number array.
664713
*
@@ -803,6 +852,7 @@ declare module '@stdlib/types/array' {
803852
* Mapping of data types for complex number typed arrays to array constructors.
804853
*/
805854
type ComplexFloatingPointDataTypeMap = { // eslint-disable-line @typescript-eslint/consistent-type-definitions
855+
'complex32': Complex32Array;
806856
'complex64': Complex64Array;
807857
'complex128': Complex128Array;
808858
};
@@ -1504,7 +1554,7 @@ declare module '@stdlib/types/ndarray' {
15041554
/**
15051555
* Data type string for complex number ndarrays.
15061556
*/
1507-
type ComplexFloatingPointDataTypeString = 'complex64' | 'complex128'; // "complex_floating_point"
1557+
type ComplexFloatingPointDataTypeString = 'complex32' | 'complex64' | 'complex128'; // "complex_floating_point"
15081558

15091559
/**
15101560
* Data type string for complex number ndarrays.
@@ -2199,7 +2249,7 @@ declare module '@stdlib/types/ndarray' {
21992249
/**
22002250
* Data type object for complex number ndarrays.
22012251
*/
2202-
type ComplexFloatingPointDataTypeObject = Complex64DataTypeObject | Complex128DataTypeObject; // "complex_floating_point"
2252+
type ComplexFloatingPointDataTypeObject = Complex32DataTypeObject | Complex64DataTypeObject | Complex128DataTypeObject; // "complex_floating_point"
22032253

22042254
/**
22052255
* Data type object for complex number ndarrays.
@@ -4306,6 +4356,75 @@ declare module '@stdlib/types/ndarray' {
43064356
set( ...args: Array<number | ComplexLike> ): complex64ndarray;
43074357
}
43084358

4359+
/**
4360+
* Interface describing an ndarray having a half-precision complex floating-point data type.
4361+
*
4362+
* @example
4363+
* const arr: complex32ndarray = {
4364+
* 'byteLength': 12,
4365+
* 'BYTES_PER_ELEMENT': 4,
4366+
* 'data': new Complex32Array( [ 1, 2, 3, 4, 5, 6 ] ),
4367+
* 'dtype': 'complex32',
4368+
* 'flags': {
4369+
* 'ROW_MAJOR_CONTIGUOUS': true,
4370+
* 'COLUMN_MAJOR_CONTIGUOUS': false
4371+
* },
4372+
* 'length': 3,
4373+
* 'ndims': 1,
4374+
* 'offset': 0,
4375+
* 'order': 'row-major',
4376+
* 'shape': [ 3 ],
4377+
* 'strides': [ 1 ],
4378+
* 'get': function get( i ) {
4379+
* return new Complex32( this.data[ i*2 ], this.data[ (i*2)+1 ] );
4380+
* },
4381+
* 'set': function set( i, v ) {
4382+
* this.data[ i ] = v;
4383+
* return this;
4384+
* }
4385+
* };
4386+
*/
4387+
interface complex32ndarray extends complexndarray {
4388+
/**
4389+
* Size (in bytes) of each array element.
4390+
*/
4391+
BYTES_PER_ELEMENT: 4;
4392+
4393+
/**
4394+
* A reference to the underlying data buffer.
4395+
*/
4396+
data: Complex32Array;
4397+
4398+
/**
4399+
* Underlying data type.
4400+
*/
4401+
dtype: Complex32DataType;
4402+
4403+
/**
4404+
* Returns an array element specified according to provided subscripts.
4405+
*
4406+
* ## Notes
4407+
*
4408+
* - The number of provided subscripts should equal the number of dimensions.
4409+
*
4410+
* @param args - subscripts
4411+
* @returns array element
4412+
*/
4413+
get( ...args: Array<number> ): Complex32;
4414+
4415+
/**
4416+
* Sets an array element specified according to provided subscripts.
4417+
*
4418+
* ## Notes
4419+
*
4420+
* - The number of provided subscripts should equal the number of dimensions.
4421+
*
4422+
* @param args - subscripts and value to set
4423+
* @returns ndarray instance
4424+
*/
4425+
set( ...args: Array<number | ComplexLike> ): complex32ndarray;
4426+
}
4427+
43094428
/**
43104429
* Interface describing a one-dimensional ndarray having a homogeneous data type.
43114430
*
@@ -4471,6 +4590,7 @@ declare module '@stdlib/types/ndarray' {
44714590
* Mapping of data types for complex number typed ndarrays to ndarray constructors.
44724591
*/
44734592
type ComplexFloatingPointDataTypeMap = { // eslint-disable-line @typescript-eslint/consistent-type-definitions
4593+
'complex32': complex32ndarray;
44744594
'complex64': complex64ndarray;
44754595
'complex128': complex128ndarray;
44764596
};
@@ -5129,7 +5249,7 @@ declare module '@stdlib/types/complex' {
51295249
/**
51305250
* Complex number data type.
51315251
*/
5132-
type ComplexFloatingPointDataType = 'complex64' | 'complex128';
5252+
type ComplexFloatingPointDataType = 'complex32' | 'complex64' | 'complex128';
51335253

51345254
/**
51355255
* A complex number-like object.
@@ -5149,6 +5269,29 @@ declare module '@stdlib/types/complex' {
51495269
im: number;
51505270
}
51515271

5272+
/**
5273+
* A 32-bit complex number.
5274+
*
5275+
* @example
5276+
* const x: Complex32 = {
5277+
* 're': 5.0,
5278+
* 'im': 3.0,
5279+
* 'byteLength': 4,
5280+
* 'BYTES_PER_ELEMENT': 2
5281+
* };
5282+
*/
5283+
interface Complex32 extends ComplexLike {
5284+
/**
5285+
* Size (in bytes) of the complex number.
5286+
*/
5287+
byteLength: 4;
5288+
5289+
/**
5290+
* Size (in bytes) of each component.
5291+
*/
5292+
BYTES_PER_ELEMENT: 2;
5293+
}
5294+
51525295
/**
51535296
* A 64-bit complex number.
51545297
*

0 commit comments

Comments
 (0)