Skip to content

Commit 8ae9939

Browse files
Sachinn-64kgrytestdlib-bot
authored
feat: add stats/strided/dmskmaxabs
PR-URL: #9743 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <noreply@stdlib.io>
1 parent b1c1ac0 commit 8ae9939

33 files changed

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

0 commit comments

Comments
 (0)