Skip to content

Commit 3fea255

Browse files
committed
Auto-generated commit
1 parent dfdab8e commit 3fea255

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+13484
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`5149a37`](https://github.com/stdlib-js/stdlib/commit/5149a3789bf321b18b1636b838ab086175b6c2ca) - add `ndarray/base/unary-reduce-subarray-by` [(#7008)](https://github.com/stdlib-js/stdlib/pull/7008)
1314
- [`54dc71e`](https://github.com/stdlib-js/stdlib/commit/54dc71e0ff4a2b5661d48a1bdee584507f66373f) - add `every` and `includes` to namespace
1415
- [`2349a6e`](https://github.com/stdlib-js/stdlib/commit/2349a6edf849f8f7093a77bbdeb2fdd7d9955f89) - add `vector` to namespace
1516
- [`1ab9f58`](https://github.com/stdlib-js/stdlib/commit/1ab9f58bcd109f19afd9ab08212d69bfe9d32bbe) - add `ndarray/vector` namespace
@@ -406,6 +407,7 @@ A total of 15 issues were closed in this release:
406407

407408
<details>
408409

410+
- [`5149a37`](https://github.com/stdlib-js/stdlib/commit/5149a3789bf321b18b1636b838ab086175b6c2ca) - **feat:** add `ndarray/base/unary-reduce-subarray-by` [(#7008)](https://github.com/stdlib-js/stdlib/pull/7008) _(by Muhammad Haris, Athan Reines)_
409411
- [`89d9dc3`](https://github.com/stdlib-js/stdlib/commit/89d9dc316985aa3c194222afbf8146e58ff6d761) - **docs:** update namespace table of contents [(#7046)](https://github.com/stdlib-js/stdlib/pull/7046) _(by stdlib-bot)_
410412
- [`a300862`](https://github.com/stdlib-js/stdlib/commit/a300862d4f05d4d8bd85f1e235db93ad5d35a767) - **fix:** address increment bugs _(by Athan Reines)_
411413
- [`fab9873`](https://github.com/stdlib-js/stdlib/commit/fab9873a907807195f2f6673b5b97f09e383bd69) - **fix:** address index bug _(by Athan Reines)_

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Ryan Seal <[email protected]>
146146
Rylan Yang <[email protected]>
147147
SAHIL KUMAR <[email protected]>
148148
SHIVAM YADAV <[email protected]>
149+
Sachin Raj <[email protected]>
149150
Sahil Goyal <[email protected]>
150151
Sai Avinash <[email protected]>
151152
Sai Srikar Dumpeti <[email protected]>
@@ -170,6 +171,7 @@ Tanishq Ahuja <[email protected]>
170171
Tirtadwipa Manunggal <[email protected]>
171172
Tudor Pagu <[email protected]>
172173
Tufailahmed Bargir <[email protected]>
174+
Uday Kakade <[email protected]>
173175
Utkarsh <http://[email protected]>
174176
Utkarsh Raj <[email protected]>
175177
UtkershBasnet <[email protected]>
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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+
# unaryReduceSubarrayBy
22+
23+
> Perform a reduction over a list of specified dimensions in an input ndarray according to a callback function and assign results to a provided output ndarray.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var unaryReduceSubarrayBy = require( '@stdlib/ndarray/base/unary-reduce-subarray-by' );
37+
```
38+
39+
#### unaryReduceSubarrayBy( fcn, arrays, dims\[, options], clbk\[, thisArg] )
40+
41+
Performs a reduction over a list of specified dimensions in an input ndarray according to a callback function and assigns results to a provided output ndarray.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
var filled = require( '@stdlib/array/base/filled' );
48+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
49+
var everyBy = require( '@stdlib/ndarray/base/every-by' );
50+
51+
function clbk( value ) {
52+
return value > 0.0;
53+
}
54+
55+
// Create data buffers:
56+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
57+
var ybuf = filled( false, 3 );
58+
59+
// Define the array shapes:
60+
var xsh = [ 1, 3, 2, 2 ];
61+
var ysh = [ 1, 3 ];
62+
63+
// Define the array strides:
64+
var sx = [ 12, 4, 2, 1 ];
65+
var sy = [ 3, 1 ];
66+
67+
// Define the index offsets:
68+
var ox = 0;
69+
var oy = 0;
70+
71+
// Create an input ndarray-like object:
72+
var x = {
73+
'dtype': 'float64',
74+
'data': xbuf,
75+
'shape': xsh,
76+
'strides': sx,
77+
'offset': ox,
78+
'order': 'row-major'
79+
};
80+
81+
// Create an output ndarray-like object:
82+
var y = {
83+
'dtype': 'generic',
84+
'data': ybuf,
85+
'shape': ysh,
86+
'strides': sy,
87+
'offset': oy,
88+
'order': 'row-major'
89+
};
90+
91+
// Perform a reduction:
92+
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], clbk );
93+
94+
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
95+
// returns [ [ true, false, true ] ]
96+
```
97+
98+
The function accepts the following arguments:
99+
100+
- **fcn**: function which will be applied to a subarray and should reduce the subarray to a single scalar value.
101+
- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments.
102+
- **dims**: list of dimensions over which to perform a reduction.
103+
- **options**: function options which are passed through to `fcn` (_optional_).
104+
- **clbk**: callback function.
105+
- **thisArg**: callback execution context (_optional_).
106+
107+
Each provided ndarray should be an object with the following properties:
108+
109+
- **dtype**: data type.
110+
- **data**: data buffer.
111+
- **shape**: dimensions.
112+
- **strides**: stride lengths.
113+
- **offset**: index offset.
114+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
115+
116+
The invoked callback function is provided the following arguments:
117+
118+
- **value**: input array element.
119+
- **indices**: current array element indices.
120+
- **arr**: the input ndarray.
121+
122+
To set the callback execution context, provide a `thisArg`.
123+
124+
<!-- eslint-disable max-len -->
125+
126+
```javascript
127+
var Float64Array = require( '@stdlib/array/float64' );
128+
var filled = require( '@stdlib/array/base/filled' );
129+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
130+
var everyBy = require( '@stdlib/ndarray/base/every-by' );
131+
132+
function clbk( value ) {
133+
this.count += 1;
134+
return value > 0.0;
135+
}
136+
137+
// Create data buffers:
138+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
139+
var ybuf = filled( false, 6 );
140+
141+
// Define the array shapes:
142+
var xsh = [ 3, 2, 2 ];
143+
var ysh = [ 3, 2 ];
144+
145+
// Define the array strides:
146+
var sx = [ 4, 2, 1 ];
147+
var sy = [ 2, 1 ];
148+
149+
// Define the index offsets:
150+
var ox = 0;
151+
var oy = 0;
152+
153+
// Create an input ndarray-like object:
154+
var x = {
155+
'dtype': 'float64',
156+
'data': xbuf,
157+
'shape': xsh,
158+
'strides': sx,
159+
'offset': ox,
160+
'order': 'row-major'
161+
};
162+
163+
// Create an output ndarray-like object:
164+
var y = {
165+
'dtype': 'generic',
166+
'data': ybuf,
167+
'shape': ysh,
168+
'strides': sy,
169+
'offset': oy,
170+
'order': 'row-major'
171+
};
172+
173+
var ctx = {
174+
'count': 0
175+
};
176+
177+
// Perform a reduction:
178+
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 1 ], clbk, ctx );
179+
180+
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
181+
// returns [ [ true, true ], [ true, false ], [ true, true ] ]
182+
183+
var count = ctx.count;
184+
// returns 11
185+
```
186+
187+
#### TODO: document factory method
188+
189+
</section>
190+
191+
<!-- /.usage -->
192+
193+
<section class="notes">
194+
195+
## Notes
196+
197+
- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarray. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
198+
199+
- The reduction function is expected to have the following signature:
200+
201+
```text
202+
fcn( arrays[, options], wrappedCallback )
203+
```
204+
205+
where
206+
207+
- **arrays**: array containing a subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
208+
- **options**: function options (_optional_).
209+
- **wrappedCallback**: callback function. This function is a wrapper around a provided `clbk` argument.
210+
211+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance.
212+
213+
</section>
214+
215+
<!-- /.notes -->
216+
217+
<section class="examples">
218+
219+
## Examples
220+
221+
<!-- eslint no-undef: "error" -->
222+
223+
```javascript
224+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
225+
var filled = require( '@stdlib/array/base/filled' );
226+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
227+
var everyBy = require( '@stdlib/ndarray/base/every-by' );
228+
var unaryReduceSubarrayBy = require( '@stdlib/ndarray/base/unary-reduce-subarray-by' );
229+
230+
function clbk( value ) {
231+
return value > -3;
232+
}
233+
234+
var x = {
235+
'dtype': 'generic',
236+
'data': discreteUniform( 40, -5, 5, {
237+
'dtype': 'generic'
238+
}),
239+
'shape': [ 2, 5, 2, 2 ],
240+
'strides': [ 1, 2, 10, 20 ],
241+
'offset': 0,
242+
'order': 'column-major'
243+
};
244+
var y = {
245+
'dtype': 'generic',
246+
'data': filled( false, 10 ),
247+
'shape': [ 2, 5 ],
248+
'strides': [ 1, 2 ],
249+
'offset': 0,
250+
'order': 'column-major'
251+
};
252+
253+
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], clbk );
254+
255+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
256+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
257+
```
258+
259+
</section>
260+
261+
<!-- /.examples -->
262+
263+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
264+
265+
<section class="related">
266+
267+
</section>
268+
269+
<!-- /.related -->
270+
271+
<section class="links">
272+
273+
</section>
274+
275+
<!-- /.links -->

0 commit comments

Comments
 (0)