Skip to content

Commit b8cacc1

Browse files
committed
docs: add README and fix docs
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c2e0a60 commit b8cacc1

File tree

26 files changed

+549
-216
lines changed

26 files changed

+549
-216
lines changed
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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-to-struct' );
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 Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' );
49+
var structFactory = require( '@stdlib/array/struct-factory' );
50+
var ztest = require( '@stdlib/stats/base/ndarray/ztest' );
51+
52+
var ResultsArray = structFactory( Float64Results );
53+
54+
// Create data buffers:
55+
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 ] );
56+
var ybuf = new ResultsArray( 3 );
57+
58+
// Define the array shapes:
59+
var xsh = [ 1, 3, 2, 2 ];
60+
var ysh = [ 1, 3 ];
61+
62+
// Define the array strides:
63+
var sx = [ 12, 4, 2, 1 ];
64+
var sy = [ 3, 1 ];
65+
66+
// Define the index offsets:
67+
var ox = 0;
68+
var oy = 0;
69+
70+
// Create an input ndarray-like object:
71+
var x = {
72+
'dtype': 'float64',
73+
'data': xbuf,
74+
'shape': xsh,
75+
'strides': sx,
76+
'offset': ox,
77+
'order': 'row-major'
78+
};
79+
80+
// Create an output ndarray-like object:
81+
var y = {
82+
'dtype': Float64Results,
83+
'data': ybuf,
84+
'shape': ysh,
85+
'strides': sy,
86+
'offset': oy,
87+
'order': 'row-major'
88+
};
89+
90+
// Create additional parameter ndarray-like objects:
91+
var alternative = {
92+
'dtype': 'generic',
93+
'data': [ 'two-sided' ],
94+
'shape': ysh,
95+
'strides': [ 0, 0 ],
96+
'offset': 0,
97+
'order': 'row-major'
98+
};
99+
var alpha = {
100+
'dtype': 'float64',
101+
'data': [ 0.05 ],
102+
'shape': ysh,
103+
'strides': [ 0, 0 ],
104+
'offset': 0,
105+
'order': 'row-major'
106+
};
107+
var mu = {
108+
'dtype': 'float64',
109+
'data': [ 0.0 ],
110+
'shape': ysh,
111+
'strides': [ 0, 0 ],
112+
'offset': 0,
113+
'order': 'row-major'
114+
};
115+
var sigma = {
116+
'dtype': 'float64',
117+
'data': [ 1.0 ],
118+
'shape': ysh,
119+
'strides': [ 0, 0 ],
120+
'offset': 0,
121+
'order': 'row-major'
122+
};
123+
124+
// Perform a reduction:
125+
unaryReduceStrided1d( ztest, [ x, y, alternative, alpha, mu, sigma ], [ 2, 3 ] );
126+
127+
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
128+
// returns [ [ <Float64Results>, <Float64Results>, <Float64Results> ] ]
129+
```
130+
131+
The function accepts the following arguments:
132+
133+
- **fcn**: function which will be applied to a one-dimensional subarray and should store reduction results in an output [`struct`][@stdlib/dstructs/struct] object.
134+
- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments.
135+
- **dims**: list of dimensions over which to perform a reduction.
136+
- **options**: function options which are passed through to `fcn` (_optional_).
137+
138+
Each provided ndarray should be an object with the following properties:
139+
140+
- **dtype**: data type.
141+
- **data**: data buffer.
142+
- **shape**: dimensions.
143+
- **strides**: stride lengths.
144+
- **offset**: index offset.
145+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
146+
147+
#### TODO: document factory method
148+
149+
</section>
150+
151+
<!-- /.usage -->
152+
153+
<section class="notes">
154+
155+
## Notes
156+
157+
- 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.
158+
159+
- The reduction function is expected to have the following signature:
160+
161+
```text
162+
fcn( arrays[, options] )
163+
```
164+
165+
where
166+
167+
- **arrays**: array containing a one-dimensional subarray of the input ndarray, a zero-dimensional subarray of the output ndarray containing the output [`struct`][@stdlib/dstructs/struct] object, and any additional ndarray arguments as zero-dimensional ndarrays.
168+
- **options**: function options (_optional_).
169+
170+
- 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.
171+
172+
</section>
173+
174+
<!-- /.notes -->
175+
176+
<section class="examples">
177+
178+
## Examples
179+
180+
<!-- eslint no-undef: "error" -->
181+
182+
```javascript
183+
var normal = require( '@stdlib/random/array/normal' );
184+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
185+
var Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' );
186+
var structFactory = require( '@stdlib/array/struct-factory' );
187+
var ztest = require( '@stdlib/stats/base/ndarray/ztest' );
188+
var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d-to-struct' );
189+
190+
var ResultsArray = structFactory( Float64Results );
191+
192+
var N = 10;
193+
var x = {
194+
'dtype': 'generic',
195+
'data': normal( N, 0.0, 1.0, {
196+
'dtype': 'generic'
197+
}),
198+
'shape': [ 1, 5, 2 ],
199+
'strides': [ 10, 2, 1 ],
200+
'offset': 0,
201+
'order': 'row-major'
202+
};
203+
var y = {
204+
'dtype': Float64Results,
205+
'data': new ResultsArray( 2 ),
206+
'shape': [ 1, 2 ],
207+
'strides': [ 2, 1 ],
208+
'offset': 0,
209+
'order': 'row-major'
210+
};
211+
var alternative = {
212+
'dtype': 'generic',
213+
'data': [ 'two-sided' ],
214+
'shape': [ 1, 2 ],
215+
'strides': [ 0, 0 ],
216+
'offset': 0,
217+
'order': 'row-major'
218+
};
219+
var alpha = {
220+
'dtype': 'generic',
221+
'data': [ 0.05 ],
222+
'shape': [ 1, 2 ],
223+
'strides': [ 0, 0 ],
224+
'offset': 0,
225+
'order': 'row-major'
226+
};
227+
var mu = {
228+
'dtype': 'generic',
229+
'data': [ 0.0 ],
230+
'shape': [ 1, 2 ],
231+
'strides': [ 0, 0 ],
232+
'offset': 0,
233+
'order': 'row-major'
234+
};
235+
var sigma = {
236+
'dtype': 'generic',
237+
'data': [ 1.0 ],
238+
'shape': [ 1, 2 ],
239+
'strides': [ 0, 0 ],
240+
'offset': 0,
241+
'order': 'row-major'
242+
};
243+
244+
unaryReduceStrided1d( ztest, [ x, y, alternative, alpha, mu, sigma ], [ 1 ] );
245+
246+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
247+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
248+
```
249+
250+
</section>
251+
252+
<!-- /.examples -->
253+
254+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
255+
256+
<section class="related">
257+
258+
</section>
259+
260+
<!-- /.related -->
261+
262+
<section class="links">
263+
264+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct
265+
266+
</section>
267+
268+
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-to-struct/lib/0d.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@
7777
*
7878
* // Create additional parameter ndarray-like objects:
7979
* var alternative = {
80-
* 'dtype': 'generic',
81-
* 'data': [ 'two-sided' ],
82-
* 'shape': ysh,
83-
* 'strides': [ 0 ],
84-
* 'offset': 0,
85-
* 'order': 'row-major'
80+
* 'dtype': 'generic',
81+
* 'data': [ 'two-sided' ],
82+
* 'shape': ysh,
83+
* 'strides': [ 0 ],
84+
* 'offset': 0,
85+
* 'order': 'row-major'
8686
};
8787
* var alpha = {
8888
* 'dtype': 'float64',
@@ -91,15 +91,15 @@
9191
* 'strides': [ 0 ],
9292
* 'offset': 0,
9393
* 'order': 'row-major'
94-
};
94+
* };
9595
* var mu = {
9696
* 'dtype': 'float64',
9797
* 'data': [ 0.0 ],
9898
* 'shape': ysh,
9999
* 'strides': [ 0 ],
100100
* 'offset': 0,
101101
* 'order': 'row-major'
102-
};
102+
* };
103103
* var sigma = {
104104
* 'dtype': 'float64',
105105
* 'data': [ 1.0 ],

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-to-struct/lib/10d.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ var offsets = require( './offsets.js' );
9090
*
9191
* // Create additional parameter ndarray-like objects:
9292
* var alternative = {
93-
* 'dtype': 'generic',
94-
* 'data': [ 'two-sided' ],
95-
* 'shape': ysh,
96-
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
97-
* 'offset': 0,
98-
* 'order': 'row-major'
93+
* 'dtype': 'generic',
94+
* 'data': [ 'two-sided' ],
95+
* 'shape': ysh,
96+
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
97+
* 'offset': 0,
98+
* 'order': 'row-major'
9999
};
100100
* var alpha = {
101101
* 'dtype': 'float64',
@@ -104,15 +104,15 @@ var offsets = require( './offsets.js' );
104104
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
105105
* 'offset': 0,
106106
* 'order': 'row-major'
107-
};
107+
* };
108108
* var mu = {
109109
* 'dtype': 'float64',
110110
* 'data': [ 0.0 ],
111111
* 'shape': ysh,
112112
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
113113
* 'offset': 0,
114114
* 'order': 'row-major'
115-
};
115+
* };
116116
* var sigma = {
117117
* 'dtype': 'float64',
118118
* 'data': [ 1.0 ],

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-to-struct/lib/10d_blocked.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ var offsets = require( './offsets.js' );
9393
*
9494
* // Create additional parameter ndarray-like objects:
9595
* var alternative = {
96-
* 'dtype': 'generic',
97-
* 'data': [ 'two-sided' ],
98-
* 'shape': ysh,
99-
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
100-
* 'offset': 0,
101-
* 'order': 'row-major'
96+
* 'dtype': 'generic',
97+
* 'data': [ 'two-sided' ],
98+
* 'shape': ysh,
99+
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
100+
* 'offset': 0,
101+
* 'order': 'row-major'
102102
};
103103
* var alpha = {
104104
* 'dtype': 'float64',
@@ -107,15 +107,15 @@ var offsets = require( './offsets.js' );
107107
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
108108
* 'offset': 0,
109109
* 'order': 'row-major'
110-
};
110+
* };
111111
* var mu = {
112112
* 'dtype': 'float64',
113113
* 'data': [ 0.0 ],
114114
* 'shape': ysh,
115115
* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
116116
* 'offset': 0,
117117
* 'order': 'row-major'
118-
};
118+
* };
119119
* var sigma = {
120120
* 'dtype': 'float64',
121121
* 'data': [ 1.0 ],

0 commit comments

Comments
 (0)