Skip to content

Commit fe6e54b

Browse files
committed
Auto-generated commit
1 parent 53a07d4 commit fe6e54b

File tree

13 files changed

+2791
-2
lines changed

13 files changed

+2791
-2
lines changed

CHANGELOG.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-12-12)
7+
## Unreleased (2024-12-13)
88

99
<section class="packages">
1010

@@ -146,6 +146,28 @@
146146

147147
<!-- /.package -->
148148

149+
<section class="package" id="ndarray-map-unreleased">
150+
151+
#### [@stdlib/ndarray/map](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/map)
152+
153+
<details>
154+
155+
<section class="features">
156+
157+
##### Features
158+
159+
- [`3ea906b`](https://github.com/stdlib-js/stdlib/commit/3ea906bb64f93b4d323bc91f99a176d2729a2cc9) - add `ndarray/map` [(#3314)](https://github.com/stdlib-js/stdlib/pull/3314)
160+
161+
</section>
162+
163+
<!-- /.features -->
164+
165+
</details>
166+
167+
</section>
168+
169+
<!-- /.package -->
170+
149171
</section>
150172

151173
<!-- /.packages -->
@@ -166,8 +188,10 @@
166188

167189
### Contributors
168190

169-
A total of 1 person contributed to this release. Thank you to this contributor:
191+
A total of 3 people contributed to this release. Thank you to the following contributors:
170192

193+
- Athan Reines
194+
- Muhammad Haris
171195
- Philipp Burckhardt
172196

173197
</section>
@@ -180,6 +204,7 @@ A total of 1 person contributed to this release. Thank you to this contributor:
180204

181205
<details>
182206

207+
- [`3ea906b`](https://github.com/stdlib-js/stdlib/commit/3ea906bb64f93b4d323bc91f99a176d2729a2cc9) - **feat:** add `ndarray/map` [(#3314)](https://github.com/stdlib-js/stdlib/pull/3314) _(by Muhammad Haris, Athan Reines)_
183208
- [`cf7d38a`](https://github.com/stdlib-js/stdlib/commit/cf7d38ae3e7bce92cf47778f7b1c3da731121d77) - **docs:** update related packages sections [(#3527)](https://github.com/stdlib-js/stdlib/pull/3527) _(by stdlib-bot)_
184209
- [`bf5643f`](https://github.com/stdlib-js/stdlib/commit/bf5643fb1a3f32a60903d8e210f71571e609119f) - **docs:** update related packages sections [(#3404)](https://github.com/stdlib-js/stdlib/pull/3404) _(by stdlib-bot)_
185210
- [`a80835b`](https://github.com/stdlib-js/stdlib/commit/a80835b8f9959a15751adfce5572bb2b29cfeeed) - **refactor:** declare parameters and pointer as const _(by Philipp Burckhardt)_

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ UtkershBasnet <[email protected]>
112112
Vaibhav Patel <[email protected]>
113113
Varad Gupta <[email protected]>
114114
Vinit Pandit <[email protected]>
115+
Vivek maurya <[email protected]>
115116
Xiaochuan Ye <[email protected]>
116117
Yaswanth Kosuru <[email protected]>
117118
Yernar Yergaziyev <[email protected]>

map/README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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 [ndarray][@stdlib/ndarray/ctor] and assign results to elements in a new output [ndarray][@stdlib/ndarray/ctor].
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var map = require( '@stdlib/ndarray/map' );
37+
```
38+
39+
#### map( x\[, options], fcn\[, thisArg] )
40+
41+
Applies a callback function to elements in an input [ndarray][@stdlib/ndarray/ctor] and assigns results to elements in a new output [ndarray][@stdlib/ndarray/ctor].
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
var ndarray = require( '@stdlib/ndarray/ctor' );
48+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
49+
50+
function scale( z ) {
51+
return z * 10.0;
52+
}
53+
54+
var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
55+
var shape = [ 2, 3 ];
56+
var strides = [ 6, 1 ];
57+
var offset = 1;
58+
59+
var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
60+
// returns <ndarray>
61+
62+
var y = map( x, scale );
63+
// returns <ndarray>
64+
65+
var arr = ndarray2array( y );
66+
// returns [ [ 20.0, 30.0, 40.0 ], [ 80.0, 90.0, 100.0 ] ]
67+
```
68+
69+
The function accepts the following arguments:
70+
71+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
72+
- **options**: function options.
73+
- **fcn**: callback to apply.
74+
- **thisArg**: callback execution context.
75+
76+
The function accepts the following options:
77+
78+
- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. If not specified, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor].
79+
80+
By default, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. To return an ndarray with a different [data type][@stdlib/ndarray/dtypes], specify the `dtype` option.
81+
82+
<!-- eslint-disable max-len -->
83+
84+
```javascript
85+
var Float64Array = require( '@stdlib/array/float64' );
86+
var ndarray = require( '@stdlib/ndarray/ctor' );
87+
var dtype = require( '@stdlib/ndarray/dtype' );
88+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
89+
90+
function scale( z ) {
91+
return z * 10.0;
92+
}
93+
94+
var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
95+
var shape = [ 2, 3 ];
96+
var strides = [ 6, 1 ];
97+
var offset = 1;
98+
99+
var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
100+
// returns <ndarray>
101+
102+
var opts = {
103+
'dtype': 'float32'
104+
};
105+
var y = map( x, opts, scale );
106+
// returns <ndarray>
107+
108+
var dt = dtype( y );
109+
// returns 'float32'
110+
111+
var arr = ndarray2array( y );
112+
// returns [ [ 20.0, 30.0, 40.0 ], [ 80.0, 90.0, 100.0 ] ]
113+
```
114+
115+
The callback function is provided the following arguments:
116+
117+
- **values**: current array element.
118+
- **indices**: current array element indices.
119+
- **arr**: the input [ndarray][@stdlib/ndarray/ctor].
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<section class="notes">
126+
127+
## Notes
128+
129+
- The function does **not** perform explicit casting (e.g., from a real-valued floating-point number to a complex floating-point number). Any such casting should be performed by a provided callback function.
130+
131+
<!-- eslint-disable max-len -->
132+
133+
```javascript
134+
var Float64Array = require( '@stdlib/array/float64' );
135+
var ndarray = require( '@stdlib/ndarray/ctor' );
136+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
137+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
138+
139+
function toComplex( z ) {
140+
return new Complex128( z, 0.0 );
141+
}
142+
143+
var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
144+
var shape = [ 2, 3 ];
145+
var strides = [ 6, 1 ];
146+
var offset = 1;
147+
148+
var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
149+
// returns <ndarray>
150+
151+
var opts = {
152+
'dtype': 'complex128'
153+
};
154+
var y = map( x, opts, toComplex );
155+
// returns <ndarray>
156+
```
157+
158+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a callback function in order to achieve better performance.
159+
160+
</section>
161+
162+
<!-- /.notes -->
163+
164+
<section class="examples">
165+
166+
## Examples
167+
168+
<!-- eslint no-undef: "error" -->
169+
170+
```javascript
171+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
172+
var abs = require( '@stdlib/math/base/special/abs' );
173+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
174+
var naryFunction = require( '@stdlib/utils/nary-function' );
175+
var ndarray = require( '@stdlib/ndarray/ctor' );
176+
var map = require( '@stdlib/ndarray/map' );
177+
178+
var buffer = discreteUniform( 10, -100, 100, {
179+
'dtype': 'generic'
180+
});
181+
var shape = [ 5, 2 ];
182+
var strides = [ 2, 1 ];
183+
var offset = 0;
184+
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
185+
console.log( ndarray2array( x ) );
186+
187+
var y = map( x, naryFunction( abs, 1 ) );
188+
console.log( ndarray2array( y ) );
189+
```
190+
191+
</section>
192+
193+
<!-- /.examples -->
194+
195+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
196+
197+
<section class="related">
198+
199+
</section>
200+
201+
<!-- /.related -->
202+
203+
<section class="links">
204+
205+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
206+
207+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
208+
209+
<!-- <related-links> -->
210+
211+
<!-- </related-links> -->
212+
213+
</section>
214+
215+
<!-- /.links -->

0 commit comments

Comments
 (0)