Skip to content

Commit

Permalink
refactor: refactored stats/base/dmeanvarpn
Browse files Browse the repository at this point in the history
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: passed
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
  • Loading branch information
DhruvArvindSingh committed Jan 13, 2025
1 parent a0e7465 commit 33e74d7
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 161 deletions.
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 );
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
21 changes: 10 additions & 11 deletions lib/node_modules/@stdlib/stats/base/dmeanvarpn/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Computes the mean and variance of a double-precision floating-point strided
array using a two-pass algorithm.

The `N` and `stride` parameters determine which elements are accessed at
The `N` and stride parameters determine which elements are accessed at
runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
Expand Down Expand Up @@ -32,13 +32,13 @@
Input array.

strideX: integer
Index increment for `x`.
Stride Lenght for `x`.

out: Float64Array
Output array.

strideOut: integer
Index increment for `out`.
Stride Lenght for `out`.

Returns
-------
Expand All @@ -53,27 +53,26 @@
> {{alias}}( x.length, 1, x, 1, out, 1 )
<Float64Array>[ ~0.3333, ~4.3333 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
> out = new {{alias:@stdlib/array/float64}}( 2 );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, 1, x, 2, out, 1 )
> {{alias}}( 3, 1, x, 2, out, 1 )
<Float64Array>[ ~0.3333, ~4.3333 ]

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> out = new {{alias:@stdlib/array/float64}}( 2 );
> {{alias}}( N, 1, x1, 2, out, 1 )
> {{alias}}( 3, 1, x1, 2, out, 1 )
<Float64Array>[ ~0.3333, ~4.3333 ]


{{alias}}.ndarray( N, c, x, strideX, offsetX, out, strideOut, offsetOut )
Computes the mean and variance of a double-precision floating-point strided
array using a two-pass algorithm and alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameter supports indexing semantics based on a
buffer, the offset parameter supports indexing semantics based on a
starting index.

Parameters
Expand All @@ -97,7 +96,7 @@
Input array.

strideX: integer
Index increment for `x`.
Stride Length for `x`.

offsetX: integer
Starting index for `x`.
Expand All @@ -106,7 +105,7 @@
Output array.

strideOut: integer
Index increment for `out`.
Stride Length for `out`.

offsetOut: integer
Starting index for `out`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ interface Routine {
* @param N - number of indexed elements
* @param correction - degrees of freedom adjustment
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param out - output array
* @param strideOut - `out` stride length
* @param strideOut - stride length for `out`
* @returns output array
*
* @example
Expand All @@ -50,11 +50,11 @@ interface Routine {
* @param N - number of indexed elements
* @param correction - degrees of freedom adjustment
* @param x - input array
* @param strideX - `x` stride length
* @param offsetX - `x` starting index
* @param strideX - stride length for `x`
* @param offsetX - starting index for `x`
* @param out - output array
* @param strideOut - `out` stride length
* @param offsetOut - `out` starting index
* @param strideOut - stride length for `out`
* @param offsetOut - starting index for `out`
* @returns output array
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
*/

#include "stdlib/stats/base/dmeanvarpn.h"
#include <stdint.h>
#include <stdio.h>

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

// Create an output array:
double out[] = { 0.0, 0.0 };

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

// Specify the stride lengths:
int64_t strideX = 2;
int64_t strideOut = 1;
int strideX = 2;
int strideOut = 1;

// Compute the mean and variance:
stdlib_strided_dmeanvarpn( N, 1, x, strideX, out, strideOut );
Expand Down
19 changes: 7 additions & 12 deletions lib/node_modules/@stdlib/stats/base/dmeanvarpn/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var dmeanvarpn = require( './../lib' );

var out;
var x;
var i;

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

out = new Float64Array( 2 );
var out = discreteUniform( 10, 0, 0, {
'dtype': 'float64'
});
dmeanvarpn( x.length, 1, x, 1, out, 1 );
console.log( out );
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
*/
void API_SUFFIX( stdlib_strided_dmeanvarpn )( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT strideOut );
/**
* Computes the mean and variance of a double-precision floating-point strided array using a two-pass algorithm.
* Computes the mean and variance of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
*/
void API_SUFFIX( stdlib_strided_dmeanvarpn_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 );

Expand Down
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/stats/base/dmeanvarpn/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
* var dmeanvarpn = require( '@stdlib/stats/base/dmeanvarpn' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dmeanvarpn.ndarray( N, 1, x, 2, 1, out, 1, 0 );
* var v = dmeanvarpn.ndarray( 4, 1, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 1.25, 6.25 ]
*/

Expand Down
7 changes: 2 additions & 5 deletions lib/node_modules/@stdlib/stats/base/dmeanvarpn/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var dsumpw = require( '@stdlib/blas/ext/base/dsumpw' ).ndarray;
// MAIN //

/**
* Computes the mean and variance of a double-precision floating-point strided array using a two-pass algorithm.
* Computes the mean and variance of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
*
* ## Method
*
Expand All @@ -50,14 +50,11 @@ var dsumpw = require( '@stdlib/blas/ext/base/dsumpw' ).ndarray;
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dmeanvarpn( N, 1, x, 2, 1, out, 1, 0 );
* var v = dmeanvarpn( 4, 1, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 1.25, 6.25 ]
*/
function dmeanvarpn( N, correction, x, strideX, offsetX, out, strideOut, offsetOut ) { // eslint-disable-line max-len
Expand Down
Loading

0 comments on commit 33e74d7

Please sign in to comment.