Skip to content

Commit 03a47ea

Browse files
committed
feat: add stats/strided/dcumaxabs
Ref: stdlib-js#4797 --- 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: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent a93ccc0 commit 03a47ea

33 files changed

+4220
-0
lines changed
+337
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2020 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+
<!-- lint disable maximum-heading-length -->
22+
23+
# dcumaxabs
24+
25+
> Calculate the cumulative maximum absolute value of double-precision floating-point strided array elements.
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<section class="usage">
34+
35+
## Usage
36+
37+
```javascript
38+
var dcumaxabs = require( '@stdlib/stats/strided/dcumaxabs' );
39+
```
40+
41+
#### dcumaxabs( N, x, strideX, y, strideY )
42+
43+
Computes the cumulative maximum absolute value of double-precision floating-point strided array elements.
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
48+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
49+
var y = new Float64Array( x.length );
50+
51+
dcumaxabs( x.length, x, 1, y, 1 );
52+
// y => <Float64Array>[ 1.0, 2.0, 2.0 ]
53+
```
54+
55+
The function has the following parameters:
56+
57+
- **N**: number of indexed elements.
58+
- **x**: input [`Float64Array`][@stdlib/array/float64].
59+
- **strideX**: stride length for `x`.
60+
- **y**: output [`Float64Array`][@stdlib/array/float64].
61+
- **strideY**: stride length for `y`.
62+
63+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative maximum absolute value of every other element in `x`,
64+
65+
```javascript
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
68+
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
69+
var y = new Float64Array( x.length );
70+
71+
var v = dcumaxabs( 4, x, 2, y, 1 );
72+
// y => <Float64Array>[ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
73+
```
74+
75+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
76+
77+
<!-- eslint-disable stdlib/capitalized-comments -->
78+
79+
```javascript
80+
var Float64Array = require( '@stdlib/array/float64' );
81+
82+
// Initial arrays...
83+
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
84+
var y0 = new Float64Array( x0.length );
85+
86+
// Create offset views...
87+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
88+
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
89+
90+
dcumaxabs( 4, x1, -2, y1, 1 );
91+
// y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0, 0.0 ]
92+
```
93+
94+
#### dcumaxabs.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
95+
96+
Computes the cumulative maximum absolute value of double-precision floating-point strided array elements using alternative indexing semantics.
97+
98+
```javascript
99+
var Float64Array = require( '@stdlib/array/float64' );
100+
101+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
102+
var y = new Float64Array( x.length );
103+
104+
dcumaxabs.ndarray( x.length, x, 1, 0, y, 1, 0 );
105+
// y => <Float64Array>[ 1.0, 2.0, 2.0 ]
106+
```
107+
108+
The function has the following additional parameters:
109+
110+
- **offsetX**: starting index for `x`.
111+
- **offsetY**: starting index for `y`.
112+
113+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative maximum absolute value of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element
114+
115+
```javascript
116+
var Float64Array = require( '@stdlib/array/float64' );
117+
118+
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
119+
var y = new Float64Array( x.length );
120+
121+
dcumaxabs.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
122+
// y => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 4.0, 2.0, 2.0, 1.0 ]
123+
```
124+
125+
</section>
126+
127+
<!-- /.usage -->
128+
129+
<section class="notes">
130+
131+
## Notes
132+
133+
- If `N <= 0`, both functions return `y` unchanged.
134+
135+
</section>
136+
137+
<!-- /.notes -->
138+
139+
<section class="examples">
140+
141+
## Examples
142+
143+
<!-- eslint no-undef: "error" -->
144+
145+
```javascript
146+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
147+
var Float64Array = require( '@stdlib/array/float64' );
148+
var dcumaxabs = require( '@stdlib/stats/strided/dcumaxabs' );
149+
150+
var x = discreteUniform( 10, -50, 50, {
151+
'dtype': 'float64'
152+
});
153+
console.log( x );
154+
155+
var y = new Float64Array( x.length );
156+
console.log( y );
157+
158+
dcumaxabs( x.length, x, 1, y, -1 );
159+
console.log( y );
160+
```
161+
162+
</section>
163+
164+
<!-- /.examples -->
165+
166+
<!-- C interface documentation. -->
167+
168+
* * *
169+
170+
<section class="c">
171+
172+
## C APIs
173+
174+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
175+
176+
<section class="intro">
177+
178+
</section>
179+
180+
<!-- /.intro -->
181+
182+
<!-- C usage documentation. -->
183+
184+
<section class="usage">
185+
186+
### Usage
187+
188+
```c
189+
#include "stdlib/stats/strided/dcumaxabs.h"
190+
```
191+
192+
#### stdlib_strided_dcumaxabs( N, \*X, strideX, \*Y, strideY )
193+
194+
Computes the cumulative maximum absolute value of double-precision floating-point strided array elements.
195+
196+
```c
197+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
198+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
199+
200+
stdlib_strided_dcumaxabs( 4, x, 2, y, -2 );
201+
```
202+
203+
The function accepts the following arguments:
204+
205+
- **N**: `[in] CBLAS_INT` number of indexed elements.
206+
- **X**: `[in] double*` input array.
207+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
208+
- **Y**: `[out] double*` output array.
209+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
210+
211+
```c
212+
void stdlib_strided_dcumaxabs( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
213+
```
214+
215+
#### stdlib_strided_dcumaxabs_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY )
216+
217+
Computes the cumulative maximum absolute value of double-precision floating-point strided array elements using alternative indexing semantics.
218+
219+
```c
220+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
221+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
222+
223+
stdlib_strided_dcumaxabs_ndarray( 4, x, 2, 0, y, -2, 0 );
224+
```
225+
226+
The function accepts the following arguments:
227+
228+
- **N**: `[in] CBLAS_INT` number of indexed elements.
229+
- **X**: `[in] double*` input array.
230+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
231+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
232+
- **Y**: `[out] double*` output array.
233+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
234+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
235+
236+
```c
237+
void stdlib_strided_dcumaxabs_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
238+
```
239+
240+
</section>
241+
242+
<!-- /.usage -->
243+
244+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
245+
246+
<section class="notes">
247+
248+
</section>
249+
250+
<!-- /.notes -->
251+
252+
<!-- C API usage examples. -->
253+
254+
<section class="examples">
255+
256+
### Examples
257+
258+
```c
259+
#include "stdlib/stats/strided/dcumaxabs.h"
260+
#include <stdio.h>
261+
262+
int main( void ) {
263+
// Create strided arrays:
264+
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
265+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
266+
267+
// Specify the number of elements:
268+
const int N = 4;
269+
270+
// Specify stride lengths:
271+
const int strideX = 2;
272+
const int strideY = -2;
273+
274+
// Compute the cumulative maximum absolute value:
275+
stdlib_strided_dcumaxabs( N, x, strideX, y, strideY );
276+
277+
// Print the result:
278+
for ( int i = 0; i < 8; i++ ) {
279+
printf( "y[ %d ] = %lf\n", i, y[ i ] );
280+
}
281+
}
282+
```
283+
284+
</section>
285+
286+
<!-- /.examples -->
287+
288+
</section>
289+
290+
<!-- /.c -->
291+
292+
<section class="references">
293+
294+
</section>
295+
296+
<!-- /.references -->
297+
298+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
299+
300+
<section class="related">
301+
302+
* * *
303+
304+
## See Also
305+
306+
- <span class="package-name">[`@stdlib/stats/base/cumaxabs`][@stdlib/stats/base/cumaxabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum absolute value of a strided array.</span>
307+
- <span class="package-name">[`@stdlib/stats/strided/dcumax`][@stdlib/stats/strided/dcumax]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum of double-precision floating-point strided array elements.</span>
308+
- <span class="package-name">[`@stdlib/stats/base/dcuminabs`][@stdlib/stats/base/dcuminabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative minimum absolute value of double-precision floating-point strided array elements.</span>
309+
- <span class="package-name">[`@stdlib/stats/base/scumaxabs`][@stdlib/stats/base/scumaxabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum absolute value of single-precision floating-point strided array elements.</span>
310+
311+
</section>
312+
313+
<!-- /.related -->
314+
315+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
316+
317+
<section class="links">
318+
319+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
320+
321+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
322+
323+
<!-- <related-links> -->
324+
325+
[@stdlib/stats/base/cumaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/cumaxabs
326+
327+
[@stdlib/stats/strided/dcumax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dcumax
328+
329+
[@stdlib/stats/base/dcuminabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dcuminabs
330+
331+
[@stdlib/stats/base/scumaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/scumaxabs
332+
333+
<!-- </related-links> -->
334+
335+
</section>
336+
337+
<!-- /.links -->

0 commit comments

Comments
 (0)