Skip to content

Commit bcb5292

Browse files
committed
Auto-generated commit
1 parent 1aa3b96 commit bcb5292

10 files changed

+471
-12
lines changed

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-11-26)
7+
## Unreleased (2024-11-27)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270)
1314
- [`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)
1415
- [`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)
1516
- [`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)
@@ -24,9 +25,9 @@
2425

2526
### Closed Issues
2627

27-
A total of 3 issues were closed in this release:
28+
A total of 4 issues were closed in this release:
2829

29-
[#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)
30+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
3031

3132
</section>
3233

@@ -38,6 +39,7 @@ A total of 3 issues were closed in this release:
3839

3940
<details>
4041

42+
- [`1d217ba`](https://github.com/stdlib-js/stdlib/commit/1d217bad1d35210a57d65c8be67c596815589082) - **feat:** add `map` method to `array/fixed-endian-factory` [(#3270)](https://github.com/stdlib-js/stdlib/pull/3270) _(by Aayush Khanna, Athan Reines)_
4143
- [`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)_
4244
- [`abb0dc3`](https://github.com/stdlib-js/stdlib/commit/abb0dc38783210623e67f19a5bb95b3998f75ff7) - **docs:** update examples and descriptions _(by Athan Reines)_
4345
- [`95d0bbc`](https://github.com/stdlib-js/stdlib/commit/95d0bbc4b76c57dba4b4edd343dcd046490d4a51) - **bench:** test for primitive value _(by Athan Reines)_

CONTRIBUTORS

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Contributors listed in alphabetical order.
44

55
Aayush Khanna <aayushiitbhu23@gmail.com>
6-
Abhijit <abhijitmraut8010@gmail.com>
7-
AbhijitRaut04 <121740684+AbhijitRaut04@users.noreply.github.com>
6+
Abhijit Raut <abhijitmraut8010@gmail.com>
87
Adarsh Palaskar <adarshpalaskar99@gmail.com>
98
Aditya Sapra <adityaework@gmail.com>
109
AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com>
@@ -45,7 +44,6 @@ Joey Reed <joeyrreed@gmail.com>
4544
Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com>
4645
Joris Labie <joris.labie1@gmail.com>
4746
Justin Dennison <justin1dennison@gmail.com>
48-
Kaif Mohd <mdkaifprofession@gmail.com>
4947
Karthik Prakash <116057817+skoriop@users.noreply.github.com>
5048
Khaldon <kahmd1444@gmail.com>
5149
Kohantika Nath <145763549+kohantikanath@users.noreply.github.com>
@@ -56,7 +54,7 @@ Marcus Fantham <mfantham@users.noreply.github.com>
5654
Matt Cochrane <matthew.cochrane.eng@gmail.com>
5755
Mihir Pandit <129577900+MSP20086@users.noreply.github.com>
5856
Milan Raj <rajsite@users.noreply.github.com>
59-
Mohammad Kaif <98884589+Kaif987@users.noreply.github.com>
57+
Mohammad Kaif <mdkaifprofession@gmail.com>
6058
Momtchil Momtchev <momtchil@momtchev.com>
6159
Muhammad Haris <harriskhan047@outlook.com>
6260
Naresh Jagadeesan <naresh.naresh000@gmail.com>

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,68 @@ var v = arr.get( 100 );
516516
// returns undefined
517517
```
518518

519+
<a name="method-map"></a>
520+
521+
#### TypedArray.prototype.map( callbackFn\[, thisArg] )
522+
523+
Returns a new array with each element being the result of a provided callback function.
524+
525+
```javascript
526+
function fcn( v ) {
527+
return -v;
528+
}
529+
530+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
531+
532+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
533+
// returns <Float64ArrayFE>
534+
535+
var out = arr.map( fcn );
536+
// returns <Float64ArrayFE>
537+
538+
var z = out.get( 0 );
539+
// returns -1.0
540+
541+
z = out.get( 1 );
542+
// returns -2.0
543+
544+
z = out.get( 2 );
545+
// returns -3.0
546+
```
547+
548+
The callback function is provided three arguments:
549+
550+
- **value**: current array element.
551+
- **index**: current array element index.
552+
- **arr**: the array on which this method was called.
553+
554+
To set the function execution context, provide a `thisArg`.
555+
556+
```javascript
557+
function fcn( v, i ) {
558+
this.count += i;
559+
return -v;
560+
}
561+
562+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
563+
564+
var arr = new Float64ArrayFE( 'little-endian', 3 );
565+
566+
arr.set( -1.0, 0 );
567+
arr.set( 1.0, 1 );
568+
arr.set( -1.0, 2 );
569+
570+
var context = {
571+
'count': 0
572+
};
573+
574+
var out = arr.map( fcn, context );
575+
// returns <Float64ArrayFE>
576+
577+
var count = context.count;
578+
// returns 3;
579+
```
580+
519581
<a name="method-set"></a>
520582

521583
#### TypedArrayFE.prototype.set( arr\[, offset] )

benchmark/benchmark.map.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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-harness' );
24+
var pkg = require( './../package.json' ).name;
25+
var factory = require( './../lib' );
26+
27+
28+
// VARIABLES //
29+
30+
var Float64ArrayFE = factory( 'float64' );
31+
32+
33+
// MAIN //
34+
35+
bench( pkg+':map', function benchmark( b ) {
36+
var out;
37+
var arr;
38+
var i;
39+
40+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] );
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
out = arr.map( identity );
45+
if ( typeof out !== 'object' ) {
46+
b.fail( 'should return an object' );
47+
}
48+
}
49+
b.toc();
50+
if ( !( out instanceof Float64ArrayFE ) ) {
51+
b.fail( 'should return a typed array' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
56+
function identity( v ) {
57+
return v;
58+
}
59+
});

benchmark/benchmark.map.length.js

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

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.js

+49-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ var fromIteratorMap = require( './from_iterator_map.js' );
5151
// VARIABLES //
5252

5353
var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport();
54+
var LITTLE_ENDIAN = 'little-endian';
55+
var BIG_ENDIAN = 'big-endian';
5456
var DTYPES = [ 'float64', 'float32', 'int32', 'int16', 'uint32', 'uint16' ];
5557
var DTYPE2SET = {
5658
'float64': 'setFloat64',
@@ -99,7 +101,18 @@ function byteOrder( value ) {
99101
* @returns {boolean} boolean indicating whether a byte order is little-endian byte order
100102
*/
101103
function isLittleEndian( value ) {
102-
return ( value === 'little-endian' );
104+
return ( value === LITTLE_ENDIAN );
105+
}
106+
107+
/**
108+
* Resolves a byte order string from a boolean flag.
109+
*
110+
* @private
111+
* @param {boolean} isLE - flag indicating whether an array is little-endian
112+
* @returns {string} resolved byte order
113+
*/
114+
function flag2byteOrder( isLE ) {
115+
return ( isLE ) ? LITTLE_ENDIAN : BIG_ENDIAN;
103116
}
104117

105118
/**
@@ -634,6 +647,41 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
634647
return this._length;
635648
});
636649

650+
/**
651+
* Returns a new array with each element being the result of a provided callback function.
652+
*
653+
* @private
654+
* @name map
655+
* @memberof TypedArray.prototype
656+
* @type {Function}
657+
* @param {Function} fcn - function to invoke
658+
* @param {*} [thisArg] - function invocation context
659+
* @throws {TypeError} `this` must be a typed array instance
660+
* @throws {TypeError} first argument must be a function
661+
* @returns {TypedArray} new typed array
662+
*/
663+
setReadOnly( TypedArray.prototype, 'map', function map( fcn, thisArg ) {
664+
var obuf;
665+
var out;
666+
var buf;
667+
var i;
668+
var v;
669+
if ( !isTypedArray( this ) ) {
670+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
671+
}
672+
if ( !isFunction( fcn ) ) {
673+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
674+
}
675+
buf = this._buffer;
676+
out = new this.constructor( flag2byteOrder( this._isLE ), this._length );
677+
obuf = out._buffer; // eslint-disable-line no-underscore-dangle
678+
for ( i = 0; i < this._length; i++ ) {
679+
v = fcn.call( thisArg, buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ), i, this );
680+
obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE );
681+
}
682+
return out;
683+
});
684+
637685
/**
638686
* Sets an array element.
639687
*

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@stdlib/math-base-assert-is-nan": "^0.2.2",
7171
"@stdlib/math-base-special-pow": "^0.3.0",
7272
"@stdlib/random-array-randu": "^0.2.1",
73+
"@stdlib/utils-identity-function": "^0.2.2",
7374
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
7475
"istanbul": "^0.4.1",
7576
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",

0 commit comments

Comments
 (0)