Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
]
},
{
"task": "",
"task": "build",
"wasm": true,
"src": [
"./src/main.c"
Expand Down
316 changes: 316 additions & 0 deletions lib/node_modules/@stdlib/stats/strided/wasm/dmskmaxabs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dmskmaxabs

> Calculate the maximum absolute value of a double-precision floating-point strided array according to a mask.

<section class="usage">

## Usage

```javascript
var dmskmaxabs = require( '@stdlib/stats/strided/wasm/dmskmaxabs' );
```

#### dmskmaxabs.main( N, x, strideX, mask, strideMask )

Computes the maximum absolute value of a double-precision floating-point strided array according to a mask.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );

var x = new Float64Array( [ 1.0, -2.0, 4.0, 2.0 ] );
var mask = new Uint8Array( [ 0, 0, 1, 0 ] );

var v = dmskmaxabs.main( x.length, x, 1, mask, 1 );
// returns 2.0
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **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.
- **strideMask**: stride length for `mask`.

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`,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );

var x = new Float64Array( [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ] );
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );

var v = dmskmaxabs.main( 4, x, 2, mask, 2 );
// returns 7.0
```

Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );

var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );
var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var v = dmskmaxabs.main( 4, x1, 2, mask1, 2 );
// returns 4.0
```

#### dmskmaxabs.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask )

Computes the maximum absolute value of a double-precision floating-point strided array according to a mask using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );

var x = new Float64Array( [ 1.0, -2.0, 4.0, 2.0 ] );
var mask = new Uint8Array( [ 0, 0, 1, 0 ] );

var v = dmskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0 );
// returns 2.0
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetMask**: starting index for `mask`.

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 maximum absolute value for every other element in `x` starting from the second element,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );

var x = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] );

var v = dmskmaxabs.ndarray( 4, x, 2, 1, mask, 2, 1 );
// returns 4.0
```

* * *

### Module

#### dmskmaxabs.Module( memory )

Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory.

<!-- eslint-disable n/no-sync -->

```javascript
var Memory = require( '@stdlib/wasm/memory' );

// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
var mem = new Memory({
'initial': 10,
'maximum': 100
});

// Create a new routine:
var mod = new dmskmaxabs.Module( mem );
// returns <Module>

// Initialize the routine:
mod.initializeSync();
```

#### dmskmaxabs.Module.prototype.main( N, xp, sx, mp, sm )

Computes the maximum absolute value of a double-precision floating-point strided array according to a mask.

<!-- eslint-disable n/no-sync -->

```javascript
var Memory = require( '@stdlib/wasm/memory' );
var oneTo = require( '@stdlib/array/one-to' );
var zeros = require( '@stdlib/array/zeros' );
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );

// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
var mem = new Memory({
'initial': 10,
'maximum': 100
});

// Create a new routine:
var mod = new dmskmaxabs.Module( mem );
// returns <Module>

// Initialize the routine:
mod.initializeSync();

// Specify a vector length:
var N = 5;

// Define pointers (i.e., byte offsets) for storing the input array and mask:
var xptr = 0;
var mptr = N * bytesPerElement( 'float64' );

// Write array values to module memory:
mod.write( xptr, oneTo( N, 'float64' ) );
mod.write( mptr, zeros( N, 'uint8' ) );

// Perform computation:
var v = mod.main( N, xptr, 1, mptr, 1 );
// returns 5.0
```

The function has the following parameters:

- **N**: number of indexed elements.
- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset).
- **sx**: stride length for `x`.
- **mp**: mask [`Uint8Array`][@stdlib/array/uint8] pointer (i.e., byte offset).
- **sm**: stride length for `mask`.

#### dmskmaxabs.Module.prototype.ndarray( N, xp, sx, ox, mp, sm, om )

Computes the maximum absolute value of a double-precision floating-point strided array according to a mask using alternative indexing semantics.

<!-- eslint-disable n/no-sync -->

```javascript
var Memory = require( '@stdlib/wasm/memory' );
var oneTo = require( '@stdlib/array/one-to' );
var zeros = require( '@stdlib/array/zeros' );
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );

// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
var mem = new Memory({
'initial': 10,
'maximum': 100
});

// Create a new routine:
var mod = new dmskmaxabs.Module( mem );
// returns <Module>

// Initialize the routine:
mod.initializeSync();

// Specify a vector length:
var N = 5;

// Define pointers (i.e., byte offsets) for storing the input array and mask:
var xptr = 0;
var mptr = N * bytesPerElement( 'float64' );

// Write array values to module memory:
mod.write( xptr, oneTo( N, 'float64' ) );
mod.write( mptr, zeros( N, 'uint8' ) );

// Perform computation:
var v = mod.ndarray( N, xptr, 1, 0, mptr, 1, 0 );
// returns 5.0
```

The function has the following additional parameters:

- **ox**: starting index for `x`.
- **om**: starting index for `mask`.

</section>

<!-- /.usage -->

<section class="notes">

* * *

## Notes

- If `N <= 0`, both `main` and `ndarray` methods return `NaN`.
- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dmskmaxabs` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/stats/strided/dmskmaxabs`][@stdlib/stats/strided/dmskmaxabs]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/stats/strided/dmskmaxabs`][@stdlib/stats/strided/dmskmaxabs]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other.

</section>

<!-- /.notes -->

<section class="examples">

* * *

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random/array/uniform' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var dmskmaxabs = require( '@stdlib/stats/strided/wasm/dmskmaxabs' );

var x = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
console.log( x );

var mask = bernoulli( x.length, 0.2, {
'dtype': 'uint8'
});
console.log( mask );

var v = dmskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0 );
console.log( v );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64

[@stdlib/array/uint8]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/uint8

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[@stdlib/wasm/memory]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/memory

[@stdlib/wasm/module-wrapper]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/module-wrapper

[@stdlib/stats/strided/dmskmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmskmaxabs

</section>

<!-- /.links -->
Loading