Skip to content

Commit 456eb6e

Browse files
committed
Auto-generated commit
1 parent 233bb13 commit 456eb6e

8 files changed

Lines changed: 686 additions & 4 deletions

File tree

complex64/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,114 @@ var count = context.count;
856856
// returns 3
857857
```
858858

859+
<a name="method-fill"></a>
860+
861+
#### Complex64Array.prototype.fill( value\[, start\[, end]] )
862+
863+
Returns a modified typed array filled with a fill value.
864+
865+
```javascript
866+
var Complex64 = require( '@stdlib/complex/float32' );
867+
var realf = require( '@stdlib/complex/realf' );
868+
var imagf = require( '@stdlib/complex/imagf' );
869+
870+
var arr = new Complex64Array( 3 );
871+
872+
// Set all elements to the same value:
873+
arr.fill( new Complex64( 1.0, 1.0 ) );
874+
875+
var z = arr.get( 0 );
876+
// returns <Complex64>
877+
878+
var re = realf( z );
879+
// returns 1.0
880+
881+
var im = imagf( z );
882+
// returns 1.0
883+
884+
z = arr.get( 2 );
885+
// returns <Complex64>
886+
887+
re = realf( z );
888+
// returns 1.0
889+
890+
im = imagf( z );
891+
// returns 1.0
892+
893+
// Fill all elements starting from the second element:
894+
arr.fill( new Complex64( 2.0, 2.0 ), 1 );
895+
896+
z = arr.get( 1 );
897+
// returns <Complex64>
898+
899+
re = realf( z );
900+
// returns 2.0
901+
902+
im = imagf( z );
903+
// returns 2.0
904+
905+
z = arr.get( 2 );
906+
// returns <Complex64>
907+
908+
re = realf( z );
909+
// returns 2.0
910+
911+
im = imagf( z );
912+
// returns 2.0
913+
914+
// Fill all elements from first element until the second-to-last element:
915+
arr.fill( new Complex64( 3.0, 3.0 ), 0, 2 );
916+
917+
z = arr.get( 0 );
918+
// returns <Complex64>
919+
920+
re = realf( z );
921+
// returns 3.0
922+
923+
im = imagf( z );
924+
// returns 3.0
925+
926+
z = arr.get( 1 );
927+
// returns <Complex64>
928+
929+
re = realf( z );
930+
// returns 3.0
931+
932+
im = imagf( z );
933+
// returns 3.0
934+
```
935+
936+
When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element.
937+
938+
```javascript
939+
var Complex64 = require( '@stdlib/complex/float32' );
940+
var realf = require( '@stdlib/complex/realf' );
941+
var imagf = require( '@stdlib/complex/imagf' );
942+
943+
var arr = new Complex64Array( 3 );
944+
945+
// Set all array elements, except the last element, to the same value:
946+
arr.fill( new Complex64( 1.0, 1.0 ), 0, -1 );
947+
948+
var z = arr.get( 0 );
949+
// returns <Complex64>
950+
951+
var re = realf( z );
952+
// returns 1.0
953+
954+
var im = imagf( z );
955+
// returns 1.0
956+
957+
z = arr.get( arr.length - 1 );
958+
// returns <Complex64>
959+
960+
re = realf( z );
961+
// returns 0.0
962+
963+
im = imagf( z );
964+
// returns 0.0
965+
```
966+
859967
<a name="method-filter"></a>
860968

861969
#### Complex64Array.prototype.filter( predicate\[, thisArg] )
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 Complex64 = require( '@stdlib/complex/float32' );
25+
var isComplex64Array = require( '@stdlib/assert/is-complex64array' );
26+
var pkg = require( './../package.json' ).name;
27+
var Complex64Array = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+':fill', function benchmark( b ) {
33+
var values;
34+
var arr;
35+
var out;
36+
var i;
37+
38+
values = [
39+
new Complex64( 1.0, 1.0 ),
40+
new Complex64( 2.0, 2.0 ),
41+
new Complex64( 3.0, 3.0 )
42+
];
43+
arr = new Complex64Array( 5 );
44+
45+
b.tic();
46+
for ( i = 0; i < b.iterations; i++ ) {
47+
out = arr.fill( values[ i%values.length ] );
48+
if ( typeof out !== 'object' ) {
49+
b.fail( 'should return an object' );
50+
}
51+
}
52+
b.toc();
53+
if ( !isComplex64Array( out ) ) {
54+
b.fail( 'should return a Complex64Array' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});
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) 2023 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 Complex64 = require( '@stdlib/complex/float32' );
26+
var isComplex64Array = require('@stdlib/assert/is-complex64array');
27+
var pkg = require( './../package.json' ).name;
28+
var Complex64Array = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var arr = new Complex64Array( len );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var values;
52+
var out;
53+
var i;
54+
55+
values = [
56+
new Complex64( 1.0, 1.0 ),
57+
new Complex64( 2.0, 2.0 ),
58+
new Complex64( 3.0, 3.0 )
59+
];
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
out = arr.fill( values[ i%values.length ] );
64+
if ( typeof out !== 'object' ) {
65+
b.fail( 'should return an object' );
66+
}
67+
}
68+
b.toc();
69+
if ( !isComplex64Array( out ) ) {
70+
b.fail( 'should return a Complex64Array' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
}
75+
}
76+
77+
78+
// MAIN //
79+
80+
/**
81+
* Main execution sequence.
82+
*
83+
* @private
84+
*/
85+
function main() {
86+
var len;
87+
var min;
88+
var max;
89+
var f;
90+
var i;
91+
92+
min = 1; // 10^min
93+
max = 6; // 10^max
94+
95+
for ( i = min; i <= max; i++ ) {
96+
len = pow( 10, i );
97+
f = createBenchmark( len );
98+
bench( pkg+':fill:len='+len, f );
99+
}
100+
}
101+
102+
main();

complex64/docs/types/index.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,42 @@ declare class Complex64Array implements Complex64ArrayInterface {
433433
*/
434434
every<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): boolean;
435435

436+
/**
437+
* Returns a modified typed array filled with a fill value.
438+
*
439+
* @param value - fill value
440+
* @param start - starting index (inclusive)
441+
* @param end - ending index (exclusive)
442+
* @returns modified typed array
443+
*
444+
* @example
445+
* var realf = require( '@stdlib/complex/realf' );
446+
* var imagf = require( '@stdlib/complex/imagf' );
447+
*
448+
* var arr = new Complex64Array( 3 );
449+
*
450+
* arr.fill( new Complex64( 1.0, 1.0 ), 1 );
451+
*
452+
* var z = arr.get( 1 );
453+
* // returns <Complex64>
454+
*
455+
* var re = realf( z );
456+
* // returns 1.0
457+
*
458+
* var im = imagf( z );
459+
* // returns 1.0
460+
*
461+
* z = arr.get( 2 );
462+
* // returns <Complex64>
463+
*
464+
* re = realf( z );
465+
* // returns 1.0
466+
*
467+
* im = imagf( z );
468+
* // returns 1.0
469+
*/
470+
fill( value: ComplexLike, start?: number, end?: number ): Complex64Array;
471+
436472
/**
437473
* Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
438474
*

0 commit comments

Comments
 (0)