Skip to content

Commit 54367d5

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: passed - 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 54367d5

File tree

10 files changed

+141
-102
lines changed

10 files changed

+141
-102
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_DMEANORS_H
2020
#define STDLIB_STATS_BASE_DMEANORS_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 ordinary recursive summation.
3333
*/
34-
double stdlib_strided_dmeanors( const int64_t N, const double *X, const int64_t stride );
34+
double API_SUFFIX(stdlib_strided_dmeanors)( 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 ordinary recursive summation and alternative indexing semantics.
38+
*/
39+
double API_SUFFIX(stdlib_strided_dmeanors_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/dmeanors/lib/dmeanors.js

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

2121
// MODULES //
2222

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

2526

2627
// MAIN //
@@ -30,26 +31,19 @@ var dsumors = require( '@stdlib/blas/ext/base/dsumors' );
3031
*
3132
* @param {PositiveInteger} N - number of indexed elements
3233
* @param {Float64Array} x - input array
33-
* @param {integer} stride - stride length
34+
* @param {integer} strideX - stride length
3435
* @returns {number} arithmetic mean
3536
*
3637
* @example
3738
* var Float64Array = require( '@stdlib/array/float64' );
3839
*
3940
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
40-
* var N = x.length;
4141
*
42-
* var v = dmeanors( N, x, 1 );
42+
* var v = dmeanors( x.length, x, 1 );
4343
* // returns ~0.3333
4444
*/
45-
function dmeanors( N, x, stride ) {
46-
if ( N <= 0 ) {
47-
return NaN;
48-
}
49-
if ( N === 1 || stride === 0 ) {
50-
return x[ 0 ];
51-
}
52-
return dsumors( N, x, stride ) / N;
45+
function dmeanors( N, x, strideX ) {
46+
return ndarray( N, x, strideX, stride2offset( N, strideX ) );
5347
}
5448

5549

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' );
3030
*
3131
* @param {PositiveInteger} N - number of indexed elements
3232
* @param {Float64Array} x - input array
33-
* @param {integer} stride - stride length
33+
* @param {integer} strideX - stride length
3434
* @returns {number} arithmetic mean
3535
*
3636
* @example
3737
* var Float64Array = require( '@stdlib/array/float64' );
3838
*
3939
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
40-
* var N = x.length;
4140
*
42-
* var v = dmeanors( N, x, 1 );
41+
* var v = dmeanors( x.length, x, 1 );
4342
* // returns ~0.3333
4443
*/
45-
function dmeanors( N, x, stride ) {
46-
return addon( N, x, stride );
44+
function dmeanors( N, x, strideX ) {
45+
return addon( N, x, strideX );
4746
}
4847

4948

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@
2828
* var dmeanors = require( '@stdlib/stats/base/dmeanors' );
2929
*
3030
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
31-
* var N = x.length;
3231
*
33-
* var v = dmeanors( N, x, 1 );
32+
* var v = dmeanors( x.length, x, 1 );
3433
* // returns ~0.3333
3534
*
3635
* @example
3736
* var Float64Array = require( '@stdlib/array/float64' );
38-
* var floor = require( '@stdlib/math/base/special/floor' );
3937
* var dmeanors = require( '@stdlib/stats/base/dmeanors' );
4038
*
4139
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
42-
* var N = floor( x.length / 2 );
4340
*
44-
* var v = dmeanors.ndarray( N, x, 2, 1 );
41+
* var v = dmeanors.ndarray( 4, x, 2, 1 );
4542
* // returns 1.25
4643
*/
4744

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,26 @@ var dsumors = require( '@stdlib/blas/ext/base/dsumors' ).ndarray;
3030
*
3131
* @param {PositiveInteger} N - number of indexed elements
3232
* @param {Float64Array} x - input array
33-
* @param {integer} stride - stride length
34-
* @param {NonNegativeInteger} offset - starting index
33+
* @param {integer} strideX - stride length
34+
* @param {NonNegativeInteger} offsetX - starting index
3535
* @returns {number} arithmetic mean
3636
*
3737
* @example
3838
* var Float64Array = require( '@stdlib/array/float64' );
39-
* var floor = require( '@stdlib/math/base/special/floor' );
4039
*
4140
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
42-
* var N = floor( x.length / 2 );
4341
*
44-
* var v = dmeanors( N, x, 2, 1 );
42+
* var v = dmeanors( 4, x, 2, 1 );
4543
* // returns 1.25
4644
*/
47-
function dmeanors( N, x, stride, offset ) {
45+
function dmeanors( N, x, strideX, offsetX ) {
4846
if ( N <= 0 ) {
4947
return NaN;
5048
}
51-
if ( N === 1 || stride === 0 ) {
52-
return x[ offset ];
49+
if ( N === 1 || strideX === 0 ) {
50+
return x[ offsetX ];
5351
}
54-
return dsumors( N, x, stride, offset ) / N;
52+
return dsumors( N, x, strideX, offsetX ) / N;
5553
}
5654

5755

lib/node_modules/@stdlib/stats/base/dmeanors/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( './dmeanors.native.js' );
23+
var addon = require( './../src/addon.node' );
2524

2625

2726
// MAIN //
@@ -31,27 +30,20 @@ var addon = require( './dmeanors.native.js' );
3130
*
3231
* @param {PositiveInteger} N - number of indexed elements
3332
* @param {Float64Array} x - input array
34-
* @param {integer} stride - stride length
35-
* @param {NonNegativeInteger} offset - starting index
33+
* @param {integer} strideX - stride length
34+
* @param {NonNegativeInteger} offsetX - starting index
3635
* @returns {number} arithmetic mean
3736
*
3837
* @example
3938
* var Float64Array = require( '@stdlib/array/float64' );
40-
* var floor = require( '@stdlib/math/base/special/floor' );
4139
*
4240
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
43-
* var N = floor( x.length / 2 );
4441
*
45-
* var v = dmeanors( N, x, 2, 1 );
42+
* var v = dmeanors( 4, x, 2, 1 );
4643
* // returns 1.25
4744
*/
48-
function dmeanors( N, x, stride, offset ) {
49-
var view;
50-
if ( stride < 0 ) {
51-
offset += (N-1) * stride;
52-
}
53-
view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
54-
return addon( N, view, stride );
45+
function dmeanors( N, x, strideX, offsetX ) {
46+
return addon.ndarray( N, x, strideX, offsetX );
5547
}
5648

5749

lib/node_modules/@stdlib/stats/base/dmeanors/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/dmeanors.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/dsumors",
4244
"@stdlib/napi/export",
4345
"@stdlib/napi/argv",
@@ -48,33 +50,52 @@
4850
},
4951
{
5052
"task": "benchmark",
53+
"wasm": false,
5154
"src": [
52-
"./src/dmeanors.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/dsumors"
6366
]
6467
},
6568
{
6669
"task": "examples",
70+
"wasm": false,
6771
"src": [
68-
"./src/dmeanors.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/dsumors"
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/dsumors"
79100
]
80101
}

lib/node_modules/@stdlib/stats/base/dmeanors/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/dmeanors.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_dmeanors( 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_dmeanors)( 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_dmeanors_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/dmeanors/src/dmeanors.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)