Skip to content

Commit f420a27

Browse files
committed
feat: add stats/strided/dnancumax
--- 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 040efaf commit f420a27

33 files changed

Lines changed: 4382 additions & 0 deletions
Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# dnancumax
24+
25+
> Calculate the cumulative maximum of double-precision floating-point strided array elements, ignoring `NaN` values.
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<section class="usage">
34+
35+
## Usage
36+
37+
```javascript
38+
var dnancumax = require( '@stdlib/stats/strided/dnancumax' );
39+
```
40+
41+
#### dnancumax( N, x, strideX, y, strideY )
42+
43+
Computes the cumulative maximum of double-precision floating-point strided array elements, ignoring `NaN` values.
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
48+
var x = new Float64Array( [ 1.0, NaN, 2.0 ] );
49+
var y = new Float64Array( x.length );
50+
51+
dnancumax( x.length, x, 1, y, 1 );
52+
// y => <Float64Array>[ 1.0, 1.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 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, NaN, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
69+
var y = new Float64Array( x.length );
70+
71+
var v = dnancumax( 4, x, 2, y, 1 );
72+
// y => <Float64Array>[ 1.0, 1.0, 1.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, NaN, 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+
dnancumax( 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+
#### dnancumax.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
95+
96+
Computes the cumulative maximum of double-precision floating-point strided array elements, ignoring `NaN` values, using alternative indexing semantics.
97+
98+
```javascript
99+
var Float64Array = require( '@stdlib/array/float64' );
100+
101+
var x = new Float64Array( [ 1.0, NaN, 2.0 ] );
102+
var y = new Float64Array( x.length );
103+
104+
dnancumax.ndarray( x.length, x, 1, 0, y, 1, 0 );
105+
// y => <Float64Array>[ 1.0, 1.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 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, NaN, -2.0, 2.0, 3.0, 4.0 ] );
119+
var y = new Float64Array( x.length );
120+
121+
dnancumax.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, 1.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 dnancumax = require( '@stdlib/stats/strided/dnancumax' );
149+
150+
var x = discreteUniform( 10, -50, 50, {
151+
'dtype': 'float64'
152+
});
153+
x[ 3 ] = NaN;
154+
x[ 7 ] = NaN;
155+
console.log( x );
156+
157+
var y = new Float64Array( x.length );
158+
console.log( y );
159+
160+
dnancumax( x.length, x, 1, y, -1 );
161+
console.log( y );
162+
```
163+
164+
</section>
165+
166+
<!-- /.examples -->
167+
168+
<!-- C interface documentation. -->
169+
170+
* * *
171+
172+
<section class="c">
173+
174+
## C APIs
175+
176+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
177+
178+
<section class="intro">
179+
180+
</section>
181+
182+
<!-- /.intro -->
183+
184+
<!-- C usage documentation. -->
185+
186+
<section class="usage">
187+
188+
### Usage
189+
190+
```c
191+
#include "stdlib/stats/strided/dnancumax.h"
192+
```
193+
194+
#### stdlib_strided_dnancumax( N, \*X, strideX, \*Y, strideY )
195+
196+
Computes the cumulative maximum of double-precision floating-point strided array elements, ignoring `NaN` values.
197+
198+
```c
199+
const double x[] = { 1.0, 2.0, -3.0, 4.0, 0.0/0.0, 6.0, 7.0, 8.0 };
200+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
201+
202+
stdlib_strided_dnancumax( 4, x, 2, y, -2 );
203+
```
204+
205+
The function accepts the following arguments:
206+
207+
- **N**: `[in] CBLAS_INT` number of indexed elements.
208+
- **X**: `[in] double*` input array.
209+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
210+
- **Y**: `[out] double*` output array.
211+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
212+
213+
```c
214+
void stdlib_strided_dnancumax( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
215+
```
216+
217+
#### stdlib_strided_dnancumax_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY )
218+
219+
Computes the cumulative maximum of double-precision floating-point strided array elements, ignoring `NaN` values, using alternative indexing semantics.
220+
221+
```c
222+
const double x[] = { 1.0, 2.0, -3.0, 4.0, 0.0/0.0, 6.0, 7.0, 8.0 };
223+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
224+
225+
stdlib_strided_dnancumax_ndarray( 4, x, 2, 0, y, -2, 0 );
226+
```
227+
228+
The function accepts the following arguments:
229+
230+
- **N**: `[in] CBLAS_INT` number of indexed elements.
231+
- **X**: `[in] double*` input array.
232+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
233+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
234+
- **Y**: `[out] double*` output array.
235+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
236+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
237+
238+
```c
239+
void stdlib_strided_dnancumax_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 );
240+
```
241+
242+
</section>
243+
244+
<!-- /.usage -->
245+
246+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
247+
248+
<section class="notes">
249+
250+
</section>
251+
252+
<!-- /.notes -->
253+
254+
<!-- C API usage examples. -->
255+
256+
<section class="examples">
257+
258+
### Examples
259+
260+
```c
261+
#include "stdlib/stats/strided/dnancumax.h"
262+
#include <stdio.h>
263+
264+
int main( void ) {
265+
// Create strided arrays:
266+
const double x[] = { 1.0, 2.0, -3.0, 4.0, 0.0/0.0, 6.0, 7.0, 8.0 };
267+
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
268+
269+
// Specify the number of elements:
270+
const int N = 4;
271+
272+
// Specify stride lengths:
273+
const int strideX = 2;
274+
const int strideY = -2;
275+
276+
// Compute the cumulative maximum:
277+
stdlib_strided_dnancumax( N, x, strideX, y, strideY );
278+
279+
// Print the result:
280+
for ( int i = 0; i < 8; i++ ) {
281+
printf( "y[ %d ] = %lf\n", i, y[ i ] );
282+
}
283+
}
284+
```
285+
286+
</section>
287+
288+
<!-- /.examples -->
289+
290+
</section>
291+
292+
<!-- /.c -->
293+
294+
<section class="references">
295+
296+
</section>
297+
298+
<!-- /.references -->
299+
300+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
301+
302+
<section class="related">
303+
304+
</section>
305+
306+
<!-- /.related -->
307+
308+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
309+
310+
<section class="links">
311+
312+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
313+
314+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
315+
316+
<!-- <related-links> -->
317+
318+
<!-- </related-links> -->
319+
320+
</section>
321+
322+
<!-- /.links -->

0 commit comments

Comments
 (0)