Skip to content

Commit 265e6f5

Browse files
committed
Add support for providing complex number arrays
1 parent 415b3d6 commit 265e6f5

File tree

22 files changed

+774
-68
lines changed

22 files changed

+774
-68
lines changed

lib/node_modules/@stdlib/math/strided/ops/add/benchmark/benchmark.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ var types = [
3939
'float64', 'float64', 'float64',
4040
'float32', 'float32', 'float32',
4141
'int32', 'int32', 'int32',
42-
'uint8', 'uint8', 'uint8'
42+
'uint8', 'uint8', 'uint8',
43+
'complex64', 'complex64', 'complex64',
44+
'complex128', 'complex128', 'complex128'
4345
];
4446
var rand = uniform( 0.0, 10.0 );
4547

@@ -112,18 +114,28 @@ function main() {
112114
var t1;
113115
var t2;
114116
var t3;
117+
var re;
118+
var N;
115119
var f;
116120
var i;
117121
var j;
118122

119123
min = 1; // 10^min
120124
max = 6; // 10^max
121125

126+
re = /^complex/;
127+
122128
for ( j = 0; j < types.length; j += 3 ) {
123129
t1 = resolveStr( types[ j ] );
124130
t2 = resolveStr( types[ j+1 ] );
125131
t3 = resolveStr( types[ j+2 ] );
126-
for ( i = min; i <= max; i++ ) {
132+
133+
if ( re.test( t1 ) || re.test( t2 ) || re.test( t3 ) ) {
134+
N = 4;
135+
} else {
136+
N = max;
137+
}
138+
for ( i = min; i <= N; i++ ) {
127139
len = pow( 10, i );
128140
f = createBenchmark( len, t1, t2, t3 );
129141
bench( pkg+':len='+len+',xtype='+t1+',ytype='+t2+',ztype='+t3, f );

lib/node_modules/@stdlib/math/strided/ops/add/benchmark/benchmark.native.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ var types = [
4444
'float64', 'float64', 'float64',
4545
'float32', 'float32', 'float32',
4646
'int32', 'int32', 'int32',
47-
'uint8', 'uint8', 'uint8'
47+
'uint8', 'uint8', 'uint8',
48+
'complex64', 'complex64', 'complex64',
49+
'complex128', 'complex128', 'complex128'
4850
];
4951
var rand = uniform( 0.0, 10.0 );
5052

lib/node_modules/@stdlib/math/strided/ops/add/benchmark/benchmark.ndarray.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ var types = [
3939
'float64', 'float64', 'float64',
4040
'float32', 'float32', 'float32',
4141
'int32', 'int32', 'int32',
42-
'uint8', 'uint8', 'uint8'
42+
'uint8', 'uint8', 'uint8',
43+
'complex64', 'complex64', 'complex64',
44+
'complex128', 'complex128', 'complex128'
4345
];
4446
var rand = uniform( 0.0, 10.0 );
4547

@@ -112,18 +114,28 @@ function main() {
112114
var t1;
113115
var t2;
114116
var t3;
117+
var re;
118+
var N;
115119
var f;
116120
var i;
117121
var j;
118122

119123
min = 1; // 10^min
120124
max = 6; // 10^max
121125

126+
re = /^complex/;
127+
122128
for ( j = 0; j < types.length; j += 3 ) {
123129
t1 = resolveStr( types[ j ] );
124130
t2 = resolveStr( types[ j+1 ] );
125131
t3 = resolveStr( types[ j+2 ] );
126-
for ( i = min; i <= max; i++ ) {
132+
133+
if ( re.test( t1 ) || re.test( t2 ) || re.test( t3 ) ) {
134+
N = 4;
135+
} else {
136+
N = max;
137+
}
138+
for ( i = min; i <= N; i++ ) {
127139
len = pow( 10, i );
128140
f = createBenchmark( len, t1, t2, t3 );
129141
bench( pkg+':ndarray:len='+len+',xtype='+t1+',ytype='+t2+',ztype='+t3, f );

lib/node_modules/@stdlib/math/strided/ops/add/benchmark/benchmark.ndarray.native.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ var types = [
4444
'float64', 'float64', 'float64',
4545
'float32', 'float32', 'float32',
4646
'int32', 'int32', 'int32',
47-
'uint8', 'uint8', 'uint8'
47+
'uint8', 'uint8', 'uint8',
48+
'complex64', 'complex64', 'complex64',
49+
'complex128', 'complex128', 'complex128'
4850
];
4951
var rand = uniform( 0.0, 10.0 );
5052

lib/node_modules/@stdlib/math/strided/ops/add/docs/types/index.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { ArrayLike } from '@stdlib/types/array';
23+
import { ArrayLike, ComplexTypedArray } from '@stdlib/types/array';
24+
25+
/**
26+
* Real or complex number array.
27+
*/
28+
type RealOrComplexArray = ArrayLike<number> | ComplexTypedArray;
2429

2530
/**
2631
* Interface describing `add`.
@@ -55,7 +60,7 @@ interface Routine {
5560
* add( x.length, 'float64', x, 1, 'float64', y, 1, 'float64', z, 1 );
5661
* // z => <Float64Array>[ -1.0, 3.0, 6.0, -1.0, 9.0 ]
5762
*/
58-
( N: number, dtypeX: any, x: ArrayLike<number>, strideX: number, dtypeY: any, y: ArrayLike<number>, strideY: number, dtypeZ: any, z: ArrayLike<number>, strideZ: number ): ArrayLike<number>; // tslint:disable-line:max-line-length
63+
( N: number, dtypeX: any, x: RealOrComplexArray, strideX: number, dtypeY: any, y: RealOrComplexArray, strideY: number, dtypeZ: any, z: RealOrComplexArray, strideZ: number ): RealOrComplexArray; // tslint:disable-line:max-line-length
5964

6065
/**
6166
* Adds each element in a strided array `x` to a corresponding element in a strided array `y` and assigns the results to elements in a strided array `z` using alternative indexing semantics.
@@ -89,7 +94,7 @@ interface Routine {
8994
* add.ndarray( x.length, 'float64', x, 1, 0, 'float64', y, 1, 0, 'float64', z, 1, 0 );
9095
* // z => <Float64Array>[ -1.0, 3.0, 6.0, -1.0, 9.0 ]
9196
*/
92-
ndarray( N: number, dtypeX: any, x: ArrayLike<number>, strideX: number, offsetX: number, dtypeY: any, y: ArrayLike<number>, strideY: number, offsetY: number, dtypeZ: any, z: ArrayLike<number>, strideZ: number, offsetZ: number ): ArrayLike<number>; // tslint:disable-line:max-line-length
97+
ndarray( N: number, dtypeX: any, x: RealOrComplexArray, strideX: number, offsetX: number, dtypeY: any, y: RealOrComplexArray, strideY: number, offsetY: number, dtypeZ: any, z: RealOrComplexArray, strideZ: number, offsetZ: number ): RealOrComplexArray; // tslint:disable-line:max-line-length
9398
}
9499

95100
/**

lib/node_modules/@stdlib/math/strided/ops/add/docs/types/test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import add = require( './index' );
2121

2222
// TESTS //
2323

24-
// The function returns an array-like object containing numbers...
24+
// The function returns an array-like object or complex typed array...
2525
{
2626
const x = new Float64Array( 10 );
2727
const y = new Float64Array( 10 );
2828
const z = new Float64Array( 10 );
2929

30-
add( x.length, 'float64', x, 1, 'float64', y, 1, 'float64', z, 1 ); // $ExpectType ArrayLike<number>
30+
add( x.length, 'float64', x, 1, 'float64', y, 1, 'float64', z, 1 ); // $ExpectType RealOrComplexArray
3131
}
3232

3333
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -46,7 +46,7 @@ import add = require( './index' );
4646
add( ( x: number ): number => x, 'float64', x, 1, 'float64', y, 1, 'float64', z, 1 ); // $ExpectError
4747
}
4848

49-
// The compiler throws an error if the function is provided a third argument which is not an array-like object containing numbers...
49+
// The compiler throws an error if the function is provided a third argument which is not an array-like object or complex typed array...
5050
{
5151
const x = new Float64Array( 10 );
5252
const y = new Float64Array( 10 );
@@ -79,7 +79,7 @@ import add = require( './index' );
7979
add( x.length, 'float64', x, ( x: number ): number => x, 'float64', y, 1, 'float64', z, 1 ); // $ExpectError
8080
}
8181

82-
// The compiler throws an error if the function is provided a sixth argument which is not an array-like object containing numbers...
82+
// The compiler throws an error if the function is provided a sixth argument which is not an array-like object or complex typed array...
8383
{
8484
const x = new Float64Array( 10 );
8585
const z = new Float64Array( 10 );
@@ -111,7 +111,7 @@ import add = require( './index' );
111111
add( x.length, 'float64', x, 1, 'float64', y, ( x: number ): number => x, 'float64', z, 1 ); // $ExpectError
112112
}
113113

114-
// The compiler throws an error if the function is provided a ninth argument which is not an array-like object containing numbers...
114+
// The compiler throws an error if the function is provided a ninth argument which is not an array-like object or complex typed array...
115115
{
116116
const x = new Float64Array( 10 );
117117
const y = new Float64Array( 10 );
@@ -161,13 +161,13 @@ import add = require( './index' );
161161
add( x.length, 'float64', x, 1, 'float64', y, 1, z, 1, 10 ); // $ExpectError
162162
}
163163

164-
// Attached to main export is an `ndarray` method which returns an array-like object containing numbers...
164+
// Attached to main export is an `ndarray` method which returns an array-like object or complex typed array...
165165
{
166166
const x = new Float64Array( 10 );
167167
const y = new Float64Array( 10 );
168168
const z = new Float64Array( 10 );
169169

170-
add.ndarray( x.length, 'float64', x, 1, 0, 'float64', y, 1, 0, 'float64', z, 1, 0 ); // $ExpectType ArrayLike<number>
170+
add.ndarray( x.length, 'float64', x, 1, 0, 'float64', y, 1, 0, 'float64', z, 1, 0 ); // $ExpectType RealOrComplexArray
171171
}
172172

173173
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
@@ -186,7 +186,7 @@ import add = require( './index' );
186186
add.ndarray( ( x: number ): number => x, 'float64', x, 1, 0, 'float64', y, 1, 0, 'float64', z, 1, 0 ); // $ExpectError
187187
}
188188

189-
// The compiler throws an error if the `ndarray` method is provided a third argument which is not an array-like object containing numbers...
189+
// The compiler throws an error if the `ndarray` method is provided a third argument which is not an array-like object or complex typed array...
190190
{
191191
const x = new Float64Array( 10 );
192192
const y = new Float64Array( 10 );
@@ -235,7 +235,7 @@ import add = require( './index' );
235235
add.ndarray( x.length, 'float64', x, 1, ( x: number ): number => x, 'float64', y, 1, 0, 'float64', z, 1, 0 ); // $ExpectError
236236
}
237237

238-
// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not an array-like object containing numbers...
238+
// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not an array-like object or complex typed array...
239239
{
240240
const x = new Float64Array( 10 );
241241
const z = new Float64Array( 10 );
@@ -283,7 +283,7 @@ import add = require( './index' );
283283
add.ndarray( x.length, 'float64', x, 1, 0, 'float64', y, 1, ( x: number ): number => x, 'float64', z, 1, 0 ); // $ExpectError
284284
}
285285

286-
// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not an array-like object containing numbers...
286+
// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not an array-like object or complex typed array...
287287
{
288288
const x = new Float64Array( 10 );
289289
const y = new Float64Array( 10 );

lib/node_modules/@stdlib/math/strided/ops/add/lib/data.js

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,64 @@
2222

2323
var add = require( '@stdlib/math/base/ops/add' );
2424
var cadd = require( '@stdlib/math/base/ops/cadd' );
25+
var caddf = require( '@stdlib/math/base/ops/caddf' );
2526
var resolve = require( '@stdlib/strided/base/dtype-resolve-str' );
2627
var Complex64 = require( '@stdlib/complex/float32' );
2728
var Complex128 = require( '@stdlib/complex/float64' );
2829
var wrap = require( '@stdlib/complex/base/wrap-function' );
2930
var types = require( './types.js' );
3031

3132

33+
// VARIABLES //
34+
35+
var C64 = 'complex64';
36+
var C128 = 'complex128';
37+
var CTORS = {
38+
'complex64': Complex64,
39+
'complex128': Complex128
40+
};
41+
42+
3243
// FUNCTIONS //
3344

45+
/**
46+
* Resolves a callback based on provided dtypes.
47+
*
48+
* @private
49+
* @param {Object} table - callback table
50+
* @param {Function} table.default - default callback
51+
* @param {Function} table.complex64 - callback for single-precision complex floating-point numbers
52+
* @param {Function} table.complex128 - callback for double-precision complex floating-point numbers
53+
* @param {string} t1 - dtype for first argument
54+
* @param {string} t2 - dtype for second argument
55+
* @param {string} t3 - dtype for return value
56+
* @returns {Function} callback
57+
*/
58+
function resolveCallback( table, t1, t2, t3 ) {
59+
if ( t3 === C64 || t3 === C128 ) {
60+
if ( t1 === t2 && t2 === t3 ) {
61+
return table[ t3 ];
62+
}
63+
return wrap( table[ t3 ], 2, CTORS[ t3 ] );
64+
}
65+
if ( t3 === 'generic' ) {
66+
if ( t1 === C128 || t2 === C128 ) {
67+
if ( t1 === t2 ) {
68+
return table[ t1 ];
69+
}
70+
return wrap( table[ C128 ], 2, CTORS[ C128 ] );
71+
}
72+
if ( t1 === C64 || t2 === C64 ) {
73+
if ( t1 === t2 ) {
74+
return table[ t1 ];
75+
}
76+
return wrap( table[ C64 ], 2, CTORS[ C64 ] );
77+
}
78+
// Fall-through...
79+
}
80+
return table.default;
81+
}
82+
3483
/**
3584
* Assigns callbacks to binary interfaces.
3685
*
@@ -43,34 +92,24 @@ var types = require( './types.js' );
4392
* @returns {Array} list of callbacks
4493
*/
4594
function callbacks( dtypes ) {
95+
var table;
4696
var out;
4797
var t1;
4898
var t2;
4999
var t3;
50-
var f;
51100
var i;
52101

102+
table = {};
103+
table.default = add;
104+
table[ C64 ] = caddf;
105+
table[ C128 ] = cadd;
106+
53107
out = [];
54108
for ( i = 0; i < dtypes.length; i += 3 ) {
55109
t1 = resolve( dtypes[ i ] );
56110
t2 = resolve( dtypes[ i+1 ] );
57111
t3 = resolve( dtypes[ i+2 ] );
58-
if ( t3 === 'complex64' ) {
59-
if ( t1 === t2 && t2 === t3 ) {
60-
f = cadd;
61-
} else {
62-
f = wrap( cadd, 2, Complex64 );
63-
}
64-
} else if ( t3 === 'complex128' ) {
65-
if ( t1 === t2 && t2 === t3 ) {
66-
f = cadd; // FIXME: zadd
67-
} else {
68-
f = wrap( cadd, 2, Complex128 ); // FIXME: zadd
69-
}
70-
} else {
71-
f = add;
72-
}
73-
out.push( f );
112+
out.push( resolveCallback( table, t1, t2, t3 ) );
74113
}
75114
return out;
76115
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[[10,11,15,4,6,1,5,7,2],[10,11,15,4,6,1,5,7,2],[10,11,15,4,6,1,5,7,2]]
1+
[[12,13,10,11,15,4,6,1,5,7,2],[12,13,10,11,15,4,6,1,5,7,2],[12,13,10,11,15,4,6,1,5,7,2]]

lib/node_modules/@stdlib/math/strided/ops/add/lib/dtypes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ var dtypes = require( '@stdlib/strided/dtypes' );
3232
// Data types to exclude:
3333
var EXCLUDE = [
3434
'binary',
35-
'uint8c', // FIXME: remove once we have C support for `uint8c`
36-
'complex64', // FIXME: remove once we have JS support for `complex64`
37-
'complex128' // FIXME: remove once we have JS support for `complex128`
35+
'uint8c' // FIXME: remove once we have C support for `uint8c`
3836
];
3937

4038
// Resolve lists of dtypes for input and output arguments:

lib/node_modules/@stdlib/math/strided/ops/add/lib/dtypes.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[
22
[
3+
"complex64",
4+
"complex128",
35
"float32",
46
"float64",
57
"generic",
@@ -11,6 +13,8 @@
1113
"uint8"
1214
],
1315
[
16+
"complex64",
17+
"complex128",
1418
"float32",
1519
"float64",
1620
"generic",
@@ -22,6 +26,8 @@
2226
"uint8"
2327
],
2428
[
29+
"complex64",
30+
"complex128",
2531
"float32",
2632
"float64",
2733
"generic",

0 commit comments

Comments
 (0)