Skip to content

Commit 2ebc5a3

Browse files
Merge branch 'stdlib-js:develop' into Add-C-implementations-to-base-special-math-functions
2 parents a179c6d + fcedaac commit 2ebc5a3

File tree

19 files changed

+486
-93
lines changed

19 files changed

+486
-93
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,30 @@ var v = arr.get( 100 );
543543
// returns undefined
544544
```
545545

546+
<a name="method-includes"></a>
547+
548+
#### TypedArrayFE.prototype.includes( searchElement\[, fromIndex] )
549+
550+
Returns a boolean indicating whether an array includes a provided value.
551+
552+
```javascript
553+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
554+
555+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 2.0 ] );
556+
557+
var idx = arr.includes( 2.0 );
558+
// returns true
559+
560+
idx = arr.includes( 2.0, 2 );
561+
// returns true
562+
563+
idx = arr.includes( 2.0, -4 );
564+
// returns true
565+
566+
idx = arr.includes( 5.0 );
567+
// returns false
568+
```
569+
546570
<a name="method-index-of"></a>
547571

548572
#### TypedArrayFE.prototype.indexOf( searchElement\[, fromIndex] )
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 factory = require( './../lib' );
26+
var pkg = require( './../package.json' ).name;
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+':includes', function benchmark( b ) {
37+
var result;
38+
var arr;
39+
var i;
40+
41+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
result = arr.includes( 5.0, 0 );
46+
if ( typeof result !== 'boolean' ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isBoolean( result ) ) {
52+
b.fail( 'should return a boolean' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var factory = require( './../lib' );
28+
var pkg = require( './../package.json' ).name;
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 result;
57+
var v;
58+
var i;
59+
60+
v = len - 1;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
result = arr.includes( v );
65+
if ( typeof result !== 'boolean' ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
}
69+
b.toc();
70+
if ( !isBoolean( result ) ) {
71+
b.fail( 'should return a boolean' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
}
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var len;
88+
var min;
89+
var max;
90+
var f;
91+
var i;
92+
93+
min = 1; // 10^min
94+
max = 6; // 10^max
95+
96+
for ( i = min; i <= max; i++ ) {
97+
len = pow( 10, i );
98+
f = createBenchmark( len );
99+
bench( pkg+':includes:len='+len, f );
100+
}
101+
}
102+
103+
main();

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,48 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
669669
return this._buffer[ GETTER ]( idx*BYTES_PER_ELEMENT, this._isLE );
670670
});
671671

672+
/**
673+
* Returns a boolean indicating whether an array includes a provided value.
674+
*
675+
* @private
676+
* @name includes
677+
* @memberof TypedArray.prototype
678+
* @type {Function}
679+
* @param {*} searchElement - search element
680+
* @param {integer} [fromIndex=0] - starting index (inclusive)
681+
* @throws {TypeError} `this` must be a typed array instance
682+
* @throws {TypeError} second argument must be an integer
683+
* @returns {boolean} boolean indicating whether an array includes a provided value
684+
*/
685+
setReadOnly( TypedArray.prototype, 'includes', function includes( searchElement, fromIndex ) {
686+
var buf;
687+
var i;
688+
689+
if ( !isTypedArray( this ) ) {
690+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
691+
}
692+
if ( arguments.length > 1 ) {
693+
if ( !isInteger( fromIndex ) ) {
694+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
695+
}
696+
if ( fromIndex < 0 ) {
697+
fromIndex += this._length;
698+
if ( fromIndex < 0 ) {
699+
fromIndex = 0;
700+
}
701+
}
702+
} else {
703+
fromIndex = 0;
704+
}
705+
buf = this._buffer;
706+
for ( i = fromIndex; i < this._length; i++ ) {
707+
if ( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) === searchElement ) {
708+
return true;
709+
}
710+
}
711+
return false;
712+
});
713+
672714
/**
673715
* Returns the index of the first occurrence of a given element.
674716
*

0 commit comments

Comments
 (0)