Skip to content

chore: minor cleanup in stats/strided/dcovarmtk #7651

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/stats/strided/dcovarmtk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ The `N` and stride parameters determine which elements in the strided arrays are
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
var y = new Float64Array( [ -7.0, 2.0, 2.0, 1.0, -2.0, 2.0, 3.0, 4.0 ] );
var y = new Float64Array( [ 2.0, 1.0, 2.0, 1.0, -2.0, 2.0, 3.0, 4.0 ] );
Copy link
Member

Choose a reason for hiding this comment

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

@gururaj1512 Are you sure about this change?

Copy link
Member Author

@gururaj1512 gururaj1512 Jul 14, 2025

Choose a reason for hiding this comment

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

For previous array the mean of accessed elements was -1.0.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this example is off. Your proposed changes ensure a mean of 1.25; however, the covariance is no longer 6 based on my hand calculation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Appologies! this returns 5.25.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also why didn't a lint error occured here?


var v = dcovarmtk( 4, 1, 1.25, x, 2, 1.25, y, 2 );
// returns 6.0
// returns 5.25
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
Expand Down Expand Up @@ -342,7 +342,7 @@ int main( void ) {
const int strideX = 2;

// Compute the covariance of `x` with itself:
double v = stdlib_strided_dcovarmtk( N, 1, 4.5, x, strideX, 4.5, x, -strideX );
double v = stdlib_strided_dcovarmtk( N, 1.0, 4.5, x, strideX, 4.5, x, -strideX );

// Print the result:
printf( "covariance: %lf\n", v );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{{alias}}( N, correction, meanx, x, strideX, meany, y, strideY )
{{alias}}( N, correction, meanx, x, sx, meany, y, sy )
Computes the covariance of two double-precision floating-point strided
arrays provided known means and using a one-pass textbook algorithm.

Expand Down Expand Up @@ -34,7 +34,7 @@
x: Float64Array
First input array.

strideX: integer
sx: integer
Stride length of `x`.

meany: number
Expand All @@ -43,7 +43,7 @@
y: Float64Array
Second input array.

strideY: integer
sy: integer
Stride length of `y`.

Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import dcovarmtk = require( './index' );
dcovarmtk( undefined, 1, 0.0, x, 1, 0.0, x, 1 ); // $ExpectError
dcovarmtk( [], 1, 0.0, x, 1, 0.0, x, 1 ); // $ExpectError
dcovarmtk( {}, 1, 0.0, x, 1, 0.0, x, 1 ); // $ExpectError
dcovarmtk( ( x: number ): number => x, 1, 0.0, x, 1, 0.0, x, 1, 0.0, x, 1 ); // $ExpectError
dcovarmtk( ( x: number ): number => x, 1, 0.0, x, 1, 0.0, x, 1 ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a number...
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/stats/strided/dcovarmtk/src/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ static napi_value addon( napi_env env, napi_callback_info info ) {
STDLIB_NAPI_ARGV_DOUBLE( env, meany, argv, 5 );
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 4 );
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 7 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 )
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 6 )
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 );
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 6 );
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dcovarmtk)( N, correction, meanx, X, strideX, meany, Y, strideY ), v );
return v;
}
Expand Down