Skip to content

Commit cefdce4

Browse files
kgrytesaurabhraghuvanshii
authored andcommitted
feat: add stats/strided/dmax
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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 f705eb2 commit cefdce4

33 files changed

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

0 commit comments

Comments
 (0)