@stdlib/stats-strided-snanrange 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.
@@ -0,0 +1,92 @@
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
+ // TypeScript Version: 4.1
20
+
21
+ /**
22
+ * Interface describing `snanrange`.
23
+ */
24
+ interface Routine {
25
+ /**
26
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
27
+ *
28
+ * @param N - number of indexed elements
29
+ * @param x - input array
30
+ * @param strideX - stride length
31
+ * @returns range
32
+ *
33
+ * @example
34
+ * var Float32Array = require( '@stdlib/array-float32' );
35
+ *
36
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
37
+ *
38
+ * var v = snanrange( x.length, x, 1 );
39
+ * // returns 4.0
40
+ */
41
+ ( N: number, x: Float32Array, strideX: number ): number;
42
+
43
+ /**
44
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
45
+ *
46
+ * @param N - number of indexed elements
47
+ * @param x - input array
48
+ * @param strideX - stride length
49
+ * @param offsetX - starting index
50
+ * @returns range
51
+ *
52
+ * @example
53
+ * var Float32Array = require( '@stdlib/array-float32' );
54
+ *
55
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
56
+ *
57
+ * var v = snanrange.ndarray( x.length, x, 1, 0 );
58
+ * // returns 4.0
59
+ */
60
+ ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number;
61
+ }
62
+
63
+ /**
64
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
65
+ *
66
+ * @param N - number of indexed elements
67
+ * @param x - input array
68
+ * @param strideX - stride length
69
+ * @returns range
70
+ *
71
+ * @example
72
+ * var Float32Array = require( '@stdlib/array-float32' );
73
+ *
74
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
75
+ *
76
+ * var v = snanrange( x.length, x, 1 );
77
+ * // returns 4.0
78
+ *
79
+ * @example
80
+ * var Float32Array = require( '@stdlib/array-float32' );
81
+ *
82
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
83
+ *
84
+ * var v = snanrange.ndarray( x.length, x, 1, 0 );
85
+ * // returns 4.0
86
+ */
87
+ declare var snanrange: Routine;
88
+
89
+
90
+ // EXPORTS //
91
+
92
+ export = snanrange;
@@ -0,0 +1,45 @@
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
+ #ifndef STDLIB_STATS_STRIDED_SNANRANGE_H
20
+ #define STDLIB_STATS_STRIDED_SNANRANGE_H
21
+
22
+ #include "stdlib/blas/base/shared.h"
23
+
24
+ /*
25
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26
+ */
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /**
32
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
33
+ */
34
+ float API_SUFFIX(stdlib_strided_snanrange)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
35
+
36
+ /**
37
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
38
+ */
39
+ float API_SUFFIX(stdlib_strided_snanrange_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #endif // !STDLIB_STATS_STRIDED_SNANRANGE_H
package/lib/index.js ADDED
@@ -0,0 +1,68 @@
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
+ 'use strict';
20
+
21
+ /**
22
+ * Compute the range of a single-precision floating-point strided array, ignoring `NaN` values.
23
+ *
24
+ * @module @stdlib/stats-strided-snanrange
25
+ *
26
+ * @example
27
+ * var Float32Array = require( '@stdlib/array-float32' );
28
+ * var snanrange = require( '@stdlib/stats-strided-snanrange' );
29
+ *
30
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
31
+ *
32
+ * var v = snanrange( x.length, x, 1 );
33
+ * // returns 4.0
34
+ *
35
+ * @example
36
+ * var Float32Array = require( '@stdlib/array-float32' );
37
+ * var snanrange = require( '@stdlib/stats-strided-snanrange' );
38
+ *
39
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
40
+ *
41
+ * var v = snanrange.ndarray( 5, x, 2, 1 );
42
+ * // returns 6.0
43
+ */
44
+
45
+ // MODULES //
46
+
47
+ var join = require( 'path' ).join;
48
+ var tryRequire = require( '@stdlib/utils-try-require' );
49
+ var isError = require( '@stdlib/assert-is-error' );
50
+ var main = require( './main.js' );
51
+
52
+
53
+ // MAIN //
54
+
55
+ var snanrange;
56
+ var tmp = tryRequire( join( __dirname, './native.js' ) );
57
+ if ( isError( tmp ) ) {
58
+ snanrange = main;
59
+ } else {
60
+ snanrange = tmp;
61
+ }
62
+
63
+
64
+ // EXPORTS //
65
+
66
+ module.exports = snanrange;
67
+
68
+ // exports: { "ndarray": "snanrange.ndarray" }
package/lib/main.js ADDED
@@ -0,0 +1,35 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
24
+ var snanrange = require( './snanrange.js' );
25
+ var ndarray = require( './ndarray.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( snanrange, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = snanrange;
package/lib/native.js ADDED
@@ -0,0 +1,35 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
24
+ var snanrange = require( './snanrange.native.js' );
25
+ var ndarray = require( './ndarray.native.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( snanrange, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = snanrange;
package/lib/ndarray.js ADDED
@@ -0,0 +1,94 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
24
+ var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
31
+ *
32
+ * @param {PositiveInteger} N - number of indexed elements
33
+ * @param {Float32Array} x - input array
34
+ * @param {integer} strideX - stride length
35
+ * @param {NonNegativeInteger} offsetX - starting index
36
+ * @returns {number} range
37
+ *
38
+ * @example
39
+ * var Float32Array = require( '@stdlib/array-float32' );
40
+ *
41
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
42
+ *
43
+ * var v = snanrange( 5, x, 2, 1 );
44
+ * // returns 6.0
45
+ */
46
+ function snanrange( N, x, strideX, offsetX ) {
47
+ var max;
48
+ var min;
49
+ var ix;
50
+ var v;
51
+ var i;
52
+
53
+ if ( N <= 0 ) {
54
+ return NaN;
55
+ }
56
+ if ( N === 1 || strideX === 0 ) {
57
+ if ( isnanf( x[ offsetX ] ) ) {
58
+ return x[ offsetX ];
59
+ }
60
+ return 0.0;
61
+ }
62
+ ix = offsetX;
63
+ for ( i = 0; i < N; i++ ) {
64
+ v = x[ ix ];
65
+ if ( v === v ) {
66
+ break;
67
+ }
68
+ ix += strideX;
69
+ }
70
+ if ( i === N ) {
71
+ return NaN;
72
+ }
73
+ min = v;
74
+ max = min;
75
+ i += 1;
76
+ for ( i; i < N; i++ ) {
77
+ ix += strideX;
78
+ v = x[ ix ];
79
+ if ( isnanf( v ) ) {
80
+ continue;
81
+ }
82
+ if ( v < min ) {
83
+ min = v;
84
+ } else if ( v > max ) {
85
+ max = v;
86
+ }
87
+ }
88
+ return float64ToFloat32( max - min );
89
+ }
90
+
91
+
92
+ // EXPORTS //
93
+
94
+ module.exports = snanrange;
@@ -0,0 +1,52 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
30
+ *
31
+ * @param {PositiveInteger} N - number of indexed elements
32
+ * @param {Float32Array} x - input array
33
+ * @param {integer} strideX - stride length
34
+ * @param {NonNegativeInteger} offsetX - starting index
35
+ * @returns {number} range
36
+ *
37
+ * @example
38
+ * var Float32Array = require( '@stdlib/array-float32' );
39
+ *
40
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
41
+ *
42
+ * var v = snanrange( 5, x, 2, 1 );
43
+ * // returns 6.0
44
+ */
45
+ function snanrange( N, x, strideX, offsetX ) {
46
+ return addon.ndarray( N, x, strideX, offsetX );
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = snanrange;
@@ -0,0 +1,52 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
31
+ *
32
+ * @param {PositiveInteger} N - number of indexed elements
33
+ * @param {Float32Array} x - input array
34
+ * @param {integer} strideX - stride length
35
+ * @returns {number} range
36
+ *
37
+ * @example
38
+ * var Float32Array = require( '@stdlib/array-float32' );
39
+ *
40
+ * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
41
+ *
42
+ * var v = snanrange( x.length, x, 1 );
43
+ * // returns 4.0
44
+ */
45
+ function snanrange( N, x, strideX ) {
46
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = snanrange;
@@ -0,0 +1,51 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the range of a single-precision floating-point strided array, ignoring `NaN` values.
30
+ *
31
+ * @param {PositiveInteger} N - number of indexed elements
32
+ * @param {Float32Array} x - input array
33
+ * @param {integer} strideX - stride length
34
+ * @returns {number} range
35
+ *
36
+ * @example
37
+ * var Float32Array = require( '@stdlib/array-float32' );
38
+ *
39
+ * var x = new Float32Array( [ 1.0, -2.0, 2.0, NaN ] );
40
+ *
41
+ * var v = snanrange( x.length, x, 1 );
42
+ * // returns 4.0
43
+ */
44
+ function snanrange( N, x, strideX ) {
45
+ return addon( N, x, strideX );
46
+ }
47
+
48
+
49
+ // EXPORTS //
50
+
51
+ module.exports = snanrange;
package/manifest.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "options": {
3
+ "task": "build",
4
+ "wasm": false
5
+ },
6
+ "fields": [
7
+ {
8
+ "field": "src",
9
+ "resolve": true,
10
+ "relative": true
11
+ },
12
+ {
13
+ "field": "include",
14
+ "resolve": true,
15
+ "relative": true
16
+ },
17
+ {
18
+ "field": "libraries",
19
+ "resolve": false,
20
+ "relative": false
21
+ },
22
+ {
23
+ "field": "libpath",
24
+ "resolve": true,
25
+ "relative": false
26
+ }
27
+ ],
28
+ "confs": [
29
+ {
30
+ "task": "build",
31
+ "wasm": false,
32
+ "src": [
33
+ "./src/main.c"
34
+ ],
35
+ "include": [
36
+ "./include"
37
+ ],
38
+ "libraries": [],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/blas-base-shared",
42
+ "@stdlib/strided-base-stride2offset",
43
+ "@stdlib/math-base-assert-is-nanf",
44
+ "@stdlib/napi-export",
45
+ "@stdlib/napi-argv",
46
+ "@stdlib/napi-argv-int64",
47
+ "@stdlib/napi-argv-strided-float32array",
48
+ "@stdlib/napi-create-double"
49
+ ]
50
+ },
51
+ {
52
+ "task": "benchmark",
53
+ "wasm": false,
54
+ "src": [
55
+ "./src/main.c"
56
+ ],
57
+ "include": [
58
+ "./include"
59
+ ],
60
+ "libraries": [],
61
+ "libpath": [],
62
+ "dependencies": [
63
+ "@stdlib/blas-base-shared",
64
+ "@stdlib/strided-base-stride2offset",
65
+ "@stdlib/math-base-assert-is-nanf"
66
+ ]
67
+ },
68
+ {
69
+ "task": "examples",
70
+ "wasm": false,
71
+ "src": [
72
+ "./src/main.c"
73
+ ],
74
+ "include": [
75
+ "./include"
76
+ ],
77
+ "libraries": [],
78
+ "libpath": [],
79
+ "dependencies": [
80
+ "@stdlib/blas-base-shared",
81
+ "@stdlib/strided-base-stride2offset",
82
+ "@stdlib/math-base-assert-is-nanf"
83
+ ]
84
+ },
85
+ {
86
+ "task": "",
87
+ "wasm": true,
88
+ "src": [
89
+ "./src/main.c"
90
+ ],
91
+ "include": [
92
+ "./include"
93
+ ],
94
+ "libraries": [],
95
+ "libpath": [],
96
+ "dependencies": [
97
+ "@stdlib/blas-base-shared",
98
+ "@stdlib/strided-base-stride2offset",
99
+ "@stdlib/math-base-assert-is-nanf"
100
+ ]
101
+ }
102
+ ]
103
+ }