Skip to content

Commit 0c0027f

Browse files
committed
Auto-generated commit
1 parent ff0085b commit 0c0027f

File tree

6 files changed

+476
-5
lines changed

6 files changed

+476
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ This release closes the following issue:
480480

481481
##### Features
482482

483+
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241)
483484
- [`e3a2173`](https://github.com/stdlib-js/stdlib/commit/e3a2173a24bd8634f333cace626fc2d71740ebd3) - add `every` method to `array/fixed-endian-factory` [(#3200)](https://github.com/stdlib-js/stdlib/pull/3200)
484485
- [`b34732c`](https://github.com/stdlib-js/stdlib/commit/b34732cf655db60fbc798e12952f88c3edb07eaf) - add `at` method to `array/fixed-endian-factory` [(#3184)](https://github.com/stdlib-js/stdlib/pull/3184)
485486
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - add `forEach` method
@@ -492,9 +493,9 @@ This release closes the following issue:
492493

493494
##### Closed Issues
494495

495-
A total of 2 issues were closed in this release:
496+
A total of 3 issues were closed in this release:
496497

497-
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138)
498+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
498499

499500
</section>
500501

@@ -548,9 +549,9 @@ A total of 2 issues were closed in this release:
548549

549550
### Closed Issues
550551

551-
A total of 9 issues were closed in this release:
552+
A total of 10 issues were closed in this release:
552553

553-
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3164](https://github.com/stdlib-js/stdlib/issues/3164), [#3165](https://github.com/stdlib-js/stdlib/issues/3165), [#3176](https://github.com/stdlib-js/stdlib/issues/3176), [#3177](https://github.com/stdlib-js/stdlib/issues/3177), [#3178](https://github.com/stdlib-js/stdlib/issues/3178), [#3179](https://github.com/stdlib-js/stdlib/issues/3179), [#3180](https://github.com/stdlib-js/stdlib/issues/3180)
554+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3155](https://github.com/stdlib-js/stdlib/issues/3155), [#3164](https://github.com/stdlib-js/stdlib/issues/3164), [#3165](https://github.com/stdlib-js/stdlib/issues/3165), [#3176](https://github.com/stdlib-js/stdlib/issues/3176), [#3177](https://github.com/stdlib-js/stdlib/issues/3177), [#3178](https://github.com/stdlib-js/stdlib/issues/3178), [#3179](https://github.com/stdlib-js/stdlib/issues/3179), [#3180](https://github.com/stdlib-js/stdlib/issues/3180)
554555

555556
</section>
556557

@@ -560,11 +561,12 @@ A total of 9 issues were closed in this release:
560561

561562
### Contributors
562563

563-
A total of 6 people contributed to this release. Thank you to the following contributors:
564+
A total of 7 people contributed to this release. Thank you to the following contributors:
564565

565566
- Aayush Khanna
566567
- Abhijit
567568
- Athan Reines
569+
- Kshitij-Dale
568570
- Philipp Burckhardt
569571
- Rylan Yang
570572
- Vinit Pandit
@@ -579,6 +581,7 @@ A total of 6 people contributed to this release. Thank you to the following cont
579581

580582
<details>
581583

584+
- [`2df0e9b`](https://github.com/stdlib-js/stdlib/commit/2df0e9bb08b8ad1c573b7c2383ef39e492dd5436) - **feat:** add `some` method to `array/fixed-endian-factory` [(#3241)](https://github.com/stdlib-js/stdlib/pull/3241) _(by Kshitij-Dale, Athan Reines)_
582585
- [`abb0dc3`](https://github.com/stdlib-js/stdlib/commit/abb0dc38783210623e67f19a5bb95b3998f75ff7) - **docs:** update examples and descriptions _(by Athan Reines)_
583586
- [`95d0bbc`](https://github.com/stdlib-js/stdlib/commit/95d0bbc4b76c57dba4b4edd343dcd046490d4a51) - **bench:** test for primitive value _(by Athan Reines)_
584587
- [`c712a8e`](https://github.com/stdlib-js/stdlib/commit/c712a8ec07db672a01355ddfca2192be25fe85ca) - **feat:** add `array/base/broadcasted-ternary4d` [(#3232)](https://github.com/stdlib-js/stdlib/pull/3232) _(by Vinit Pandit, Athan Reines)_

fixed-endian-factory/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,56 @@ A few notes:
535535
- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error.
536536
- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range.
537537

538+
<a name="method-some"></a>
539+
540+
#### TypedArrayFE.prototype.some( predicate\[, thisArg] )
541+
542+
Tests whether at least one element in an array passes a test implemented by a predicate function.
543+
544+
```javascript
545+
function isPositive( v ) {
546+
return v > 0;
547+
}
548+
549+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
550+
551+
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, 2.0, -3.0, -4.0 ] );
552+
// returns <Float64ArrayFE>
553+
554+
var bool = arr.some( isPositive );
555+
// returns true
556+
```
557+
558+
The `predicate` function is provided three arguments:
559+
560+
- **value**: current array element.
561+
- **index**: current array element index.
562+
- **arr**: the array on which this method was called.
563+
564+
To set the function execution context, provide a `thisArg`.
565+
566+
```javascript
567+
function isPositive( v, i ) {
568+
this.count += 1;
569+
return v > 0;
570+
}
571+
572+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
573+
574+
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, -2.0, -3.0 ] );
575+
// returns <Float64ArrayFE>
576+
577+
var context = {
578+
'count': 0
579+
};
580+
581+
var bool = arr.some( isPositive, context );
582+
// returns false
583+
584+
var count = context.count;
585+
// returns 3
586+
```
587+
538588
<a name="method-to-string"></a>
539589

540590
#### TypedArrayFE.prototype.toString()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var factory = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+':some', function benchmark( b ) {
37+
var bool;
38+
var arr;
39+
var i;
40+
41+
arr = new Float64ArrayFE( 'little-endian', [ -1.0, -2.0, -2.0, 1.0 ] );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
bool = arr.some( predicate );
46+
if ( typeof bool !== 'boolean' ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isBoolean( bool ) ) {
52+
b.fail( 'should return a boolean' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
57+
function predicate( v ) {
58+
return v > 0;
59+
}
60+
});
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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( './../../zero-to' );
26+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
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+
* Predicate function.
40+
*
41+
* @private
42+
* @param {number} value - array element
43+
* @param {NonNegativeInteger} idx - array element index
44+
* @param {TypedArray} arr - array instance
45+
* @returns {boolean} boolean indicating whether a value passes a test
46+
*/
47+
function predicate( value ) {
48+
return value < 0;
49+
}
50+
51+
/**
52+
* Creates a benchmark function.
53+
*
54+
* @private
55+
* @param {PositiveInteger} len - array length
56+
* @returns {Function} benchmark function
57+
*/
58+
function createBenchmark( len ) {
59+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
60+
return benchmark;
61+
62+
/**
63+
* Benchmark function.
64+
*
65+
* @private
66+
* @param {Benchmark} b - benchmark instance
67+
*/
68+
function benchmark( b ) {
69+
var bool;
70+
var i;
71+
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
bool = arr.some( predicate );
75+
if ( typeof bool !== 'boolean' ) {
76+
b.fail( 'should return a boolean' );
77+
}
78+
}
79+
b.toc();
80+
if ( !isBoolean( bool ) ) {
81+
b.fail( 'should return a boolean' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( pkg+':some:len='+len, f );
110+
}
111+
}
112+
113+
main();

fixed-endian-factory/lib/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,37 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
729729
buf[ SETTER ]( idx*BYTES_PER_ELEMENT, value, this._isLE );
730730
});
731731

732+
/**
733+
* Tests whether at least one element in the typed array passes a test implemented by a predicate function.
734+
*
735+
* @name some
736+
* @memberof TypedArray.prototype
737+
* @type {Function}
738+
* @param {Function} predicate - predicate function
739+
* @param {*} [thisArg] - predicate function execution context
740+
* @throws {TypeError} `this` must be a typed array instance
741+
* @throws {TypeError} first argument must be a function
742+
* @returns {boolean} boolean indicating whether at least one element passes a test
743+
*/
744+
setReadOnly( TypedArray.prototype, 'some', function some( predicate, thisArg ) {
745+
var buf;
746+
var i;
747+
748+
if ( !isTypedArray( this ) ) {
749+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
750+
}
751+
if ( !isFunction( predicate ) ) {
752+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
753+
}
754+
buf = this._buffer;
755+
for ( i = 0; i < this._length; i++ ) {
756+
if ( predicate.call( thisArg, buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ), i, this ) ) {
757+
return true;
758+
}
759+
}
760+
return false;
761+
});
762+
732763
/**
733764
* Serializes an array as a string.
734765
*

0 commit comments

Comments
 (0)