Skip to content

Commit 3242006

Browse files
committed
feat: add stats/strided/dmaxabs
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 c45b0ba commit 3242006

33 files changed

+3492
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
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+
# dmaxabs
22+
23+
> Calculate the maximum absolute 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 dmaxabs = require( '@stdlib/stats/strided/dmaxabs' );
37+
```
38+
39+
#### dmaxabs( N, x, strideX )
40+
41+
Computes the maximum absolute 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 = dmaxabs( 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 absolute 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 = dmaxabs( 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 = dmaxabs( 4, x1, 2 );
80+
// returns 4.0
81+
```
82+
83+
#### dmaxabs.ndarray( N, x, strideX, offsetX )
84+
85+
Computes the maximum absolute 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+
92+
var v = dmaxabs.ndarray( x.length, x, 1, 0 );
93+
// returns 2.0
94+
```
95+
96+
The function has the following additional parameters:
97+
98+
- **offsetX**: starting index for `x`.
99+
100+
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 absolute value for every other element in `x` starting from the second element
101+
102+
```javascript
103+
var Float64Array = require( '@stdlib/array/float64' );
104+
105+
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
106+
107+
var v = dmaxabs.ndarray( 4, x, 2, 1 );
108+
// returns 4.0
109+
```
110+
111+
</section>
112+
113+
<!-- /.usage -->
114+
115+
<section class="notes">
116+
117+
## Notes
118+
119+
- If `N <= 0`, both functions return `NaN`.
120+
121+
</section>
122+
123+
<!-- /.notes -->
124+
125+
<section class="examples">
126+
127+
## Examples
128+
129+
<!-- eslint no-undef: "error" -->
130+
131+
```javascript
132+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
133+
var dmaxabs = require( '@stdlib/stats/strided/dmaxabs' );
134+
135+
var x = discreteUniform( 10, -50, 50, {
136+
'dtype': 'float64'
137+
});
138+
console.log( x );
139+
140+
var v = dmaxabs( x.length, x, 1 );
141+
console.log( v );
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- C interface documentation. -->
149+
150+
* * *
151+
152+
<section class="c">
153+
154+
## C APIs
155+
156+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
157+
158+
<section class="intro">
159+
160+
</section>
161+
162+
<!-- /.intro -->
163+
164+
<!-- C usage documentation. -->
165+
166+
<section class="usage">
167+
168+
### Usage
169+
170+
```c
171+
#include "stdlib/stats/strided/dmaxabs.h"
172+
```
173+
174+
#### stdlib_strided_dmaxabs( N, \*X, strideX )
175+
176+
Computes the maximum absolute value of a double-precision floating-point strided array.
177+
178+
```c
179+
const double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0 };
180+
181+
double v = stdlib_strided_dmaxabs( 4, x, 2 );
182+
// returns 7.0
183+
```
184+
185+
The function accepts the following arguments:
186+
187+
- **N**: `[in] CBLAS_INT` number of indexed elements.
188+
- **X**: `[in] double*` input array.
189+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
190+
191+
```c
192+
double stdlib_strided_dmaxabs( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
193+
```
194+
195+
#### stdlib_strided_dmaxabs_ndarray( N, \*X, strideX, offsetX )
196+
197+
Computes the maximum absolute value of a double-precision floating-point strided array using alternative indexing semantics.
198+
199+
```c
200+
const double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0 };
201+
202+
double v = stdlib_strided_dmaxabs_ndarray( 4, x, 2, 0 );
203+
// returns 7.0
204+
```
205+
206+
The function accepts the following arguments:
207+
208+
- **N**: `[in] CBLAS_INT` number of indexed elements.
209+
- **X**: `[in] double*` input array.
210+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
211+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
212+
213+
```c
214+
double stdlib_strided_dmaxabs_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
215+
```
216+
217+
</section>
218+
219+
<!-- /.usage -->
220+
221+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
222+
223+
<section class="notes">
224+
225+
</section>
226+
227+
<!-- /.notes -->
228+
229+
<!-- C API usage examples. -->
230+
231+
<section class="examples">
232+
233+
### Examples
234+
235+
```c
236+
#include "stdlib/stats/strided/dmaxabs.h"
237+
#include <stdio.h>
238+
239+
int main( void ) {
240+
// Create a strided array:
241+
const double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0 };
242+
243+
// Specify the number of elements:
244+
const int N = 4;
245+
246+
// Specify the stride length:
247+
const int strideX = 2;
248+
249+
// Compute the maximum value:
250+
double v = stdlib_strided_dmaxabs( N, x, strideX );
251+
252+
// Print the result:
253+
printf( "maxabs: %lf\n", v );
254+
}
255+
```
256+
257+
</section>
258+
259+
<!-- /.examples -->
260+
261+
</section>
262+
263+
<!-- /.c -->
264+
265+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
266+
267+
<section class="related">
268+
269+
* * *
270+
271+
## See Also
272+
273+
- <span class="package-name">[`@stdlib/stats/strided/dmax`][@stdlib/stats/strided/dmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a double-precision floating-point strided array.</span>
274+
- <span class="package-name">[`@stdlib/stats/base/dminabs`][@stdlib/stats/base/dminabs]</span><span class="delimiter">: </span><span class="description">calculate the minimum absolute value of a double-precision floating-point strided array.</span>
275+
- <span class="package-name">[`@stdlib/stats/base/dnanmaxabs`][@stdlib/stats/base/dnanmaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute value of a double-precision floating-point strided array, ignoring NaN values.</span>
276+
- <span class="package-name">[`@stdlib/stats/base/maxabs`][@stdlib/stats/base/maxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute value of a strided array.</span>
277+
- <span class="package-name">[`@stdlib/stats/base/smaxabs`][@stdlib/stats/base/smaxabs]</span><span class="delimiter">: </span><span class="description">calculate the maximum absolute 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/strided/dmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmax
294+
295+
[@stdlib/stats/base/dminabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dminabs
296+
297+
[@stdlib/stats/base/dnanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dnanmaxabs
298+
299+
[@stdlib/stats/base/maxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/maxabs
300+
301+
[@stdlib/stats/base/smaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/smaxabs
302+
303+
<!-- </related-links> -->
304+
305+
</section>
306+
307+
<!-- /.links -->

0 commit comments

Comments
 (0)