Skip to content

Commit fe7ae7d

Browse files
committed
Refactor to support complex number arrays
1 parent 38a8211 commit fe7ae7d

File tree

14 files changed

+984
-15
lines changed

14 files changed

+984
-15
lines changed

lib/node_modules/@stdlib/array/pool/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The function recognizes the following data types:
5757

5858
- `float64`: double-precision floating-point numbers (IEEE 754)
5959
- `float32`: single-precision floating-point numbers (IEEE 754)
60+
- `complex128`: double-precision complex floating-point numbers
61+
- `complex64`: single-precision complex floating-point numbers
6062
- `int32`: 32-bit two's complement signed integers
6163
- `uint32`: 32-bit unsigned integers
6264
- `int16`: 16-bit two's complement signed integers
@@ -364,10 +366,10 @@ pool.free( arr );
364366

365367
```javascript
366368
var randu = require( '@stdlib/random/base/randu' );
367-
var typedarraypool = require( '@stdlib/array/pool' ).factory;
369+
var typedarraypool = require( '@stdlib/array/pool' );
368370

369371
// Create a typed array pool which can allocate at most 1GB:
370-
var typedarray = typedarraypool({
372+
var typedarray = typedarraypool.factory({
371373
'highWaterMark': 1e9
372374
});
373375

lib/node_modules/@stdlib/array/pool/benchmark/benchmark.calloc.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
25+
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
2526
var pkg = require( './../package.json' ).name;
2627
var typedarray = require( './../lib' );
2728

@@ -207,3 +208,39 @@ bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) {
207208
b.pass( 'benchmark finished' );
208209
b.end();
209210
});
211+
212+
bench( pkg+':calloc:dtype=complex64', function benchmark( b ) {
213+
var arr;
214+
var i;
215+
b.tic();
216+
for ( i = 0; i < b.iterations; i++ ) {
217+
arr = typedarray.calloc( 0, 'complex64' );
218+
if ( arr.length !== 0 ) {
219+
b.fail( 'should have length 0' );
220+
}
221+
}
222+
b.toc();
223+
if ( !isComplexTypedArray( arr ) ) {
224+
b.fail( 'should return a complex typed array' );
225+
}
226+
b.pass( 'benchmark finished' );
227+
b.end();
228+
});
229+
230+
bench( pkg+':calloc:dtype=complex128', function benchmark( b ) {
231+
var arr;
232+
var i;
233+
b.tic();
234+
for ( i = 0; i < b.iterations; i++ ) {
235+
arr = typedarray.calloc( 0, 'complex128' );
236+
if ( arr.length !== 0 ) {
237+
b.fail( 'should have length 0' );
238+
}
239+
}
240+
b.toc();
241+
if ( !isComplexTypedArray( arr ) ) {
242+
b.fail( 'should return a complex typed array' );
243+
}
244+
b.pass( 'benchmark finished' );
245+
b.end();
246+
});

lib/node_modules/@stdlib/array/pool/benchmark/benchmark.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
25+
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
2526
var pkg = require( './../package.json' ).name;
2627
var typedarray = require( './../lib' );
2728

@@ -207,3 +208,39 @@ bench( pkg+':dtype=uint8c', function benchmark( b ) {
207208
b.pass( 'benchmark finished' );
208209
b.end();
209210
});
211+
212+
bench( pkg+':dtype=complex64', function benchmark( b ) {
213+
var arr;
214+
var i;
215+
b.tic();
216+
for ( i = 0; i < b.iterations; i++ ) {
217+
arr = typedarray( 0, 'complex64' );
218+
if ( arr.length !== 0 ) {
219+
b.fail( 'should have length 0' );
220+
}
221+
}
222+
b.toc();
223+
if ( !isComplexTypedArray( arr ) ) {
224+
b.fail( 'should return a complex typed array' );
225+
}
226+
b.pass( 'benchmark finished' );
227+
b.end();
228+
});
229+
230+
bench( pkg+':dtype=complex128', function benchmark( b ) {
231+
var arr;
232+
var i;
233+
b.tic();
234+
for ( i = 0; i < b.iterations; i++ ) {
235+
arr = typedarray( 0, 'complex128' );
236+
if ( arr.length !== 0 ) {
237+
b.fail( 'should have length 0' );
238+
}
239+
}
240+
b.toc();
241+
if ( !isComplexTypedArray( arr ) ) {
242+
b.fail( 'should return a complex typed array' );
243+
}
244+
b.pass( 'benchmark finished' );
245+
b.end();
246+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
26+
var pkg = require( './../package.json' ).name;
27+
var typedarray = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Creates a benchmark function.
34+
*
35+
* @private
36+
* @param {Function} fcn - allocation function
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( fcn, len ) {
41+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var arr;
51+
var i;
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
arr = fcn( len, 'complex128' );
56+
if ( arr.length !== len ) {
57+
b.fail( 'unexpected length' );
58+
}
59+
typedarray.free( arr );
60+
}
61+
b.toc();
62+
if ( !isComplexTypedArray( arr ) ) {
63+
b.fail( 'should return a complex typed array' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
91+
f = createBenchmark( typedarray, len );
92+
bench( pkg+':dtype=complex128,len='+len, f );
93+
94+
f = createBenchmark( typedarray.malloc, len );
95+
bench( pkg+':malloc:dtype=complex128,len='+len, f );
96+
97+
f = createBenchmark( typedarray.calloc, len );
98+
bench( pkg+':calloc:dtype=complex128,len='+len, f );
99+
}
100+
}
101+
102+
main();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
26+
var pkg = require( './../package.json' ).name;
27+
var typedarray = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Creates a benchmark function.
34+
*
35+
* @private
36+
* @param {Function} fcn - allocation function
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( fcn, len ) {
41+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var arr;
51+
var i;
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
arr = fcn( len, 'complex64' );
56+
if ( arr.length !== len ) {
57+
b.fail( 'unexpected length' );
58+
}
59+
typedarray.free( arr );
60+
}
61+
b.toc();
62+
if ( !isComplexTypedArray( arr ) ) {
63+
b.fail( 'should return a complex typed array' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
91+
f = createBenchmark( typedarray, len );
92+
bench( pkg+':dtype=complex64,len='+len, f );
93+
94+
f = createBenchmark( typedarray.malloc, len );
95+
bench( pkg+':malloc:dtype=complex64,len='+len, f );
96+
97+
f = createBenchmark( typedarray.calloc, len );
98+
bench( pkg+':calloc:dtype=complex64,len='+len, f );
99+
}
100+
}
101+
102+
main();

lib/node_modules/@stdlib/array/pool/benchmark/benchmark.malloc.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
25+
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
2526
var pkg = require( './../package.json' ).name;
2627
var typedarray = require( './../lib' );
2728

@@ -207,3 +208,39 @@ bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) {
207208
b.pass( 'benchmark finished' );
208209
b.end();
209210
});
211+
212+
bench( pkg+':malloc:dtype=complex64', function benchmark( b ) {
213+
var arr;
214+
var i;
215+
b.tic();
216+
for ( i = 0; i < b.iterations; i++ ) {
217+
arr = typedarray.malloc( 0, 'complex64' );
218+
if ( arr.length !== 0 ) {
219+
b.fail( 'should have length 0' );
220+
}
221+
}
222+
b.toc();
223+
if ( !isComplexTypedArray( arr ) ) {
224+
b.fail( 'should return a complex typed array' );
225+
}
226+
b.pass( 'benchmark finished' );
227+
b.end();
228+
});
229+
230+
bench( pkg+':malloc:dtype=complex128', function benchmark( b ) {
231+
var arr;
232+
var i;
233+
b.tic();
234+
for ( i = 0; i < b.iterations; i++ ) {
235+
arr = typedarray.malloc( 0, 'complex128' );
236+
if ( arr.length !== 0 ) {
237+
b.fail( 'should have length 0' );
238+
}
239+
}
240+
b.toc();
241+
if ( !isComplexTypedArray( arr ) ) {
242+
b.fail( 'should return a complex typed array' );
243+
}
244+
b.pass( 'benchmark finished' );
245+
b.end();
246+
});

lib/node_modules/@stdlib/array/pool/docs/repl.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
- float64: double-precision floating-point numbers (IEEE 754)
1111
- float32: single-precision floating-point numbers (IEEE 754)
12+
- complex128: double-precision complex floating-point numbers
13+
- complex64: single-precision complex floating-point numbers
1214
- int32: 32-bit two's complement signed integers
1315
- uint32: 32-bit unsigned integers
1416
- int16: 16-bit two's complement signed integers

0 commit comments

Comments
 (0)