Skip to content

Commit 532bcdd

Browse files
committed
Merge branch 'temp' into find_index
2 parents 3e505ad + 3ae887b commit 532bcdd

File tree

8 files changed

+369
-56
lines changed

8 files changed

+369
-56
lines changed

.github/workflows/lint_random_files.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,11 @@ jobs:
389389
390390
# Create sub-issue for C linting failures:
391391
- name: 'Create sub-issue for C lint failures'
392+
<<<<<<< HEAD
392393
if: ( github.event.inputs.c != 'false' ) && failure() && contains(steps.*.outcome, 'failure') && contains(steps.lint-c.outcome, 'failure')
394+
=======
395+
if: ( github.event.inputs.c != 'false' ) && failure() && contains(steps.*.outcome, 'failure') && contains(job.steps.*.name, 'Lint C files')
396+
>>>>>>> temp
393397
env:
394398
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
395399
run: |

CONTRIBUTORS

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

55
Aayush Khanna <[email protected]>
6+
<<<<<<< HEAD
67
Abhijit Raut <[email protected]>
8+
=======
9+
10+
AbhijitRaut04 <[email protected]>
11+
>>>>>>> temp
712
Adarsh Palaskar <[email protected]>
813
Aditya Sapra <[email protected]>
914
AgPriyanshu18 <[email protected]>

lib/node_modules/@stdlib/array/fixed-endian-factory/README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,12 @@ function isNegative( v ) {
354354
var Float64ArrayFE = fixedEndianFactory( 'float64' );
355355

356356
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, -2.0, -3.0, -4.0 ] );
357-
// returns <Float64ArrayFE>
358357

359358
var bool = arr.every( isNegative );
360359
// returns true
361360
```
362361

363-
The `predicate` function is provided three arguments:
362+
The invoked function is provided three arguments:
364363

365364
- **value**: current array element.
366365
- **index**: current array element index.
@@ -377,7 +376,6 @@ function isPositive( v, i ) {
377376
var Float64ArrayFE = fixedEndianFactory( 'float64' );
378377

379378
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, -3.0 ] );
380-
// returns <Float64ArrayFE>
381379

382380
var context = {
383381
'count': 0
@@ -390,14 +388,14 @@ var count = context.count;
390388
// returns 3
391389
```
392390

393-
<a name="method-every"></a>
391+
<a name="method-find-index"></a>
394392

395-
#### TypedArrayFE.prototype.findIndex( callbackFn\[, thisArg] )
393+
#### TypedArrayFE.prototype.findIndex( predicate\[, thisArg] )
396394

397-
Tests whether all the elements in an array pass a test implemented by a predicate function.
395+
Returns the index of the first element in a typed array for which a predicate function returns a truthy value.
398396

399397
```javascript
400-
function greaterthantwo( v ) {
398+
function predicate( v ) {
401399
return ( v > 2.0 );
402400
}
403401

@@ -409,11 +407,11 @@ arr.set( 1.5, 0 );
409407
arr.set( 2.5, 1 );
410408
arr.set( 3.5, 2 );
411409

412-
var bool = arr.every( isNegative );
413-
// returns true
410+
var idx = arr.findIndex( predicate );
411+
// returns 1
414412
```
415413

416-
The invoked function is provided three arguments:
414+
The `predicate` function is provided three arguments:
417415

418416
- **value**: current array element.
419417
- **index**: current array element index.
@@ -422,24 +420,27 @@ The invoked function is provided three arguments:
422420
To set the function execution context, provide a `thisArg`.
423421

424422
```javascript
425-
function isPositive( v, i ) {
423+
function predicate( v, i ) {
426424
this.count += 1;
427-
return v > 0;
425+
return ( v === 2.0 );
428426
}
429427

430428
var Float64ArrayFE = fixedEndianFactory( 'float64' );
431429

432-
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, -3.0 ] );
430+
var arr = new Float64ArrayFE( 'little-endian', 3 );
433431

434432
var context = {
435433
'count': 0
436434
};
437435

438-
var bool = arr.every( isPositive, context );
439-
// returns false
436+
arr.set( 1.0, 0 );
437+
arr.set( 2.0, 1 );
438+
arr.set( 3.0, 2 );
439+
440+
arr.findIndex( predicate, context );
440441

441442
var count = context.count;
442-
// returns 3
443+
// returns 2
443444
```
444445

445446
<a name="method-for-each"></a>
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) 2024 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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var factory = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':findIndex', function benchmark( b ) {
32+
var ctor;
33+
var arr;
34+
var idx;
35+
var i;
36+
37+
ctor = factory( 'float64' );
38+
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0 ] );
39+
idx = arr.findIndex( predicate );
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
idx = arr.findIndex( predicate );
44+
if ( typeof idx !== 'number' ) {
45+
b.fail( 'should return an integer' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isInteger( idx ) ) {
50+
b.fail( 'should return an integer' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
55+
function predicate( v ) {
56+
return ( v === 3.0 );
57+
}
58+
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 zeroTo = require( '@stdlib/array/zero-to' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var factory = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var Float64ArrayFE = factory( 'float64' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveInteger} len - array length
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( len ) {
46+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
47+
return benchmark;
48+
49+
/**
50+
* Benchmark function.
51+
*
52+
* @private
53+
* @param {Benchmark} b - benchmark instance
54+
*/
55+
function benchmark( b ) {
56+
var idx;
57+
var i;
58+
59+
b.tic();
60+
for ( i = 0; i < b.iterations; i++ ) {
61+
idx = arr.findIndex( callback );
62+
if ( typeof idx !== 'number' ) {
63+
b.fail( 'should return an integer' );
64+
}
65+
}
66+
b.toc();
67+
if ( arr.length !== len ) {
68+
b.fail( 'should not change an array length' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
73+
function callback( value ) {
74+
if ( isnan( value ) ) {
75+
throw new Error( 'something went wrong' );
76+
}
77+
}
78+
}
79+
}
80+
81+
82+
// MAIN //
83+
84+
/**
85+
* Main execution sequence.
86+
*
87+
* @private
88+
*/
89+
function main() {
90+
var len;
91+
var min;
92+
var max;
93+
var f;
94+
var i;
95+
96+
min = 1; // 10^min
97+
max = 6; // 10^max
98+
99+
for ( i = min; i <= max; i++ ) {
100+
len = pow( 10, i );
101+
f = createBenchmark( len );
102+
bench( pkg+':findIndex:len='+len, f );
103+
}
104+
}
105+
106+
main();

lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -538,37 +538,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
538538
*/
539539
setReadOnly( TypedArray.prototype, 'BYTES_PER_ELEMENT', TypedArray.BYTES_PER_ELEMENT );
540540

541-
/**
542-
* Tests whether all elements in an array pass a test implemented by a predicate function.
543-
*
544-
* @name every
545-
* @memberof TypedArray.prototype
546-
* @type {Function}
547-
* @param {Function} predicate - predicate function
548-
* @param {*} [thisArg] - predicate function execution context
549-
* @throws {TypeError} `this` must be a typed array instance
550-
* @throws {TypeError} first argument must be a function
551-
* @returns {boolean} boolean indicating whether all elements pass a test
552-
*/
553-
setReadOnly( TypedArray.prototype, 'every', function every( predicate, thisArg ) {
554-
var buf;
555-
var i;
556-
557-
if ( !isTypedArray( this ) ) {
558-
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
559-
}
560-
if ( !isFunction( predicate ) ) {
561-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
562-
}
563-
buf = this._buffer;
564-
for ( i = 0; i < this._length; i++ ) {
565-
if ( !predicate.call( thisArg, buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ), i, this ) ) {
566-
return false;
567-
}
568-
}
569-
return true;
570-
});
571-
572541
/**
573542
* Tests whether all elements in an array pass a test implemented by a predicate function.
574543
*
@@ -601,18 +570,18 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
601570
});
602571

603572
/**
604-
* Tests whether all elements in an array pass a test implemented by a predicate function.
573+
* Returns the index of the first element in an array for which a predicate function returns a truthy value.
605574
*
606-
* @name every
575+
* @name findIndex
607576
* @memberof TypedArray.prototype
608577
* @type {Function}
609-
* @param {Function} predicate - predicate function
578+
* @param {Function} predicate - function to invoke
610579
* @param {*} [thisArg] - function invocation context
611580
* @throws {TypeError} `this` must be a typed array instance
612581
* @throws {TypeError} first argument must be a function
613-
* @returns {boolean} boolean indicating whether all elements pass a test
582+
* @returns {integer} index or -1
614583
*/
615-
setReadOnly( TypedArray.prototype, 'every', function every( predicate, thisArg ) {
584+
setReadOnly( TypedArray.prototype, 'findIndex', function findIndex( predicate, thisArg ) {
616585
var buf;
617586
var i;
618587

@@ -622,13 +591,14 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
622591
if ( !isFunction( predicate ) ) {
623592
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
624593
}
594+
625595
buf = this._buffer;
626-
for ( i = 0; i < this._length; i++ ) {
627-
if ( !predicate.call( thisArg, buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ), i, this ) ) {
628-
return false;
596+
for (i = 0; i < this._length; i++) {
597+
if ( predicate.call(thisArg, buf[GETTER](i * BYTES_PER_ELEMENT, this._isLE), i, this ) ) {
598+
return i;
629599
}
630600
}
631-
return true;
601+
return -1;
632602
});
633603

634604
/**

0 commit comments

Comments
 (0)