Skip to content

Commit c780e16

Browse files
committed
feat: add C ndarray interface and refactor implementation
--- 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: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent abf124e commit c780e16

File tree

4 files changed

+85
-33
lines changed

4 files changed

+85
-33
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_DMEANLI_H
2020
#define STDLIB_STATS_BASE_DMEANLI_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 arithmetic mean of a double-precision floating-point strided array using a one-pass trial mean algorithm.
3333
*/
34-
double stdlib_strided_dmeanli( const int64_t N, const double *X, const int64_t stride );
34+
double API_SUFFIX(stdlib_strided_dmeanli)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
35+
36+
/**
37+
* Computes the arithmetic mean of a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics.
38+
*/
39+
double API_SUFFIX(stdlib_strided_dmeanli_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
3540

3641
#ifdef __cplusplus
3742
}

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"options": {
3-
"task": "build"
3+
"task": "build",
4+
"wasm": false
45
},
56
"fields": [
67
{
@@ -27,17 +28,18 @@
2728
"confs": [
2829
{
2930
"task": "build",
31+
"wasm": false,
3032
"src": [
31-
"./src/dmeanli.c"
33+
"./src/main.c"
3234
],
3335
"include": [
3436
"./include"
3537
],
36-
"libraries": [
37-
"-lm"
38-
],
38+
"libraries": [],
3939
"libpath": [],
4040
"dependencies": [
41+
"@stdlib/blas/base/shared",
42+
"@stdlib/strided/base/stride2offset",
4143
"@stdlib/blas/ext/base/dapxsum",
4244
"@stdlib/napi/export",
4345
"@stdlib/napi/argv",
@@ -48,33 +50,52 @@
4850
},
4951
{
5052
"task": "benchmark",
53+
"wasm": false,
5154
"src": [
52-
"./src/dmeanli.c"
55+
"./src/main.c"
5356
],
5457
"include": [
5558
"./include"
5659
],
57-
"libraries": [
58-
"-lm"
59-
],
60+
"libraries": [],
6061
"libpath": [],
6162
"dependencies": [
63+
"@stdlib/blas/base/shared",
64+
"@stdlib/strided/base/stride2offset",
6265
"@stdlib/blas/ext/base/dapxsum"
6366
]
6467
},
6568
{
6669
"task": "examples",
70+
"wasm": false,
6771
"src": [
68-
"./src/dmeanli.c"
72+
"./src/main.c"
6973
],
7074
"include": [
7175
"./include"
7276
],
73-
"libraries": [
74-
"-lm"
77+
"libraries": [],
78+
"libpath": [],
79+
"dependencies": [
80+
"@stdlib/blas/base/shared",
81+
"@stdlib/strided/base/stride2offset",
82+
"@stdlib/blas/ext/base/dapxsum"
83+
]
84+
},
85+
{
86+
"task": "",
87+
"wasm": true,
88+
"src": [
89+
"./src/main.c"
90+
],
91+
"include": [
92+
"./include"
7593
],
94+
"libraries": [],
7695
"libpath": [],
7796
"dependencies": [
97+
"@stdlib/blas/base/shared",
98+
"@stdlib/strided/base/stride2offset",
7899
"@stdlib/blas/ext/base/dapxsum"
79100
]
80101
}

lib/node_modules/@stdlib/stats/base/dmeanli/src/addon.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dmeanli.h"
20+
#include "stdlib/blas/base/shared.h"
2021
#include "stdlib/napi/export.h"
2122
#include "stdlib/napi/argv.h"
2223
#include "stdlib/napi/argv_int64.h"
@@ -34,10 +35,27 @@
3435
static napi_value addon( napi_env env, napi_callback_info info ) {
3536
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
3637
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
37-
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 );
38-
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 );
39-
STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dmeanli( N, X, stride ), v );
38+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
39+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
40+
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dmeanli)( N, X, strideX ), v );
4041
return v;
4142
}
4243

43-
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
44+
/**
45+
* Receives JavaScript callback invocation data.
46+
*
47+
* @param env environment under which the function is invoked
48+
* @param info callback data
49+
* @return Node-API value
50+
*/
51+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
52+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
53+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
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, API_SUFFIX(stdlib_strided_dmeanli_ndarray)( N, X, strideX, offsetX ), v );
58+
return v;
59+
}
60+
61+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )

lib/node_modules/@stdlib/stats/base/dmeanli/src/dmeanli.c renamed to lib/node_modules/@stdlib/stats/base/dmeanli/src/main.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
#include "stdlib/stats/base/dmeanli.h"
2020
#include "stdlib/blas/ext/base/dapxsum.h"
21-
#include <stdint.h>
21+
#include "stdlib/blas/base/shared.h"
22+
#include "stdlib/strided/base/stride2offset.h"
2223

2324
/**
2425
* Computes the arithmetic mean of a double-precision floating-point strided array using a one-pass trial mean algorithm.
@@ -27,24 +28,31 @@
2728
*
2829
* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154).
2930
*
30-
* @param N number of indexed elements
31-
* @param X input array
32-
* @param stride stride length
33-
* @return output value
31+
* @param N number of indexed elements
32+
* @param X input array
33+
* @param strideX stride length
34+
* @return output value
3435
*/
35-
double stdlib_strided_dmeanli( const int64_t N, const double *X, const int64_t stride ) {
36-
int64_t ix;
36+
double API_SUFFIX(stdlib_strided_dmeanli)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) {
37+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
38+
return API_SUFFIX(stdlib_strided_dmeanli_ndarray)( N, X, strideX, ox );
39+
}
3740

41+
/**
42+
* Computes the arithmetic mean of a double-precision floating-point strided array using a one-pass trial mean algorithm and alternative indexing semantics.
43+
*
44+
* @param N number of indexed elements
45+
* @param X input array
46+
* @param strideX stride length
47+
* @param offsetX starting index for X
48+
* @return output value
49+
*/
50+
double API_SUFFIX(stdlib_strided_dmeanli_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
3851
if ( N <= 0 ) {
3952
return 0.0 / 0.0; // NaN
4053
}
41-
if ( N == 1 || stride == 0 ) {
42-
return X[ 0 ];
43-
}
44-
if ( stride < 0 ) {
45-
ix = (1-N) * stride;
46-
} else {
47-
ix = 0;
54+
if ( N == 1 || strideX == 0 ) {
55+
return X[ offsetX ];
4856
}
49-
return X[ ix ] + ( stdlib_strided_dapxsum( N-1, -X[ ix ], X+( (stride > 0) ? stride : 0 ), stride ) / (double)N );
57+
return X[ offsetX ] + ( API_SUFFIX(stdlib_strided_dapxsum_ndarray)( N-1, -X[ offsetX ], X, strideX, offsetX + strideX ) / (double)N );
5058
}

0 commit comments

Comments
 (0)