Skip to content

Commit bc629b6

Browse files
feat: ndarray-dnanmeanors
1 parent c60ec02 commit bc629b6

File tree

15 files changed

+192
-236
lines changed

15 files changed

+192
-236
lines changed

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

+1-1
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/dnanmeanors/include/stdlib/stats/base/dnanmeanors.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_DNANMEANORS_H
2020
#define STDLIB_STATS_BASE_DNANMEANORS_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, ignoring `NaN` values and using ordinary recursive summation.
3333
*/
34-
double stdlib_strided_dnanmeanors( const int64_t N, const double *X, const int64_t stride );
34+
double API_SUFFIX(stdlib_strided_dnanmeanors)( const CBLAS_INT N, 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_dnanmeanors_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/dnanmeanors/lib/dnanmeanors.js

+9-31
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
24+
var ndarray = require( './ndarray.js' );
25+
2126
// MAIN //
2227

2328
/**
2429
* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation.
2530
*
2631
* @param {PositiveInteger} N - number of indexed elements
2732
* @param {Float64Array} x - input array
28-
* @param {integer} stride - stride length
33+
* @param {integer} strideX - stride length
2934
* @returns {number} arithmetic mean
3035
*
3136
* @example
@@ -34,38 +39,11 @@
3439
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
3540
* var N = x.length;
3641
*
37-
* var v = dnanmeanors( N, x, 1 );
42+
* var v = dnanmeanors( x.length, x, 1 );
3843
* // returns ~0.3333
3944
*/
40-
function dnanmeanors( N, x, stride ) {
41-
var ix;
42-
var v;
43-
var s;
44-
var n;
45-
var i;
46-
47-
if ( N <= 0 ) {
48-
return NaN;
49-
}
50-
if ( N === 1 || stride === 0 ) {
51-
return x[ 0 ];
52-
}
53-
if ( stride < 0 ) {
54-
ix = (1-N) * stride;
55-
} else {
56-
ix = 0;
57-
}
58-
s = 0.0;
59-
n = 0;
60-
for ( i = 0; i < N; i++ ) {
61-
v = x[ ix ];
62-
if ( v === v ) {
63-
s += v;
64-
n += 1;
65-
}
66-
ix += stride;
67-
}
68-
return s / n;
45+
function dnanmeanors( N, x, strideX ) {
46+
return ndarray( N, x, strideX, stride2offset( N, strideX ) );
6947
}
7048

7149

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ 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
@@ -39,11 +39,11 @@ var addon = require( './../src/addon.node' );
3939
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
4040
* var N = x.length;
4141
*
42-
* var v = dnanmeanors( N, x, 1 );
42+
* var v = dnanmeanors( 5, x, 1 );
4343
* // returns ~0.3333
4444
*/
45-
function dnanmeanors( N, x, stride ) {
46-
return addon( N, x, stride );
45+
function dnanmeanors( N, x, strideX ) {
46+
return addon( N, x, strideX );
4747
}
4848

4949

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

+2-4
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 = 3;
3232
*
33-
* var v = dnanmeanors( N, x, 1 );
33+
* var v = dnanmeanors( x.length, x, 1 );
3434
* // returns ~0.3333
3535
*
3636
* @example
3737
* var Float64Array = require( '@stdlib/array/float64' );
38-
* var floor = require( '@stdlib/math/base/special/floor' );
3938
* var dnanmeanors = require( '@stdlib/stats/base/dnanmeanors' );
4039
*
4140
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
42-
* var N = floor( x.length / 2 );
4341
*
44-
* var v = dnanmeanors.ndarray( N, x, 2, 1 );
42+
* var v = dnanmeanors.ndarray( 5, x, 2, 1 );
4543
* // returns 1.25
4644
*/
4745

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
XX/**
22
* @license Apache-2.0
33
*
44
* Copyright (c) 2020 The Stdlib Authors.
@@ -25,21 +25,19 @@
2525
*
2626
* @param {PositiveInteger} N - number of indexed elements
2727
* @param {Float64Array} x - input array
28-
* @param {integer} stride - stride length
29-
* @param {NonNegativeInteger} offset - starting index
28+
* @param {integer} strideX - stride length
29+
* @param {NonNegativeInteger} offsetX - starting index
3030
* @returns {number} arithmetic mean
3131
*
3232
* @example
3333
* var Float64Array = require( '@stdlib/array/float64' );
34-
* var floor = require( '@stdlib/math/base/special/floor' );
3534
*
3635
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
37-
* var N = floor( x.length / 2 );
3836
*
39-
* var v = dnanmeanors( N, x, 2, 1 );
37+
* var v = dnanmeanors( 5, x, 2, 1 );
4038
* // returns 1.25
4139
*/
42-
function dnanmeanors( N, x, stride, offset ) {
40+
function dnanmeanors( N, x, strideX, offsetX ) {
4341
var ix;
4442
var v;
4543
var s;
@@ -49,10 +47,10 @@ function dnanmeanors( N, x, stride, offset ) {
4947
if ( N <= 0 ) {
5048
return NaN;
5149
}
52-
if ( N === 1 || stride === 0 ) {
53-
return x[ offset ];
50+
if ( N === 1 || strideX === 0 ) {
51+
return x[ offsetX ];
5452
}
55-
ix = offset;
53+
ix = offsetX;
5654
s = 0.0;
5755
n = 0;
5856
for ( i = 0; i < N; i++ ) {
@@ -61,7 +59,7 @@ function dnanmeanors( N, x, stride, offset ) {
6159
s += v;
6260
n += 1;
6361
}
64-
ix += stride;
62+
ix += strideX;
6563
}
6664
return s / n;
6765
}

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

+6-14
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( './dnanmeanors.native.js' );
23+
var addon = require( './../src/addon.node' );
2524

2625

2726
// MAIN //
@@ -31,27 +30,20 @@ var addon = require( './dnanmeanors.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, NaN ] );
43-
* var N = floor( x.length / 2 );
4441
*
45-
* var v = dnanmeanors( N, x, 2, 1 );
42+
* var v = dnanmeanors( 5, x, 2, 1 );
4643
* // returns 1.25
4744
*/
48-
function dnanmeanors( 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 dnanmeanors( N, x, strideX, offsetX ) {
46+
return addon.ndarray( N, x, strideX, offsetX );
5547
}
5648

5749

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

+61-5
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,17 +27,70 @@
2427
],
2528
"confs": [
2629
{
30+
"task": "build",
31+
"wasm": false,
2732
"src": [
28-
"./src/dnanmeanors.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+
]
46+
},
47+
{
48+
"task": "benchmark",
49+
"wasm": false,
50+
"src": [
51+
"./src/main.c"
52+
],
53+
"include": [
54+
"./include"
55+
],
56+
"libraries": [],
57+
"libpath": [],
58+
"dependencies": [
59+
"@stdlib/blas/base/shared",
60+
"@stdlib/strided/base/stride2offset"
61+
]
62+
},
63+
{
64+
"task": "examples",
65+
"wasm": false,
66+
"src": [
67+
"./src/main.c"
68+
],
69+
"include": [
70+
"./include"
71+
],
72+
"libraries": [],
73+
"libpath": [],
74+
"dependencies": [
75+
"@stdlib/blas/base/shared",
76+
"@stdlib/strided/base/stride2offset"
77+
]
78+
},
79+
{
80+
"task": "",
81+
"wasm": true,
82+
"src": [
83+
"./src/main.c"
84+
],
85+
"include": [
86+
"./include"
3587
],
88+
"libraries": [],
3689
"libpath": [],
37-
"dependencies": []
90+
"dependencies": [
91+
"@stdlib/blas/base/shared",
92+
"@stdlib/strided/base/stride2offset"
93+
]
3894
}
3995
]
4096
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 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/dnanmeanors.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, 3 );
35+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
36+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
37+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
38+
STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanors( N, X, strideX ), v );
39+
return v;
40+
}
41+
42+
/**
43+
* Receives JavaScript callback invocation data.
44+
*
45+
* @param env environment under which the function is invoked
46+
* @param info callback data
47+
* @return Node-API value
48+
*/
49+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
50+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
51+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
52+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
53+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
54+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
55+
STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanors_ndarray( N, X, strideX, offsetX ), v );
56+
return v;
57+
}
58+
59+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )

0 commit comments

Comments
 (0)