8000 Auto-generated commit · stdlib-js/array-complex128@4ed64cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ed64cf

Browse files
committed
Auto-generated commit
1 parent 7be1b40 commit 4ed64cf

File tree

10 files changed

+584
-10
lines changed

10 files changed

+584
-10
lines changed

CONTRIBUTORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# Contributors listed in alphabetical order.
44

5+
Aditya Sapra <110766802+adityacodes30@users.noreply.github.com>
56
Ali Salesi <ali_sal1381@yahoo.com>
67
Amit Jimiwal <amitjimiwal45@gmail.com>
78
Athan Reines <kgryte@gmail.com>
@@ -13,6 +14,7 @@ Daniel Killenberger <daniel.killenberger@gmail.com>
1314
Dominik Moritz <domoritz@gmail.com>
1415
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
1516
Frank Kovacs <fran70kk@gmail.com>
17+
GUNJ JOSHI <gunjjoshi8372@gmail.com>
1618
Harshita Kalani <harshitakalani02@gmail.com>
1719
James Gelok <jdgelok@gmail.com>
1820
Jaysukh Makvana <jaysukhmakvana2004@gmail.com>
@@ -37,6 +39,7 @@ Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
3739
Ryan Seal <splrk@users.noreply.github.com>
3840
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
3941
Shraddheya Shendre <shendreshraddheya@gmail.com>
42+
Spandan Barve <114365550+marsian83@users.noreply.github.com>
4043
Stephannie Jiménez Gacha <steff456@hotmail.com>
4144
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
4245
orimiles5 <97595296+orimiles5@users.noreply.github.com>

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,60 @@ var count = context.count;
16531653
// returns 3
16541654
```
16551655

1656+
<a name="method-reduce"></a>
1657+
1658+
#### Complex128Array.prototype.reduce( reducerFn\[, initialValue] )
1659+
1660+
Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
1661+
1662+
```javascript
1663+
var real = require( '@stdlib/complex-real' );
1664+
var imag = require( '@stdlib/complex-imag' );
1665+
var cadd = require( '@stdlib/math-base-ops-cadd' );
1666+
1667+
var arr = new Complex128Array( 3 );
1668+
1669+
arr.set( [ 1.0, 1.0 ], 0 );
1670+
arr.set( [ 2.0, 2.0 ], 1 );
1671+
arr.set( [ 3.0, 3.0 ], 2 );
1672+
1673+
var z = arr.reduce( cadd );
1674+
// returns <Complex128>
1675+
1676+
var re = real( z );
1677+
// returns 6.0
1678+
1679+
var im = imag( z );
1680+
// returns 6.0
1681+
```
1682+
1683+
The reducer function is provided four arguments:
1684+
1685+
- **acc**: accumulated result.
1686+
- **value**: current array element.
1687+
- **index**: current array element index.
1688+
- **arr**: the array on which this method was called.
1689+
1690+
By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument.
1691+
1692+
```javascript
1693+
var real = require( '@stdlib/complex-real' );
1694+
1695+
function reducer( acc, v ) {
1696+
acc += real( v );
1697+
return acc;
1698+
}
1699+
1700+
var arr = new Complex128Array( 3 );
1701+
1702+
arr.set( [ 1.0, 1.0 ], 0 );
1703+
arr.set( [ 2.0, 2.0 ], 1 );
1704+
arr.set( [ 3.0, 3.0 ], 2 );
1705+
1706+
var z = arr.reduce( reducer, 0.0 );
1707+
// returns 6.0
1708+
```
1709+
16561710
<a name="method-reverse"></a>
16571711

16581712
#### Complex128Array.prototype.reverse()

benchmark/benchmark.reduce.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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-harness' );
24+
var cadd = require( '@stdlib/math-base-ops-cadd' );
25+
var isComplexLike = require('@stdlib/assert-is-complex-like' );
26+
var pkg = require( './../package.json' ).name;
27+
var Complex128Array = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+':reduce', function benchmark( b ) {
33+
var out;
34+
var arr;
35+
var i;
36+
37+
arr = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] );
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
out = arr.reduce( cadd );
42+
if ( typeof out !== 'object' ) {
43+
b.fail( 'should return an object' );
44+
}
45+
}
46+
b.toc();
47+
if ( !isComplexLike( out ) ) {
48+
b.fail( 'should return a complex number' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});

benchmark/benchmark.reduce.length.js

Lines changed: 104 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var cadd = require( '@stdlib/math-base-ops-cadd' );
26+
var isComplexLike = require('@stdlib/assert-is-complex-like' );
27+
var Complex128 = require( '@stdlib/complex-float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var Complex128Array = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var arr;
43+
var i;
44+
45+
arr = [];
46+
for ( i = 0; i < len; i++ ) {
47+
arr.push( new Complex128( i, i ) );
48+
}
49+
arr = new Complex128Array( arr );
50+
51+
return benchmark;
52+
53+
/**
54+
* Benchmark function.
55+
*
56+
* @private
57+
* @param {Benchmark} b - benchmark instance
58+
*/
59+
function benchmark( b ) {
60+
var out;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = arr.reduce( cadd );
66+
if ( typeof out !== 'object' ) {
67+
b.fail( 'should return an object' );
68+
}
69+
}
70+
b.toc();
71+
if ( !isComplexLike( out ) ) {
72+
b.fail( 'should return a complex number' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var len;
89+
var min;
90+
var max;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = pow( 10, i );
99+
f = createBenchmark( len );
100+
bench( pkg+':reduce:len='+len, f );
101+
}
102+
}
103+
104+
main();

0 commit comments

Comments
 (0)
0