@stdlib/stats-strided-srange 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +402 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +92 -0
- package/include/stdlib/stats/strided/srange.h +45 -0
- package/lib/index.js +68 -0
- package/lib/main.js +35 -0
- package/lib/native.js +35 -0
- package/lib/ndarray.js +83 -0
- package/lib/ndarray.native.js +52 -0
- package/lib/srange.js +52 -0
- package/lib/srange.native.js +51 -0
- package/manifest.json +103 -0
- package/package.json +96 -0
- package/src/addon.c +61 -0
- package/src/main.c +78 -0
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/stats-strided-srange",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Calculate the range of a single-precision floating-point strided array.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"browser": "./lib/main.js",
|
|
18
|
+
"gypfile": false,
|
|
19
|
+
"directories": {
|
|
20
|
+
"doc": "./docs",
|
|
21
|
+
"include": "./include",
|
|
22
|
+
"lib": "./lib",
|
|
23
|
+
"src": "./src",
|
|
24
|
+
"dist": "./dist"
|
|
25
|
+
},
|
|
26
|
+
"types": "./docs/types",
|
|
27
|
+
"scripts": {},
|
|
28
|
+
"homepage": "https://stdlib.io",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git://github.com/stdlib-js/stats-strided-srange.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/blas-base-shared": "^0.2.0",
|
|
39
|
+
"@stdlib/math-base-assert-is-nanf": "^0.2.2",
|
|
40
|
+
"@stdlib/napi-argv": "^0.2.2",
|
|
41
|
+
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
42
|
+
"@stdlib/napi-argv-strided-float32array": "^0.2.2",
|
|
43
|
+
"@stdlib/napi-create-double": "^0.0.2",
|
|
44
|
+
"@stdlib/napi-export": "^0.3.0",
|
|
45
|
+
"@stdlib/number-float64-base-to-float32": "^0.2.2",
|
|
46
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
47
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
48
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
49
|
+
"@stdlib/utils-try-require": "^0.2.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=0.10.0",
|
|
54
|
+
"npm": ">2.7.0"
|
|
55
|
+
},
|
|
56
|
+
"os": [
|
|
57
|
+
"aix",
|
|
58
|
+
"darwin",
|
|
59
|
+
"freebsd",
|
|
60
|
+
"linux",
|
|
61
|
+
"macos",
|
|
62
|
+
"openbsd",
|
|
63
|
+
"sunos",
|
|
64
|
+
"win32",
|
|
65
|
+
"windows"
|
|
66
|
+
],
|
|
67
|
+
"keywords": [
|
|
68
|
+
"stdlib",
|
|
69
|
+
"stdmath",
|
|
70
|
+
"statistics",
|
|
71
|
+
"stats",
|
|
72
|
+
"mathematics",
|
|
73
|
+
"math",
|
|
74
|
+
"maximum",
|
|
75
|
+
"max",
|
|
76
|
+
"minimum",
|
|
77
|
+
"min",
|
|
78
|
+
"range",
|
|
79
|
+
"extremes",
|
|
80
|
+
"domain",
|
|
81
|
+
"extent",
|
|
82
|
+
"dispersion",
|
|
83
|
+
"strided",
|
|
84
|
+
"strided array",
|
|
85
|
+
"typed",
|
|
86
|
+
"array",
|
|
87
|
+
"float32",
|
|
88
|
+
"float",
|
|
89
|
+
"single",
|
|
90
|
+
"float32array"
|
|
91
|
+
],
|
|
92
|
+
"funding": {
|
|
93
|
+
"type": "opencollective",
|
|
94
|
+
"url": "https://opencollective.com/stdlib"
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/addon.c
ADDED
|
@@ -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/strided/srange.h"
|
|
20
|
+
#include "stdlib/blas/base/shared.h"
|
|
21
|
+
#include "stdlib/napi/export.h"
|
|
22
|
+
#include "stdlib/napi/argv.h"
|
|
23
|
+
#include "stdlib/napi/argv_int64.h"
|
|
24
|
+
#include "stdlib/napi/argv_strided_float32array.h"
|
|
25
|
+
#include "stdlib/napi/create_double.h"
|
|
26
|
+
#include <node_api.h>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Receives JavaScript callback invocation data.
|
|
30
|
+
*
|
|
31
|
+
* @param env environment under which the function is invoked
|
|
32
|
+
* @param info callback data
|
|
33
|
+
* @return Node-API value
|
|
34
|
+
*/
|
|
35
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
36
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
|
|
37
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
38
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
39
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
40
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_srange)( N, X, strideX ), v );
|
|
41
|
+
return v;
|
|
42
|
+
}
|
|
43
|
+
|
|
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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
57
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_srange_ndarray)( N, X, strideX, offsetX ), v );
|
|
58
|
+
return v;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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/strided/srange.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nanf.h"
|
|
21
|
+
#include "stdlib/blas/base/shared.h"
|
|
22
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Computes the range of a single-precision floating-point strided array.
|
|
26
|
+
*
|
|
27
|
+
* @param N number of indexed elements
|
|
28
|
+
* @param X input array
|
|
29
|
+
* @param strideX stride length
|
|
30
|
+
* @return output value
|
|
31
|
+
*/
|
|
32
|
+
float API_SUFFIX(stdlib_strided_srange)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
|
|
33
|
+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
|
|
34
|
+
return API_SUFFIX(stdlib_strided_srange_ndarray)( N, X, strideX, ox );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Computes the range of a single-precision floating-point strided array using alternative indexing semantics.
|
|
39
|
+
*
|
|
40
|
+
* @param N number of indexed elements
|
|
41
|
+
* @param X input array
|
|
42
|
+
* @param strideX stride length
|
|
43
|
+
* @param offsetX starting index for X
|
|
44
|
+
* @return output value
|
|
45
|
+
*/
|
|
46
|
+
float API_SUFFIX(stdlib_strided_srange_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
|
|
47
|
+
CBLAS_INT ix;
|
|
48
|
+
CBLAS_INT i;
|
|
49
|
+
float max;
|
|
50
|
+
float min;
|
|
51
|
+
float v;
|
|
52
|
+
|
|
53
|
+
if ( N <= 0 ) {
|
|
54
|
+
return 0.0f / 0.0f; // NaN
|
|
55
|
+
}
|
|
56
|
+
if ( N == 1 || strideX == 0 ) {
|
|
57
|
+
if ( stdlib_base_is_nanf( X[ 0 ] ) ) {
|
|
58
|
+
return X[ offsetX ];
|
|
59
|
+
}
|
|
60
|
+
return 0.0f;
|
|
61
|
+
}
|
|
62
|
+
ix = offsetX;
|
|
63
|
+
min = X[ ix ];
|
|
64
|
+
max = min;
|
|
65
|
+
for ( i = 1; i < N; i++ ) {
|
|
66
|
+
ix += strideX;
|
|
67
|
+
v = X[ ix ];
|
|
68
|
+
if ( stdlib_base_is_nanf( v ) ) {
|
|
69
|
+
return v;
|
|
70
|
+
}
|
|
71
|
+
if ( v < min ) {
|
|
72
|
+
min = v;
|
|
73
|
+
} else if ( v > max ) {
|
|
74
|
+
max = v;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return max - min;
|
|
78
|
+
}
|