Skip to content

Commit 3a377ef

Browse files
committed
Auto-generated commit
1 parent 389df93 commit 3a377ef

15 files changed

+2080
-1
lines changed

CHANGELOG.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-03-17)
7+
## Unreleased (2025-03-18)
88

99
<section class="packages">
1010

@@ -661,6 +661,28 @@ This release closes the following issue:
661661

662662
<!-- /.package -->
663663

664+
<section class="package" id="array-base-map-unreleased">
665+
666+
#### [@stdlib/array/base/map](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/map)
667+
668+
<details>
669+
670+
<section class="features">
671+
672+
##### Features
673+
674+
- [`9b2b107`](https://github.com/stdlib-js/stdlib/commit/9b2b10706d20bf18b5a862b0be1c3c53be30c9ce) - add `array/base/map` [(#5346)](https://github.com/stdlib-js/stdlib/pull/5346)
675+
676+
</section>
677+
678+
<!-- /.features -->
679+
680+
</details>
681+
682+
</section>
683+
684+
<!-- /.package -->
685+
664686
<section class="package" id="array-base-msk-unreleased">
665687

666688
#### [@stdlib/array/base/msk](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/msk)
@@ -1261,6 +1283,7 @@ A total of 13 people contributed to this release. Thank you to the following con
12611283

12621284
<details>
12631285

1286+
- [`9b2b107`](https://github.com/stdlib-js/stdlib/commit/9b2b10706d20bf18b5a862b0be1c3c53be30c9ce) - **feat:** add `array/base/map` [(#5346)](https://github.com/stdlib-js/stdlib/pull/5346) _(by Muhammad Haris, Athan Reines)_
12641287
- [`3938b26`](https://github.com/stdlib-js/stdlib/commit/3938b265e603116448c89fcaa58df70e79d40f59) - **refactor:** update paths _(by Gururaj Gurram)_
12651288
- [`ef1d278`](https://github.com/stdlib-js/stdlib/commit/ef1d278f2a382993d2cc63f83458778593767708) - **feat:** add `array/base/banded/to-compact` _(by Athan Reines)_
12661289
- [`f9bb0d7`](https://github.com/stdlib-js/stdlib/commit/f9bb0d77a4ce5ad813c371f5d49d2cee7476b775) - **feat:** add `array/base/symmetric-banded/to-compact` _(by Athan Reines)_

base/map/README.md

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# map
22+
23+
> Apply a callback function to elements in an input array and assign results to elements in a new output array.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var map = require( '@stdlib/array/base/map' );
41+
```
42+
43+
#### map( x, fcn\[, thisArg] )
44+
45+
Applies a callback function to elements in an input array and assigns results to elements in a new output array.
46+
47+
```javascript
48+
var naryFunction = require( '@stdlib/utils/nary-function' );
49+
var abs = require( '@stdlib/math/base/special/abs' );
50+
51+
var x = [ -1.0, -2.0, -3.0, -4.0 ];
52+
53+
var y = map( x, naryFunction( abs, 1 ) );
54+
// returns [ 1.0, 2.0, 3.0, 4.0 ]
55+
```
56+
57+
The function accepts the following arguments:
58+
59+
- **x**: input array.
60+
- **fcn**: callback function.
61+
- **thisArg**: callback execution context (_optional_).
62+
63+
To set the callback function's execution context, provide a `thisArg`.
64+
65+
<!-- eslint-disable no-invalid-this -->
66+
67+
```javascript
68+
function count( x ) {
69+
this.count += 1;
70+
return x;
71+
}
72+
73+
var x = [ 1.0, 2.0, 3.0, 4.0 ];
74+
75+
var ctx = {
76+
'count': 0
77+
};
78+
79+
var y = map( x, count, ctx );
80+
// returns [ 1.0, 2.0, 3.0, 4.0 ]
81+
82+
var v = ctx.count;
83+
// returns 4
84+
```
85+
86+
The callback function is provided the following arguments:
87+
88+
- **value**: current array element.
89+
- **index**: current element index.
90+
- **arr**: input array.
91+
92+
#### map.assign( x, y, stride, offset, fcn\[, thisArg] )
93+
94+
Applies a callback function to elements in an input array and assigns results to elements in an output array.
95+
96+
```javascript
97+
var naryFunction = require( '@stdlib/utils/nary-function' );
98+
var zeros = require( '@stdlib/array/base/zeros' );
99+
var abs = require( '@stdlib/math/base/special/abs' );
100+
101+
var x = [ -1.0, -2.0, -3.0, -4.0 ];
102+
103+
var y = zeros( x.length );
104+
105+
var out = map.assign( x, y, 1, 0, naryFunction( abs, 1 ) );
106+
// returns [ 1.0, 2.0, 3.0, 4.0 ]
107+
108+
var bool = ( out === y );
109+
// returns true
110+
```
111+
112+
The function accepts the following arguments:
113+
114+
- **x**: input array.
115+
- **y**: output array.
116+
- **stride**: stride length for output array.
117+
- **offset**: starting index for output array.
118+
- **fcn**: callback function.
119+
- **thisArg**: callback execution context (_optional_).
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="notes">
128+
129+
## Notes
130+
131+
- If provided an array-like object having a `map` method, the function defers execution to that method and assumes that the method API has the following signature:
132+
133+
```text
134+
x.map( fcn, thisArg )
135+
```
136+
137+
- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).
138+
139+
</section>
140+
141+
<!-- /.notes -->
142+
143+
<section class="examples">
144+
145+
## Examples
146+
147+
<!-- eslint no-undef: "error" -->
148+
149+
```javascript
150+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
151+
var naryFunction = require( '@stdlib/utils/nary-function' );
152+
var abs = require( '@stdlib/math/base/special/abs' );
153+
var map = require( '@stdlib/array/base/map' );
154+
155+
var x = discreteUniform( 10, -10, 10, {
156+
'dtype': 'float64'
157+
});
158+
159+
var y = map( x, naryFunction( abs, 1 ) );
160+
console.log( y );
161+
```
162+
163+
</section>
164+
165+
<!-- /.examples -->
166+
167+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
168+
169+
<section class="references">
170+
171+
</section>
172+
173+
<!-- /.references -->
174+
175+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
176+
177+
<section class="related">
178+
179+
</section>
180+
181+
<!-- /.related -->
182+
183+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
184+
185+
<section class="links">
186+
187+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/array/tree/main/base/accessor
188+
189+
</section>
190+
191+
<!-- /.links -->
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var identity = require( '@stdlib/number/float64/base/identity' );
28+
var zeros = require( './../../../base/zeros' );
29+
var pkg = require( './../package.json' ).name;
30+
var map = require( './../lib' ).assign;
31+
32+
33+
// FUNCTIONS //
34+
35+
/**
36+
* Creates a benchmark function.
37+
*
38+
* @private
39+
* @param {PositiveInteger} len - array length
40+
* @returns {Function} benchmark function
41+
*/
42+
function createBenchmark( len ) {
43+
var x;
44+
var y;
45+
46+
x = uniform( len, -100.0, 100.0, {
47+
'dtype': 'generic'
48+
});
49+
y = zeros( len );
50+
51+
return benchmark;
52+
53+
/**
54+
* Benchmark function.
55+
*
56+
* @private
57+
* @param {Benchmark} b - benchmark instance
58+
*/
59+
function benchmark( b ) {
60+
var out;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = map( x, y, 1, 0, identity );
66+
if ( isnan( out[ i%len ] ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
72+
if ( isnan( out[ i % len ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = pow( 10, i );
100+
101+
f = createBenchmark( len );
102+
bench( pkg+':assign:dtype=generic,len='+len, f );
103+
}
104+
}
105+
106+
main();

0 commit comments

Comments
 (0)