Skip to content

feat: add C ndarray interface and refactor implementation for stats/base/dcumin #4144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 3, 2025
Merged
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
151 changes: 136 additions & 15 deletions lib/node_modules/@stdlib/stats/base/dcumin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: index increment for `x`.
- **strideX**: stride length for `x`.
- **y**: output [`Float64Array`][@stdlib/array/float64].
- **strideY**: index increment for `y`.
- **strideY**: stride length for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down Expand Up @@ -108,7 +108,7 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element
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 cumulative minimum 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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down Expand Up @@ -141,21 +141,16 @@ dcumin.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var dcumin = require( '@stdlib/stats/base/dcumin' );

var y;
var x;
var i;

x = new Float64Array( 10 );
y = new Float64Array( x.length );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
}
var x = discreteUniform( 10, -50, 50, {
'dtype': 'float64'
});
console.log( x );

var y = new Float64Array( x.length );
console.log( y );

dcumin( x.length, x, 1, y, -1 );
Expand All @@ -166,6 +161,132 @@ console.log( y );

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/stats/base/dcumin.h"
```

#### stdlib_strided_dcumin( N, \*X, strideX, \*Y, strideY )

Computes the cumulative minimum of double-precision floating-point strided array elements.

```c
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_dcumin( 4, x, 2, y, -2 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Y**: `[out] double*` output array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.

```c
void stdlib_strided_dcumin( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
```

#### stdlib_strided_dcumin_ndarray(N, \*X, strideX, offsetX, \*Y, strideY, offsetY )

Computes the cumulative minimum of double-precision floating-point strided array elements using alternative indexing semantics.

```c
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_dcumin_ndarray( 4, x, 2, 0, y, -2, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[out] double*` output array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.

```c
void stdlib_strided_dcumin_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 );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/stats/base/dcumin.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
const double x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

// Specify the number of elements:
const int N = 4;

// Specify stride lengths:
const int strideX = 2;
const int strideY = -2;

// Compute the cumulative minimum:
stdlib_strided_dcumin( N, x, strideX, y, strideY );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "y[ %d ] = %lf\n", i, y[ i ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<section class="references">

</section>
Expand Down
20 changes: 10 additions & 10 deletions lib/node_modules/@stdlib/stats/base/dcumin/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dcumin = require( './../lib/dcumin.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
Expand All @@ -39,15 +46,8 @@ var dcumin = require( './../lib/dcumin.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var y;
var x;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = uniform( len, -10.0, 10.0, options );
var y = new Float64Array( len );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -36,6 +36,9 @@ var dcumin = tryRequire( resolve( __dirname, './../lib/dcumin.native.js' ) );
var opts = {
'skip': ( dcumin instanceof Error )
};
var options = {
'dtype': 'float64'
};


// FUNCTIONS //
Expand All @@ -48,15 +51,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = uniform( len, -10.0, 10.0, options );
var y = new Float64Array( len );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dcumin = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
Expand All @@ -39,15 +46,8 @@ var dcumin = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = uniform( len, -10.0, 10.0, options );
var y = new Float64Array( len );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -36,6 +36,9 @@ var dcumin = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( dcumin instanceof Error )
};
var options = {
'dtype': 'float64'
};


// FUNCTIONS //
Expand All @@ -48,15 +51,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = uniform( len, -10.0, 10.0, options );
var y = new Float64Array( len );
return benchmark;

function benchmark( b ) {
Expand Down
Loading
Loading