Skip to content
Closed
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
109 changes: 109 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dmeanvarpn/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also missing changes in the JavaScript docs regarding removing the usage of math/base/special/floor in examples

Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,115 @@ console.log( out );

<!-- /.examples -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

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

#### stdlib_strided_dmeanvarpn( N, correction, \*X, strideX, \*Out, strideOut )

Computes the [mean][arithmetic-mean] and [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm.

```c
double x[] ={ 1.0, -2.0, 2.0 };
double out[2];
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );
// Out = [ ~0.3333, ~4.3333 ]
Comment on lines +257 to +260
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double x[] ={ 1.0, -2.0, 2.0 };
double out[2];
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );
// Out = [ ~0.3333, ~4.3333 ]
const double x[] ={ 1.0, -2.0, 2.0 };
double out[] = { 0.0, 0.0 };
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );

```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **correction**: `[in] double` degrees of freedom adjustment.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[in] double*` Output array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Out**: `[in] double*` Output array.
- **Out**: `[out] double*` Output array.

- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.

```c
double stdlib_strided_dmeanvarpn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT strideOut );
```

#### stdlib_strided_dmeanvarpn_ndarray( N, correction, \*X, strideX, offsetX, \*Out, strideOut, offsetOut )

Computes the [mean][arithmetic-mean] and [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.

```c
const double x[] = { 1.0, -2.0, 2.0 };

stdlib_strided_dmeanvarpn_ndarray( x.length, 1, x, 1, 0, out, 1, 0 );
// Out = [ ~0.3333, ~4.3333 ]
Comment on lines +281 to +284
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no declaration for Out here

```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **correction**: `[in] double` degrees of freedom adjustment.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` `X` starting index.
- **Out**: `[in] double*` Output array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Out**: `[in] double*` Output array.
- **Out**: `[out] double*` Output array.

- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
- **offsetOut**: `[in] CBLAS_INT` `Out` starting index.

```c
double stdlib_strided_dmeankbn2_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
```

</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/dmeanvarpn.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
const double x[] = { 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 };

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

// Specify the stride length:
const CBLAS_INT strideX = 2;

// Compute the arithmetic mean:
stdlib_strided_dmeanvarpn_ndarray( N, 1, x, 2, 1, out, 1, 0 );

// Print the result:
printf( "sample mean: %lf\n", out[ 0 ] );
printf( "sample variance: %lf\n", out[ 1 ] );
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

* * *

<section class="references">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
// 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 dmeanvarpn = require( './../lib/dmeanvarpn.js' );


// VARIABLES //

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


// FUNCTIONS //

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

x = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
out = new Float64Array( 2 );
var out = uniform( 2, 0.0, 0.0, options );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var out = uniform( 2, 0.0, 0.0, options );
var out = new Float64Array( 2 );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment for all other JS benchmarks

var x = uniform( len, -10.0, 10.0, options );
return benchmark;

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

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' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +35,9 @@ var dmeanvarpn = tryRequire( resolve( __dirname, './../lib/dmeanvarpn.native.js'
var opts = {
'skip': ( dmeanvarpn instanceof Error )
};
var options = {
'dtype': 'float64'
};


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

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

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
// 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 dmeanvarpn = require( './../lib/ndarray.js' );


// VARIABLES //

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


// FUNCTIONS //

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

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

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

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' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +35,9 @@ var dmeanvarpn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' )
var opts = {
'skip': ( dmeanvarpn instanceof Error )
};
var options = {
'dtype': 'float64'
};


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

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

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static double rand_double( void ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
static double benchmark1( int iterations, int len ) {
double elapsed;
double out[ 2 ];
double x[ len ];
Expand All @@ -109,6 +109,7 @@ static double benchmark( int iterations, int len ) {

t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
stdlib_strided_dmeanvarpn( len, 1, x, 1, out, 1 );
if ( out[ i%2 ] != out[ i%2 ] ) {
printf( "should not return NaN\n" );
Expand All @@ -122,6 +123,42 @@ static double benchmark( int iterations, int len ) {
return elapsed;
}

/**
* Runs a benchmark.
*
* @param iterations number of iterations
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark2( int iterations, int len ) {
double elapsed;
double out[ 2 ];
double x[ len ];
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
}
out[ 0 ] = 0.0;
out[ 1 ] = 0.0;

t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
stdlib_strided_dmeanvarpn_ndarray( len, 1, x, 1, 0, out, 1, 0 );
if ( out[ i%2 ] != out[ i%2 ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( out[ i%2 ] != out[ i%2 ] ) {
printf( "should not return NaN\n" );
}
return elapsed;
}

/**
* Main execution sequence.
*/
Expand All @@ -144,7 +181,18 @@ int main( void ) {
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:len=%d\n", NAME, len );
elapsed = benchmark( iter, len );
elapsed = benchmark1( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
}
for ( i = MIN; i <= MAX; i++ ) {
len = pow( 10, i );
iter = ITERATIONS / pow( 10, i-1 );
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
elapsed = benchmark2( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
Expand Down
Loading
Loading