Skip to content

feat: add support for the typed array every method in array/complex64 #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1f53999
feat: add support for the typed array every method in array/complex64
Jaysukh-409 Dec 17, 2023
53a8044
Apply suggestions from code review
kgryte Dec 17, 2023
97989b0
Apply suggestions from code review
kgryte Dec 17, 2023
30bddf7
Apply suggestions from code review
kgryte Dec 17, 2023
7221da5
Apply suggestions from code review
kgryte Dec 17, 2023
67d50b8
Apply suggestions from code review
kgryte Dec 17, 2023
09d968a
feat: updated README and Typescript declaration and added benchmark
Jaysukh-409 Dec 17, 2023
dbe3004
Apply suggestions from code review
kgryte Dec 18, 2023
0b5abfe
Apply suggestions from code review
kgryte Dec 18, 2023
080ca06
Apply suggestions from code review
kgryte Dec 18, 2023
3bc51ab
Apply suggestions from code review
kgryte Dec 18, 2023
16215ca
Apply suggestions from code review
kgryte Dec 18, 2023
defa47e
Apply suggestions from code review
kgryte Dec 18, 2023
fa7a0d6
Apply suggestions from code review
kgryte Dec 18, 2023
0ca60a4
refactor: move method to ensure methods are in alphabetical order
kgryte Dec 18, 2023
032bbec
refactor: abstract logic into internal function
kgryte Dec 18, 2023
e329f94
refactor: improve TypeScript declarations
kgryte Dec 18, 2023
3406be7
refactor: update TypeScript declarations for `from`
kgryte Dec 18, 2023
37cde25
style: remove extraneous spaces
kgryte Dec 18, 2023
4da554a
bench: add length benchmarks and update annotations
kgryte Dec 18, 2023
84fbebf
feat: add test to the array/complex64
Jaysukh-409 Dec 18, 2023
0646e31
Apply suggestions from code review
kgryte Dec 18, 2023
babf221
Apply suggestions from code review
kgryte Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions lib/node_modules/@stdlib/array/complex64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,64 @@ z = arr.at( -100 );
// returns undefined
```

<a name="method-every"></a>

#### Complex64Array.prototype.every( predicate\[, thisArg] )

Returns a boolean indicating whether all elements pass a test.

```javascript
var realf = require( '@stdlib/complex/realf' );
var imagf = require( '@stdlib/complex/imagf' );

function predicate( v ) {
return ( realf( v ) === imagf( v ) );
}

var arr = new Complex64Array( 3 );

// Set the first three elements:
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );

// Check whether all elements pass a test:
var z = arr.every( predicate );
// returns true
```

The `predicate` function is provided four arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`.

```javascript
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 );
}

var arr = new Complex64Array( 3 );

var context = {
'count': 0
};

// Set the first three elements:
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );

var z = arr.every( predicate, context );
// returns true

var count = context.count;
// returns 3
```

<a name="method-set"></a>

#### Complex64Array.prototype.set( z\[, i] )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Complex64Array = require( './../lib' );

// MAIN //

bench( pkg+':copyWithin', function benchmark( b ) {
bench( pkg+':copyWithin:len=5', function benchmark( b ) {
var arr;
var buf;
var i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Complex64Array = require( './../lib' );

// MAIN //

bench( pkg+':entries', function benchmark( b ) {
bench( pkg+':entries:len=10', function benchmark( b ) {
var iter;
var arr;
var i;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isComplex64 = require( '@stdlib/assert/is-complex64' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var Complex64Array = require( './../lib' );


// MAIN //

bench( pkg+':every', function benchmark( b ) {
var bool;
var arr;
var i;

arr = new Complex64Array( [ 1, 2, 3, 4 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.every( predicate );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();

function predicate( v ) {
return isComplex64( v );
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
var Complex64 = require( '@stdlib/complex/float32' );
var realf = require( '@stdlib/complex/realf' );
var imagf = require( '@stdlib/complex/imagf' );
var pkg = require( './../package.json' ).name;
var Complex64Array = require( './../lib' );


// FUNCTIONS //

/**
* Predicate function.
*
* @private
* @param {Complex64} value - array element
* @param {NonNegativeInteger} idx - array element index
* @param {Complex64Array} arr - array instance
* @returns {boolean} boolean indicating whether a value passes a test
*/
function predicate( value ) {
return ( realf( value ) === imagf( value ) );
}

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = [];
for ( i = 0; i < len; i++ ) {
arr.push( new Complex64( i, i ) );
}
arr = new Complex64Array( arr );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var bool;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.every( predicate );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':every:len='+len, f );
}
}

main();
Loading