-
-
Notifications
You must be signed in to change notification settings - Fork 881
feat: add C ndarray
implementation for stats/base/dmeanvarpn
#4720
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
Changes from all commits
d5fe50e
b6ab880
a0e7465
33e74d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
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. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
- **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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no declaration for |
||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
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. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
- **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"> | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 // | ||||||
|
||||||
/** | ||||||
|
@@ -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 ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) { | ||||||
|
There was a problem hiding this comment.
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