Skip to content

Commit a417c21

Browse files
committed
Auto-generated commit
1 parent bd8ccb0 commit a417c21

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

+12747
-3
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,28 @@ This release closes the following issue:
984984

985985
<!-- /.package -->
986986

987+
<section class="package" id="ndarray-base-unary-reduce-strided1d-unreleased">
988+
989+
#### [@stdlib/ndarray/base/unary-reduce-strided1d](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-strided1d)
990+
991+
<details>
992+
993+
<section class="features">
994+
995+
##### Features
996+
997+
- [`ca10e52`](https://github.com/stdlib-js/stdlib/commit/ca10e526a8d174acca07ea25631f3254a768690c) - add `ndarray/base/unary-reduce-strided1d`
998+
999+
</section>
1000+
1001+
<!-- /.features -->
1002+
1003+
</details>
1004+
1005+
</section>
1006+
1007+
<!-- /.package -->
1008+
9871009
<section class="package" id="ndarray-base-unary-reduce-subarray-unreleased">
9881010

9891011
#### [@stdlib/ndarray/base/unary-reduce-subarray](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-subarray)
@@ -1497,6 +1519,12 @@ A total of 13 people contributed to this release. Thank you to the following con
14971519

14981520
<details>
14991521

1522+
- [`9d6cd84`](https://github.com/stdlib-js/stdlib/commit/9d6cd84404f09e09f22721d4e3bd1d083b8f83b1) - **chore:** add TODO _(by Athan Reines)_
1523+
- [`35612e9`](https://github.com/stdlib-js/stdlib/commit/35612e9369b15f22fc8be80a9da56cf73aee05d8) - **chore:** add TODO _(by Athan Reines)_
1524+
- [`ca10e52`](https://github.com/stdlib-js/stdlib/commit/ca10e526a8d174acca07ea25631f3254a768690c) - **feat:** add `ndarray/base/unary-reduce-strided1d` _(by Athan Reines)_
1525+
- [`999b4d7`](https://github.com/stdlib-js/stdlib/commit/999b4d7f258e8c9c20ef474b1839f62a9481c652) - **docs:** update note _(by Athan Reines)_
1526+
- [`a032199`](https://github.com/stdlib-js/stdlib/commit/a03219903da3dce11a6a290890078a969841e582) - **docs:** update description _(by Athan Reines)_
1527+
- [`29a39e8`](https://github.com/stdlib-js/stdlib/commit/29a39e8cb6562c29d96a91b3969ef35ae85b661a) - **chore:** update copyright year _(by Athan Reines)_
15001528
- [`cdc66ce`](https://github.com/stdlib-js/stdlib/commit/cdc66ce1876b95dd8c23aa2f869aebe9b842e86e) - **fix:** remove unused parameters _(by Athan Reines)_
15011529
- [`9485c2b`](https://github.com/stdlib-js/stdlib/commit/9485c2b14a159557d8d097c2cfbd106db12a2210) - **chore:** fix EditorConfig lint errors (issue #6663) [(#6672)](https://github.com/stdlib-js/stdlib/pull/6672) _(by Dipjyoti Das)_
15021530
- [`f9d3b79`](https://github.com/stdlib-js/stdlib/commit/f9d3b793f4100fcf1c9b7391550d3264bb395b00) - **docs:** update related packages sections [(#6670)](https://github.com/stdlib-js/stdlib/pull/6670) _(by stdlib-bot)_
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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+
# unaryReduceStrided1d
22+
23+
> Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction 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 unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d' );
37+
```
38+
39+
#### unaryReduceStrided1d( fcn, arrays, dims\[, options] )
40+
41+
Performs a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction 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 ndarray2array = require( '@stdlib/ndarray/base/to-array' );
48+
var getStride = require( '@stdlib/ndarray/base/stride' );
49+
var getOffset = require( '@stdlib/ndarray/base/offset' );
50+
var getData = require( '@stdlib/ndarray/base/data-buffer' );
51+
var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' );
52+
var gsum = require( '@stdlib/blas/ext/base/gsum' ).ndarray;
53+
54+
function wrapper( arrays ) {
55+
var x = arrays[ 0 ];
56+
return gsum( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) );
57+
}
58+
59+
// Create data buffers:
60+
var xbuf = 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 ] );
61+
var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] );
62+
63+
// Define the array shapes:
64+
var xsh = [ 1, 3, 2, 2 ];
65+
var ysh = [ 1, 3 ];
66+
67+
// Define the array strides:
68+
var sx = [ 12, 4, 2, 1 ];
69+
var sy = [ 3, 1 ];
70+
71+
// Define the index offsets:
72+
var ox = 0;
73+
var oy = 0;
74+
75+
// Create an input ndarray-like object:
76+
var x = {
77+
'dtype': 'float64',
78+
'data': xbuf,
79+
'shape': xsh,
80+
'strides': sx,
81+
'offset': ox,
82+
'order': 'row-major'
83+
};
84+
85+
// Create an output ndarray-like object:
86+
var y = {
87+
'dtype': 'float64',
88+
'data': ybuf,
89+
'shape': ysh,
90+
'strides': sy,
91+
'offset': oy,
92+
'order': 'row-major'
93+
};
94+
95+
// Perform a reduction:
96+
unaryReduceStrided1d( wrapper, [ x, y ], [ 2, 3 ] );
97+
98+
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
99+
// returns [ [ 10.0, 26.0, 42.0 ] ]
100+
```
101+
102+
The function accepts the following arguments:
103+
104+
- **fcn**: function which will be applied to a one-dimensional subarray and should reduce the subarray to a single scalar value.
105+
- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments.
106+
- **dims**: list of dimensions over which to perform a reduction.
107+
- **options**: function options which are passed through to `fcn` (_optional_).
108+
109+
Each provided ndarray should be an object with the following properties:
110+
111+
- **dtype**: data type.
112+
- **data**: data buffer.
113+
- **shape**: dimensions.
114+
- **strides**: stride lengths.
115+
- **offset**: index offset.
116+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
117+
118+
#### TODO: document factory method
119+
120+
</section>
121+
122+
<!-- /.usage -->
123+
124+
<section class="notes">
125+
126+
## Notes
127+
128+
- 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.
129+
130+
- The reduction function is expected to have the following signature:
131+
132+
```text
133+
fcn( arrays[, options] )
134+
```
135+
136+
where
137+
138+
- **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
139+
- **options**: function options (_optional_).
140+
141+
- 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.
142+
143+
</section>
144+
145+
<!-- /.notes -->
146+
147+
<section class="examples">
148+
149+
## Examples
150+
151+
<!-- eslint no-undef: "error" -->
152+
153+
```javascript
154+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
155+
var zeros = require( '@stdlib/array/base/zeros' );
156+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
157+
var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' );
158+
var getData = require( '@stdlib/ndarray/base/data-buffer' );
159+
var getStride = require( '@stdlib/ndarray/base/stride' );
160+
var getOffset = require( '@stdlib/ndarray/base/offset' );
161+
var gsum = require( '@stdlib/blas/ext/base/gsum' ).ndarray;
162+
var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d' );
163+
164+
function wrapper( arrays ) {
165+
var x = arrays[ 0 ];
166+
return gsum( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
167+
}
168+
169+
var N = 10;
170+
var x = {
171+
'dtype': 'generic',
172+
'data': discreteUniform( N, -5, 5, {
173+
'dtype': 'generic'
174+
}),
175+
'shape': [ 1, 5, 2 ],
176+
'strides': [ 10, 2, 1 ],
177+
'offset': 0,
178+
'order': 'row-major'
179+
};
180+
var y = {
181+
'dtype': 'generic',
182+
'data': zeros( 2 ),
183+
'shape': [ 1, 2 ],
184+
'strides': [ 2, 1 ],
185+
'offset': 0,
186+
'order': 'row-major'
187+
};
188+
189+
unaryReduceStrided1d( wrapper, [ x, y ], [ 1 ] );
190+
191+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
192+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
193+
```
194+
195+
</section>
196+
197+
<!-- /.examples -->
198+
199+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
200+
201+
<section class="related">
202+
203+
</section>
204+
205+
<!-- /.related -->
206+
207+
<section class="links">
208+
209+
</section>
210+
211+
<!-- /.links -->
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
{{alias}}( fcn, arrays, dims[, options] )
3+
Performs a reduction over a list of specified dimensions in an input ndarray
4+
via a one-dimensional strided array reduction function and assigns results
5+
to a provided output ndarray.
6+
7+
Each provided "ndarray" should be an object with the following properties:
8+
9+
- dtype: data type.
10+
- data: data buffer.
11+
- shape: dimensions.
12+
- strides: stride lengths.
13+
- offset: index offset.
14+
- order: specifies whether an ndarray is row-major (C-style) or column-major
15+
(Fortran-style).
16+
17+
The output ndarray and any additional ndarray arguments are expected to have
18+
the same dimensions as the non-reduced dimensions of the input ndarray. When
19+
calling the reduction function, any additional ndarray arguments are
20+
provided as zero-dimensional ndarray-like objects.
21+
22+
Parameters
23+
----------
24+
fcn: Function
25+
Function which will be applied to a one-dimensional subarray and should
26+
reduce the subarray to a single scalar value. The function should have
27+
the following signature:
28+
29+
fcn( arrays[, options] )
30+
31+
where
32+
33+
- arrays: array containing a one-dimensional subarray of the input
34+
ndarray and any additional ndarray arguments as zero-dimensional
35+
ndarrays.
36+
- options: function options.
37+
38+
arrays: ArrayLikeObject<ndarray>
39+
Array-like object containing one input ndarray and one output ndarray,
40+
followed by any additional ndarray arguments.
41+
42+
dims: Array<integer>
43+
List of dimensions over which to perform a reduction.
44+
45+
options: Object (optional)
46+
Function options.
47+
48+
Examples
49+
--------
50+
// Define ndarray data and meta data...
51+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
52+
> var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0 ] );
53+
> var dtype = 'float64';
54+
> var shx = [ 2, 2 ];
55+
> var shy = [];
56+
> var sx = [ 2, 1 ];
57+
> var sy = [ 0 ];
58+
> var ox = 0;
59+
> var oy = 0;
60+
> var order = 'row-major';
61+
62+
// Define a wrapper for an extended BLAS function...
63+
> function fcn( arrays ) {
64+
... var x = arrays[ 0 ];
65+
... var N = x.shape[ 0 ];
66+
... var d = x.data;
67+
... var s = x.strides[ 0 ];
68+
... var o = x.offset;
69+
... return {{alias:@stdlib/blas/ext/base/gsum}}.ndarray( N, d, s, o );
70+
... };
71+
72+
// Using minimal ndarray-like objects...
73+
> x = {
74+
... 'dtype': dtype,
75+
... 'data': xbuf,
76+
... 'shape': shx,
77+
... 'strides': sx,
78+
... 'offset': ox,
79+
... 'order': order
80+
... };
81+
> y = {
82+
... 'dtype': dtype,
83+
... 'data': ybuf,
84+
... 'shape': shy,
85+
... 'strides': sy,
86+
... 'offset': oy,
87+
... 'order': order
88+
... };
89+
> {{alias}}( fcn, [ x, y ], [ 0, 1 ] );
90+
> y.data
91+
<Float64Array>[ 10.0 ]
92+
93+
See Also
94+
--------
95+

0 commit comments

Comments
 (0)