Skip to content

Commit 1eee6f5

Browse files
aayush0325kgryte
authored andcommitted
feat: add stats/strided/dcumax
Ref: #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 7a0ea1d commit 1eee6f5

33 files changed

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

0 commit comments

Comments
 (0)