Skip to content

Commit

Permalink
refactor: refactored benchmarks, tests and docs
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: passed
  - 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: passed
  - 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 5e74a4e commit 05492cd
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 202 deletions.
50 changes: 16 additions & 34 deletions lib/node_modules/@stdlib/stats/base/sdsnanmeanors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as
var sdsnanmeanors = require( '@stdlib/stats/base/sdsnanmeanors' );
```

#### sdsnanmeanors( N, x, stride )
#### sdsnanmeanors( N, x, strideX )

Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x`, ignoring `NaN` values and using ordinary recursive summation with extended accumulation.

Expand All @@ -69,18 +69,16 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Float32Array`][@stdlib/array/float32].
- **stride**: index increment for `x`.
- **strideX**: index increment for `x`.

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] );
var N = floor( x.length / 2 );

var v = sdsnanmeanors( N, x, 2 );
var v = sdsnanmeanors( 4, x, 2 );
// returns 1.25
```

Expand All @@ -90,45 +88,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

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

var N = floor( x0.length / 2 );

var v = sdsnanmeanors( N, x1, 2 );
var v = sdsnanmeanors( 4, x1, 2 );
// returns 1.25
```

#### sdsnanmeanors.ndarray( N, x, stride, offset )
#### sdsnanmeanors.ndarray( N, x, strideX, offsetX )

Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
var N = x.length;

var v = sdsnanmeanors.ndarray( N, x, 1, 0 );
var v = sdsnanmeanors.ndarray( x.length, x, 1, 0 );
// returns ~0.33333
```

The function has the following additional parameters:

- **offset**: starting index for `x`.
- **offsetX**: starting index for `x`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [arithmetic mean][arithmetic-mean] for every other element in `x` starting from the second element

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
var N = floor( x.length / 2 );

var v = sdsnanmeanors.ndarray( N, x, 2, 1 );
var v = sdsnanmeanors.ndarray( 4, x, 2, 1 );
// returns 1.25
```

Expand All @@ -155,22 +147,12 @@ var v = sdsnanmeanors.ndarray( N, x, 2, 1 );
<!-- eslint no-undef: "error" -->

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

var x;
var i;

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

var v = sdsnanmeanors( x.length, x, 1 );
Expand Down Expand Up @@ -198,7 +180,7 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p
```c
const float x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };

double v = stdlib_strided_sdsnanmeanors( 4, x, 1 );
double v = stdlib_strided_sdsnanmeanors( x.length, x, 1 );
// returns ~0.3333
```
Expand All @@ -219,7 +201,7 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p
```c
const float x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };

double v = stdlib_strided_sdsnanmeanors_ndarray( 4, x, 1, 0 );
double v = stdlib_strided_sdsnanmeanors_ndarray( x.length, x, 1, 0 );
// returns ~0.3333
```
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sdsnanmeanors = require( './../lib/sdsnanmeanors.js' );


// VARIABLES //

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


// FUNCTIONS //

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

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
}
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

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


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

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
}
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sdsnanmeanors = require( './../lib/ndarray.js' );


// VARIABLES //

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


// FUNCTIONS //

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

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
}
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

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


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

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

function benchmark( b ) {
Expand Down
32 changes: 14 additions & 18 deletions lib/node_modules/@stdlib/stats/base/sdsnanmeanors/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

{{alias}}( N, x, stride )
{{alias}}( N, x, strideX )
Computes the arithmetic mean of a single-precision floating-point strided
array, ignoring `NaN` values and using ordinary recursive summation with
extended accumulation.

The `N` and `stride` parameters determine which elements in `x` are accessed
at runtime.
The `N` and stride parameters determine which elements in the strided array
are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
array view.
Expand All @@ -22,8 +22,8 @@
x: Float32Array
Input array.

stride: integer
Index increment.
strideX: integer
Stride Length.

Returns
-------
Expand All @@ -37,22 +37,19 @@
> {{alias}}( x.length, x, 1 )
~0.3333

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

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

{{alias}}.ndarray( N, x, stride, offset )

{{alias}}.ndarray( N, x, strideX, offsetX )
Computes the arithmetic mean of a single-precision floating-point strided
array, ignoring `NaN` values and using ordinary recursive summation with
extended accumulation and alternative indexing semantics.
Expand All @@ -69,10 +66,10 @@
x: Float32Array
Input array.

stride: integer
Index increment.
strideX: integer
Stride Length.

offset: integer
offsetX: integer
Starting index.

Returns
Expand All @@ -89,8 +86,7 @@

// Using offset parameter:
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, x, 2, 1 )
> {{alias}}.ndarray( 3, x, 2, 1 )
~-0.3333

See Also
Expand Down
Loading

0 comments on commit 05492cd

Please sign in to comment.