Skip to content

Commit 542edd4

Browse files
feat: ndarray-dnanstdev
1 parent 8785e54 commit 542edd4

File tree

15 files changed

+180
-361
lines changed

15 files changed

+180
-361
lines changed

lib/node_modules/@stdlib/stats/base/dnanstdev/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Source files:
3838
'src_files': [
39-
'<(src_dir)/addon.cpp',
39+
'<(src_dir)/addon.c',
4040
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
4141
],
4242

lib/node_modules/@stdlib/stats/base/dnanstdev/include/stdlib/stats/base/dnanstdev.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_DNANSTDEV_H
2020
#define STDLIB_STATS_BASE_DNANSTDEV_H
2121

22-
#include <stdint.h>
22+
#include "stdlib/blas/base/shared.h"
2323

2424
/*
2525
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
@@ -31,7 +31,12 @@ extern "C" {
3131
/**
3232
* Computes the standard deviation of a double-precision floating-point strided array ignoring `NaN` values.
3333
*/
34-
double stdlib_strided_dnanstdev( const int64_t N, const double correction, const double *X, const int64_t stride );
34+
double API_SUFFIX(stdlib_strided_dnanstdev)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX );
35+
36+
/**
37+
* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics .
38+
*/
39+
double API_SUFFIX(stdlib_strided_dnanstdev_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
3540

3641
#ifdef __cplusplus
3742
}

lib/node_modules/@stdlib/stats/base/dnanstdev/lib/dnanstdev.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

23-
var dnanstdevpn = require( '@stdlib/stats/base/dnanstdevpn' );
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
24+
var ndarray = require( './ndarray.js' );
2425

2526

2627
// MAIN //
@@ -31,7 +32,7 @@ var dnanstdevpn = require( '@stdlib/stats/base/dnanstdevpn' );
3132
* @param {PositiveInteger} N - number of indexed elements
3233
* @param {number} correction - degrees of freedom adjustment
3334
* @param {Float64Array} x - input array
34-
* @param {integer} stride - stride length
35+
* @param {integer} strideX - stride length
3536
* @returns {number} standard deviation
3637
*
3738
* @example
@@ -40,11 +41,11 @@ var dnanstdevpn = require( '@stdlib/stats/base/dnanstdevpn' );
4041
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
4142
* var N = x.length;
4243
*
43-
* var v = dnanstdev( N, 1, x, 1 );
44+
* var v = dnanstdev( x.length, 1, x, 1 );
4445
* // returns ~2.0817
4546
*/
46-
function dnanstdev( N, correction, x, stride ) {
47-
return dnanstdevpn( N, correction, x, stride );
47+
function dnanstdev( N, correction, x, strideX ) {
48+
return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) );
4849
}
4950

5051

lib/node_modules/@stdlib/stats/base/dnanstdev/lib/dnanstdev.native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' );
3131
* @param {PositiveInteger} N - number of indexed elements
3232
* @param {number} correction - degrees of freedom adjustment
3333
* @param {Float64Array} x - input array
34-
* @param {integer} stride - stride length
34+
* @param {integer} strideX - stride length
3535
* @returns {number} standard deviation
3636
*
3737
* @example
@@ -40,11 +40,11 @@ var addon = require( './../src/addon.node' );
4040
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
4141
* var N = x.length;
4242
*
43-
* var v = dnanstdev( N, 1, x, 1 );
43+
* var v = dnanstdev( x.length, 1, x, 1 );
4444
* // returns ~2.0817
4545
*/
46-
function dnanstdev( N, correction, x, stride ) {
47-
return addon( N, correction, x, stride );
46+
function dnanstdev( N, correction, x, strideX ) {
47+
return addon( N, correction, x, strideX );
4848
}
4949

5050

lib/node_modules/@stdlib/stats/base/dnanstdev/lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@
3030
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
3131
* var N = x.length;
3232
*
33-
* var v = dnanstdev( N, 1, x, 1 );
33+
* var v = dnanstdev( x.length, 1, x, 1 );
3434
* // returns ~2.0817
3535
*
3636
* @example
3737
* var Float64Array = require( '@stdlib/array/float64' );
38-
* var floor = require( '@stdlib/math/base/special/floor' );
3938
* var dnanstdev = require( '@stdlib/stats/base/dnanstdev' );
4039
*
4140
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
42-
* var N = floor( x.length / 2 );
4341
*
44-
* var v = dnanstdev.ndarray( N, 1, x, 2, 1 );
42+
* var v = dnanstdev.ndarray( 5, 1, x, 2, 1 );
4543
* // returns 2.5
4644
*/
4745

lib/node_modules/@stdlib/stats/base/dnanstdev/lib/ndarray.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ var dnanstdevpn = require( '@stdlib/stats/base/dnanstdevpn' ).ndarray;
3131
* @param {PositiveInteger} N - number of indexed elements
3232
* @param {number} correction - degrees of freedom adjustment
3333
* @param {Float64Array} x - input array
34-
* @param {integer} stride - stride length
35-
* @param {NonNegativeInteger} offset - starting index
34+
* @param {integer} strideX - stride length
35+
* @param {NonNegativeInteger} offsetX - starting index
3636
* @returns {number} standard deviation
3737
*
3838
* @example
3939
* var Float64Array = require( '@stdlib/array/float64' );
40-
* var floor = require( '@stdlib/math/base/special/floor' );
4140
*
4241
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
43-
* var N = floor( x.length / 2 );
4442
*
45-
* var v = dnanstdev( N, 1, x, 2, 1 );
43+
* var v = dnanstdev( 5, 1, x, 2, 1 );
4644
* // returns 2.5
4745
*/
48-
function dnanstdev( N, correction, x, stride, offset ) {
49-
return dnanstdevpn( N, correction, x, stride, offset );
46+
function dnanstdev( N, correction, x, strideX, offsetX ) {
47+
return dnanstdevpn( N, correction, x, strideX, offsetX );
5048
}
5149

5250

lib/node_modules/@stdlib/stats/base/dnanstdev/lib/ndarray.native.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
// MODULES //
2222

23-
var Float64Array = require( '@stdlib/array/float64' );
24-
var addon = require( './dnanstdev.native.js' );
23+
var addon = require( './../src/addon.node' );
2524

2625

2726
// MAIN //
@@ -32,27 +31,20 @@ var addon = require( './dnanstdev.native.js' );
3231
* @param {PositiveInteger} N - number of indexed elements
3332
* @param {number} correction - degrees of freedom adjustment
3433
* @param {Float64Array} x - input array
35-
* @param {integer} stride - stride length
36-
* @param {NonNegativeInteger} offset - starting index
34+
* @param {integer} strideX - stride length
35+
* @param {NonNegativeInteger} offsetX - starting index
3736
* @returns {number} standard deviation
3837
*
3938
* @example
4039
* var Float64Array = require( '@stdlib/array/float64' );
41-
* var floor = require( '@stdlib/math/base/special/floor' );
4240
*
4341
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
44-
* var N = floor( x.length / 2 );
4542
*
46-
* var v = dnanstdev( N, 1, x, 2, 1 );
43+
* var v = dnanstdev( 5, 1, x, 2, 1 );
4744
* // returns 2.5
4845
*/
49-
function dnanstdev( N, correction, x, stride, offset ) {
50-
var view;
51-
if ( stride < 0 ) {
52-
offset += (N-1) * stride;
53-
}
54-
view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
55-
return addon( N, correction, view, stride );
46+
function dnanstdev( N, correction, x, strideX, offsetX ) {
47+
return addon.ndarray( N, correction, x, strideX, offsetX );
5648
}
5749

5850

lib/node_modules/@stdlib/stats/base/dnanstdev/manifest.json

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"options": {},
2+
"options": {
3+
"task": "build",
4+
"wasm": false
5+
},
36
"fields": [
47
{
58
"field": "src",
@@ -24,18 +27,75 @@
2427
],
2528
"confs": [
2629
{
30+
"task": "build",
31+
"wasm": false,
2732
"src": [
28-
"./src/dnanstdev.c"
33+
"./src/main.c"
2934
],
3035
"include": [
3136
"./include"
3237
],
33-
"libraries": [
34-
"-lm"
38+
"libraries": [],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/blas/base/shared",
42+
"@stdlib/strided/base/stride2offset",
43+
"@stdlib/napi/export",
44+
"@stdlib/napi/argv",
45+
"@stdlib/napi/argv-int64",
46+
"@stdlib/napi/argv-strided-float64array",
47+
"@stdlib/napi/create-double"
48+
]
49+
},
50+
{
51+
"task": "benchmark",
52+
"wasm": false,
53+
"src": [
54+
"./src/main.c"
55+
],
56+
"include": [
57+
"./include"
58+
],
59+
"libraries": [],
60+
"libpath": [],
61+
"dependencies": [
62+
"@stdlib/stats/base/dnanstdevpn",
63+
"@stdlib/blas/base/shared",
64+
"@stdlib/strided/base/stride2offset"
65+
]
66+
},
67+
{
68+
"task": "examples",
69+
"wasm": false,
70+
"src": [
71+
"./src/main.c"
72+
],
73+
"include": [
74+
"./include"
75+
],
76+
"libraries": [],
77+
"libpath": [],
78+
"dependencies": [
79+
"@stdlib/stats/base/dnanstdevpn",
80+
"@stdlib/blas/base/shared",
81+
"@stdlib/strided/base/stride2offset"
82+
]
83+
},
84+
{
85+
"task": "",
86+
"wasm": true,
87+
"src": [
88+
"./src/main.c"
89+
],
90+
"include": [
91+
"./include"
3592
],
93+
"libraries": [],
3694
"libpath": [],
3795
"dependencies": [
38-
"@stdlib/stats/base/dnanstdevpn"
96+
"@stdlib/stats/base/dnanstdevpn",
97+
"@stdlib/blas/base/shared",
98+
"@stdlib/strided/base/stride2offset"
3999
]
40100
}
41101
]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "stdlib/stats/base/dnanstdev.h"
20+
#include "stdlib/napi/export.h"
21+
#include "stdlib/napi/argv.h"
22+
#include "stdlib/napi/argv_int64.h"
23+
#include "stdlib/napi/argv_strided_float64array.h"
24+
#include "stdlib/napi/create_double.h"
25+
26+
/**
27+
* Receives JavaScript callback invocation data.
28+
*
29+
* @param env environment under which the function is invoked
30+
* @param info callback data
31+
* @return Node-API value
32+
*/
33+
static napi_value addon( napi_env env, napi_callback_info info ) {
34+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
35+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
36+
STDLIB_NAPI_ARGV_INT64( env, correction, argv, 2 );
37+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
38+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, correction, strideX, argv, 1 );
39+
STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanstdev( N, correction, X, strideX ), v );
40+
return v;
41+
}
42+
43+
/**
44+
* Receives JavaScript callback invocation data.
45+
*
46+
* @param env environment under which the function is invoked
47+
* @param info callback data
48+
* @return Node-API value
49+
*/
50+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
51+
STDLIB_NAPI_ARGV( env, info, argv, argc, 5 );
52+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
53+
STDLIB_NAPI_ARGV_INT64( env, correction, argv, 4 );
54+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
55+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
56+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
57+
STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanstdev_ndarray( N, correction, strideX, offsetX ), v );
58+
return v;
59+
}
60+
61+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )

0 commit comments

Comments
 (0)