Skip to content

Commit fa7e420

Browse files
committed
feat!: move complex number types to separate module
BREAKING CHANGE: move complex number types to separate module To migrate, users should import `@stdlib/types/complex` instead of `@stdlib/types/object` when wanting to use complex number type definitions.
1 parent b0b5d31 commit fa7e420

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

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

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

3939
/**
4040
* Data type.
@@ -316,7 +316,7 @@ declare module '@stdlib/types/array' {
316316
* const x: IntegerTypedArray = new Uint32Array( 10 );
317317
* const y: IntegerTypedArray = new Int32Array( 10 );
318318
*/
319-
type IntegerTypedArray = SignedIntegerTypedArray | UnsignedIntegerTypedArray; // tslint:disable-line:max-line-length
319+
type IntegerTypedArray = SignedIntegerTypedArray | UnsignedIntegerTypedArray;
320320

321321
/**
322322
* A signed integer typed array.
@@ -332,7 +332,7 @@ declare module '@stdlib/types/array' {
332332
* @example
333333
* const x: UnsignedIntegerTypedArray = new Uint32Array( 10 );
334334
*/
335-
type UnsignedIntegerTypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array; // tslint:disable-line:max-line-length
335+
type UnsignedIntegerTypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
336336

337337
/**
338338
* A floating-point typed array.
@@ -435,7 +435,7 @@ declare module '@stdlib/types/array' {
435435
* @param value - value(s)
436436
* @param i - element index at which to start writing values (default: 0)
437437
*/
438-
set( value: ArrayLike<number | ComplexLike> | ComplexArrayLike | ComplexLike, i?: number ): void; // tslint:disable-line:max-line-length
438+
set( value: ArrayLike<number | ComplexLike> | ComplexArrayLike | ComplexLike, i?: number ): void;
439439
}
440440

441441
/**
@@ -479,7 +479,7 @@ declare module '@stdlib/types/array' {
479479
* @param value - value(s)
480480
* @param i - element index at which to start writing values (default: 0)
481481
*/
482-
set( value: ArrayLike<number | ComplexLike> | Complex64Array | ComplexLike, i?: number ): void; // tslint:disable-line:max-line-length
482+
set( value: ArrayLike<number | ComplexLike> | Complex64Array | ComplexLike, i?: number ): void;
483483
}
484484

485485
/**
@@ -523,7 +523,7 @@ declare module '@stdlib/types/array' {
523523
* @param value - value(s)
524524
* @param i - element index at which to start writing values (default: 0)
525525
*/
526-
set( value: ArrayLike<number | ComplexLike> | Complex128Array | ComplexLike, i?: number ): void; // tslint:disable-line:max-line-length
526+
set( value: ArrayLike<number | ComplexLike> | Complex128Array | ComplexLike, i?: number ): void;
527527
}
528528
}
529529

@@ -732,8 +732,9 @@ declare module '@stdlib/types/iter' {
732732
* };
733733
*/
734734
declare module '@stdlib/types/ndarray' {
735-
import { ArrayLike, AccessorArrayLike, Complex128Array, Complex64Array, RealOrComplexTypedArray, FloatOrComplexTypedArray, RealTypedArray, ComplexTypedArray, IntegerTypedArray, FloatTypedArray, SignedIntegerTypedArray, UnsignedIntegerTypedArray } from '@stdlib/types/array'; // tslint:disable-line:max-line-length
736-
import { ComplexLike, Complex128, Complex64, Collection } from '@stdlib/types/object';
735+
import { ArrayLike, AccessorArrayLike, Complex128Array, Complex64Array, RealOrComplexTypedArray, FloatOrComplexTypedArray, RealTypedArray, ComplexTypedArray, IntegerTypedArray, FloatTypedArray, SignedIntegerTypedArray, UnsignedIntegerTypedArray } from '@stdlib/types/array';
736+
import { ComplexLike, Complex128, Complex64 } from '@stdlib/types/complex';
737+
import { Collection } from '@stdlib/types/object';
737738

738739
/**
739740
* Data type.
@@ -783,7 +784,7 @@ declare module '@stdlib/types/ndarray' {
783784
/**
784785
* Output data type policy.
785786
*/
786-
type OutputPolicy = 'default' | 'same' | 'promoted' | 'bool' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer'; // tslint:disable-line:max-line-length
787+
type OutputPolicy = 'default' | 'same' | 'promoted' | 'bool' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
787788

788789
/**
789790
* Array order.
@@ -2501,7 +2502,7 @@ declare module '@stdlib/types/object' {
25012502
* 'value': 'beep'
25022503
* };
25032504
*/
2504-
type PropertyDescriptor = DataPropertyDescriptor | AccessorPropertyDescriptor; // tslint:disable-line:max-line-length
2505+
type PropertyDescriptor = DataPropertyDescriptor | AccessorPropertyDescriptor;
25052506

25062507
/**
25072508
* An object property name.
@@ -2518,7 +2519,17 @@ declare module '@stdlib/types/object' {
25182519
* const x: Collection<number> = [ 1, 2, 3 ];
25192520
*/
25202521
type Collection<T = any> = Array<T> | TypedArray | ArrayLike<T>;
2522+
}
25212523

2524+
/**
2525+
* Module containing definitions for complex numbers.
2526+
*
2527+
* @example
2528+
* import * as complex from `@stdlib/types/complex`;
2529+
*
2530+
* const x: complex.ComplexLike = { 're': 5.0, 'im': 3.0 };
2531+
*/
2532+
declare module '@stdlib/types/complex' {
25222533
/**
25232534
* Complex number data type.
25242535
*/

lib/node_modules/@stdlib/types/test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as array from '@stdlib/types/array';
2222
import * as iter from '@stdlib/types/iter';
2323
import * as ndarray from '@stdlib/types/ndarray';
2424
import * as obj from '@stdlib/types/object';
25+
import * as complex from '@stdlib/types/complex';
2526
import * as random from '@stdlib/types/random';
2627

2728
/**
@@ -113,13 +114,13 @@ function cmplxArray(): array.ComplexArrayLike {
113114
'byteOffset': 0,
114115
'BYTES_PER_ELEMENT': 8,
115116
'length': 8,
116-
'get': ( i: number ): obj.ComplexLike => {
117+
'get': ( i: number ): complex.ComplexLike => {
117118
return {
118119
're': i * 10,
119120
'im': i * 10
120121
};
121122
},
122-
'set': ( value: obj.ComplexLike, i?: number ) => {
123+
'set': ( value: complex.ComplexLike, i?: number ) => {
123124
i = ( i ) ? i : 0;
124125
buf[ i ] = value.re;
125126
buf[ i + 1 ] = value.im;
@@ -140,15 +141,15 @@ function cmplx64Array(): array.Complex64Array {
140141
'byteOffset': 0,
141142
'BYTES_PER_ELEMENT': 8,
142143
'length': 8,
143-
'get': ( i: number ): obj.Complex64 => {
144+
'get': ( i: number ): complex.Complex64 => {
144145
return {
145146
're': i * 10,
146147
'im': i * 10,
147148
'byteLength': 8,
148149
'BYTES_PER_ELEMENT': 4
149150
};
150151
},
151-
'set': ( value: obj.Complex64, i?: number ) => {
152+
'set': ( value: complex.Complex64, i?: number ) => {
152153
i = ( i ) ? i : 0;
153154
buf[ i ] = value.re;
154155
buf[ i + 1 ] = value.im;
@@ -169,15 +170,15 @@ function cmplx128Array(): array.Complex128Array {
169170
'byteOffset': 0,
170171
'BYTES_PER_ELEMENT': 16,
171172
'length': 8,
172-
'get': ( i: number ): obj.Complex128 => {
173+
'get': ( i: number ): complex.Complex128 => {
173174
return {
174175
're': i * 10,
175176
'im': i * 10,
176177
'byteLength': 16,
177178
'BYTES_PER_ELEMENT': 8
178179
};
179180
},
180-
'set': ( value: obj.Complex128, i?: number ) => {
181+
'set': ( value: complex.Complex128, i?: number ) => {
181182
i = ( i ) ? i : 0;
182183
buf[ i ] = value.re;
183184
buf[ i + 1 ] = value.im;
@@ -538,32 +539,35 @@ function cmplx128Array(): array.Complex128Array {
538539
if ( arr.length !== 3 ) {
539540
throw new Error( 'something went wrong' );
540541
}
542+
}
541543

542-
const z: obj.ComplexLike = {
544+
// The compiler should not throw an error when using complex number types...
545+
{
546+
const v1: complex.ComplexLike = {
543547
're': 1.0,
544548
'im': 1.0
545549
};
546-
if ( z.re !== 1.0 ) {
550+
if ( v1.re !== 1.0 ) {
547551
throw new Error( 'something went wrong' );
548552
}
549553

550-
const z64: obj.Complex64 = {
554+
const v2: complex.Complex64 = {
551555
're': 1.0,
552556
'im': 1.0,
553557
'byteLength': 8,
554558
'BYTES_PER_ELEMENT': 4
555559
};
556-
if ( z64.re !== 1.0 ) {
560+
if ( v2.re !== 1.0 ) {
557561
throw new Error( 'something went wrong' );
558562
}
559563

560-
const z128: obj.Complex128 = {
564+
const v3: complex.Complex128 = {
561565
're': 1.0,
562566
'im': 1.0,
563567
'byteLength': 16,
564568
'BYTES_PER_ELEMENT': 8
565569
};
566-
if ( z128.re !== 1.0 ) {
570+
if ( v3.re !== 1.0 ) {
567571
throw new Error( 'something went wrong' );
568572
}
569573
}

0 commit comments

Comments
 (0)