@stdlib/stats-strided-snanmskrange 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 +456 -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 +107 -0
- package/include/stdlib/stats/strided/snanmskrange.h +46 -0
- package/lib/index.js +72 -0
- package/lib/main.js +35 -0
- package/lib/native.js +35 -0
- package/lib/ndarray.js +100 -0
- package/lib/ndarray.native.js +57 -0
- package/lib/snanmskrange.js +56 -0
- package/lib/snanmskrange.native.js +55 -0
- package/manifest.json +104 -0
- package/package.json +100 -0
- package/src/addon.c +67 -0
- package/src/main.c +97 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/ndarray.js", "../lib/snanmskrange.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar isnanf = require( '@stdlib/math-base-assert-is-nanf' );\n\n\n// MAIN //\n\n/**\n* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {Uint8Array} mask - mask array\n* @param {integer} strideMask - `mask` stride length\n* @param {NonNegativeInteger} offsetMask - `mask` starting index\n* @returns {number} range\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );\n* var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );\n*\n* var v = snanmskrange( 5, x, 2, 1, mask, 2, 1 );\n* // returns 6.0\n*/\nfunction snanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {\n\tvar max;\n\tvar min;\n\tvar ix;\n\tvar im;\n\tvar v;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tix = offsetX;\n\tim = offsetMask;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( v === v && mask[ im ] === 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t\tim += strideMask;\n\t}\n\tif ( i === N ) {\n\t\treturn NaN;\n\t}\n\tmin = v;\n\tmax = min;\n\ti += 1;\n\tfor ( i; i < N; i++ ) {\n\t\tix += strideX;\n\t\tim += strideMask;\n\t\tif ( mask[ im ] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tv = x[ ix ];\n\t\tif ( isnanf( v ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( v < min ) {\n\t\t\tmin = v;\n\t\t} else if ( v > max ) {\n\t\t\tmax = v;\n\t\t}\n\t}\n\treturn float64ToFloat32( max - min );\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanmskrange;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {Uint8Array} mask - mask array\n* @param {integer} strideMask - `mask` stride length\n* @returns {number} range\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );\n* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );\n*\n* var v = snanmskrange( x.length, x, 1, mask, 1 );\n* // returns 4.0\n*/\nfunction snanmskrange( N, x, strideX, mask, strideMask ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ), mask, strideMask, stride2offset( N, strideMask ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanmskrange;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar snanmskrange = require( './snanmskrange.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( snanmskrange, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = snanmskrange;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.\n*\n* @module @stdlib/stats-strided-snanmskrange\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var snanmskrange = require( '@stdlib/stats-strided-snanmskrange' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );\n* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );\n*\n* var v = snanmskrange( x.length, x, 1, mask, 1 );\n* // returns 4.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var snanmskrange = require( '@stdlib/stats-strided-snanmskrange' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );\n* var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );\n*\n* var v = snanmskrange.ndarray( 5, x, 2, 1, mask, 2, 1 );\n* // returns 6.0\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar snanmskrange;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tsnanmskrange = main;\n} else {\n\tsnanmskrange = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanmskrange;\n\n// exports: { \"ndarray\": \"snanmskrange.ndarray\" }\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,wCAAyC,EACrEC,EAAS,QAAS,kCAAmC,EA2BzD,SAASC,EAAcC,EAAGC,EAAGC,EAASC,EAASC,EAAMC,EAAYC,EAAa,CAC7E,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EAEJ,GAAKX,GAAK,EACT,MAAO,KAIR,IAFAS,EAAKN,EACLO,EAAKJ,EACC,EAAI,EAAG,EAAIN,IAChBW,EAAIV,EAAGQ,CAAG,EACL,EAAAE,IAAMA,GAAKP,EAAMM,CAAG,IAAM,IAFZ,IAKnBD,GAAMP,EACNQ,GAAML,EAEP,GAAK,IAAML,EACV,MAAO,KAKR,IAHAQ,EAAMG,EACNJ,EAAMC,EACN,GAAK,EACC,EAAG,EAAIR,EAAG,IACfS,GAAMP,EACNQ,GAAML,EACD,CAAAD,EAAMM,CAAG,IAGdC,EAAIV,EAAGQ,CAAG,EACL,CAAAX,EAAQa,CAAE,IAGVA,EAAIH,EACRA,EAAMG,EACKA,EAAIJ,IACfA,EAAMI,KAGR,OAAOd,EAAkBU,EAAMC,CAAI,CACpC,CAKAZ,EAAO,QAAUG,ICnGjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAyBd,SAASC,EAAcC,EAAGC,EAAGC,EAASC,EAAMC,EAAa,CACxD,OAAON,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,EAAGC,EAAMC,EAAYP,EAAeG,EAAGI,CAAW,CAAE,CAC9G,CAKAR,EAAO,QAAUG,ICvDjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAe,IACfC,EAAU,IAKdF,EAAaC,EAAc,UAAWC,CAAQ,EAK9CH,EAAO,QAAUE,ICgBjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAeD,EAEfC,EAAeC,EAMhB,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "float64ToFloat32", "isnanf", "snanmskrange", "N", "x", "strideX", "offsetX", "mask", "strideMask", "offsetMask", "max", "min", "ix", "im", "v", "require_snanmskrange", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "snanmskrange", "N", "x", "strideX", "mask", "strideMask", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "snanmskrange", "ndarray", "join", "tryRequire", "isError", "main", "snanmskrange", "tmp"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 `snanmskrange`.
|
|
23
|
+
*/
|
|
24
|
+
interface Routine {
|
|
25
|
+
/**
|
|
26
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
|
|
27
|
+
*
|
|
28
|
+
* @param N - number of indexed elements
|
|
29
|
+
* @param x - input array
|
|
30
|
+
* @param strideX - `x` stride length
|
|
31
|
+
* @param mask - mask array
|
|
32
|
+
* @param strideMask - `mask` stride length
|
|
33
|
+
* @returns range
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
37
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
38
|
+
*
|
|
39
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
40
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
41
|
+
*
|
|
42
|
+
* var v = snanmskrange( x.length, x, 1, mask, 1 );
|
|
43
|
+
* // returns 4.0
|
|
44
|
+
*/
|
|
45
|
+
( N: number, x: Float32Array, strideX: number, mask: Uint8Array, strideMask: number ): number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values and using alternative indexing semantics.
|
|
49
|
+
*
|
|
50
|
+
* @param N - number of indexed elements
|
|
51
|
+
* @param x - input array
|
|
52
|
+
* @param strideX - `x` stride length
|
|
53
|
+
* @param offsetX - `x` starting index
|
|
54
|
+
* @param mask - mask array
|
|
55
|
+
* @param strideMask - `mask` stride length
|
|
56
|
+
* @param offsetMask - `mask` starting index
|
|
57
|
+
* @returns range
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
61
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
62
|
+
*
|
|
63
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
64
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
65
|
+
*
|
|
66
|
+
* var v = snanmskrange.ndarray( x.length, x, 1, 0, mask, 1, 0 );
|
|
67
|
+
* // returns 4.0
|
|
68
|
+
*/
|
|
69
|
+
ndarray( N: number, x: Float32Array, strideX: number, offsetX: number, mask: Uint8Array, strideMask: number, offsetMask: number ): number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
|
|
74
|
+
*
|
|
75
|
+
* @param N - number of indexed elements
|
|
76
|
+
* @param x - input array
|
|
77
|
+
* @param strideX - `x` stride length
|
|
78
|
+
* @param mask - mask array
|
|
79
|
+
* @param strideMask - `mask` stride length
|
|
80
|
+
* @returns range
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
84
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
85
|
+
*
|
|
86
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
87
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
88
|
+
*
|
|
89
|
+
* var v = snanmskrange( x.length, x, 1, mask, 1 );
|
|
90
|
+
* // returns 4.0
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
94
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
95
|
+
*
|
|
96
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
97
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
98
|
+
*
|
|
99
|
+
* var v = snanmskrange.ndarray( x.length, x, 1, 0, mask, 1, 0 );
|
|
100
|
+
* // returns 4.0
|
|
101
|
+
*/
|
|
102
|
+
declare var snanmskrange: Routine;
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// EXPORTS //
|
|
106
|
+
|
|
107
|
+
export = snanmskrange;
|
|
@@ -0,0 +1,46 @@
|
|
|
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_SNANMSKRANGE_H
|
|
20
|
+
#define STDLIB_STATS_STRIDED_SNANMSKRANGE_H
|
|
21
|
+
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
23
|
+
#include <stdint.h>
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
27
|
+
*/
|
|
28
|
+
#ifdef __cplusplus
|
|
29
|
+
extern "C" {
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
|
|
34
|
+
*/
|
|
35
|
+
float API_SUFFIX(stdlib_strided_snanmskrange)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const uint8_t *Mask, const CBLAS_INT strideMask );
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values and using alternative indexing semantics.
|
|
39
|
+
*/
|
|
40
|
+
float API_SUFFIX(stdlib_strided_snanmskrange_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const uint8_t *Mask, const CBLAS_INT strideMask, const CBLAS_INT offsetMask );
|
|
41
|
+
|
|
42
|
+
#ifdef __cplusplus
|
|
43
|
+
}
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#endif // !STDLIB_STATS_STRIDED_SNANMSKRANGE_H
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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 according to a mask, ignoring `NaN` values.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/stats-strided-snanmskrange
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
28
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
29
|
+
* var snanmskrange = require( '@stdlib/stats-strided-snanmskrange' );
|
|
30
|
+
*
|
|
31
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
32
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
33
|
+
*
|
|
34
|
+
* var v = snanmskrange( x.length, x, 1, mask, 1 );
|
|
35
|
+
* // returns 4.0
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
39
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
40
|
+
* var snanmskrange = require( '@stdlib/stats-strided-snanmskrange' );
|
|
41
|
+
*
|
|
42
|
+
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
|
|
43
|
+
* var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );
|
|
44
|
+
*
|
|
45
|
+
* var v = snanmskrange.ndarray( 5, x, 2, 1, mask, 2, 1 );
|
|
46
|
+
* // returns 6.0
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
// MODULES //
|
|
50
|
+
|
|
51
|
+
var join = require( 'path' ).join;
|
|
52
|
+
var tryRequire = require( '@stdlib/utils-try-require' );
|
|
53
|
+
var isError = require( '@stdlib/assert-is-error' );
|
|
54
|
+
var main = require( './main.js' );
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// MAIN //
|
|
58
|
+
|
|
59
|
+
var snanmskrange;
|
|
60
|
+
var tmp = tryRequire( join( __dirname, './native.js' ) );
|
|
61
|
+
if ( isError( tmp ) ) {
|
|
62
|
+
snanmskrange = main;
|
|
63
|
+
} else {
|
|
64
|
+
snanmskrange = tmp;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// EXPORTS //
|
|
69
|
+
|
|
70
|
+
module.exports = snanmskrange;
|
|
71
|
+
|
|
72
|
+
// exports: { "ndarray": "snanmskrange.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 snanmskrange = require( './snanmskrange.js' );
|
|
25
|
+
var ndarray = require( './ndarray.js' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// MAIN //
|
|
29
|
+
|
|
30
|
+
setReadOnly( snanmskrange, 'ndarray', ndarray );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// EXPORTS //
|
|
34
|
+
|
|
35
|
+
module.exports = snanmskrange;
|
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 snanmskrange = require( './snanmskrange.native.js' );
|
|
25
|
+
var ndarray = require( './ndarray.native.js' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// MAIN //
|
|
29
|
+
|
|
30
|
+
setReadOnly( snanmskrange, 'ndarray', ndarray );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// EXPORTS //
|
|
34
|
+
|
|
35
|
+
module.exports = snanmskrange;
|
package/lib/ndarray.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
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 float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
|
|
24
|
+
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes the range of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
|
|
31
|
+
*
|
|
32
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
33
|
+
* @param {Float32Array} x - input array
|
|
34
|
+
* @param {integer} strideX - `x` stride length
|
|
35
|
+
* @param {NonNegativeInteger} offsetX - `x` starting index
|
|
36
|
+
* @param {Uint8Array} mask - mask array
|
|
37
|
+
* @param {integer} strideMask - `mask` stride length
|
|
38
|
+
* @param {NonNegativeInteger} offsetMask - `mask` starting index
|
|
39
|
+
* @returns {number} range
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
43
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
44
|
+
*
|
|
45
|
+
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
|
|
46
|
+
* var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );
|
|
47
|
+
*
|
|
48
|
+
* var v = snanmskrange( 5, x, 2, 1, mask, 2, 1 );
|
|
49
|
+
* // returns 6.0
|
|
50
|
+
*/
|
|
51
|
+
function snanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {
|
|
52
|
+
var max;
|
|
53
|
+
var min;
|
|
54
|
+
var ix;
|
|
55
|
+
var im;
|
|
56
|
+
var v;
|
|
57
|
+
var i;
|
|
58
|
+
|
|
59
|
+
if ( N <= 0 ) {
|
|
60
|
+
return NaN;
|
|
61
|
+
}
|
|
62
|
+
ix = offsetX;
|
|
63
|
+
im = offsetMask;
|
|
64
|
+
for ( i = 0; i < N; i++ ) {
|
|
65
|
+
v = x[ ix ];
|
|
66
|
+
if ( v === v && mask[ im ] === 0 ) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
ix += strideX;
|
|
70
|
+
im += strideMask;
|
|
71
|
+
}
|
|
72
|
+
if ( i === N ) {
|
|
73
|
+
return NaN;
|
|
74
|
+
}
|
|
75
|
+
min = v;
|
|
76
|
+
max = min;
|
|
77
|
+
i += 1;
|
|
78
|
+
for ( i; i < N; i++ ) {
|
|
79
|
+
ix += strideX;
|
|
80
|
+
im += strideMask;
|
|
81
|
+
if ( mask[ im ] ) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
v = x[ ix ];
|
|
85
|
+
if ( isnanf( v ) ) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if ( v < min ) {
|
|
89
|
+
min = v;
|
|
90
|
+
} else if ( v > max ) {
|
|
91
|
+
max = v;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return float64ToFloat32( max - min );
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
// EXPORTS //
|
|
99
|
+
|
|
100
|
+
module.exports = snanmskrange;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 according to a mask, ignoring `NaN` values.
|
|
30
|
+
*
|
|
31
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
32
|
+
* @param {Float32Array} x - input array
|
|
33
|
+
* @param {integer} strideX - `x` stride length
|
|
34
|
+
* @param {NonNegativeInteger} offsetX - `x` starting index
|
|
35
|
+
* @param {Uint8Array} mask - mask array
|
|
36
|
+
* @param {integer} strideMask - `mask` stride length
|
|
37
|
+
* @param {NonNegativeInteger} offsetMask - `mask` starting index
|
|
38
|
+
* @returns {number} range
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
42
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
43
|
+
*
|
|
44
|
+
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
|
|
45
|
+
* var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );
|
|
46
|
+
*
|
|
47
|
+
* var v = snanmskrange( 5, x, 2, 1, mask, 2, 1 );
|
|
48
|
+
* // returns 6.0
|
|
49
|
+
*/
|
|
50
|
+
function snanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {
|
|
51
|
+
return addon.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ); // eslint-disable-line max-len
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// EXPORTS //
|
|
56
|
+
|
|
57
|
+
module.exports = snanmskrange;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 according to a mask, ignoring `NaN` values.
|
|
31
|
+
*
|
|
32
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
33
|
+
* @param {Float32Array} x - input array
|
|
34
|
+
* @param {integer} strideX - `x` stride length
|
|
35
|
+
* @param {Uint8Array} mask - mask array
|
|
36
|
+
* @param {integer} strideMask - `mask` stride length
|
|
37
|
+
* @returns {number} range
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
41
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
42
|
+
*
|
|
43
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
44
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
45
|
+
*
|
|
46
|
+
* var v = snanmskrange( x.length, x, 1, mask, 1 );
|
|
47
|
+
* // returns 4.0
|
|
48
|
+
*/
|
|
49
|
+
function snanmskrange( N, x, strideX, mask, strideMask ) {
|
|
50
|
+
return ndarray( N, x, strideX, stride2offset( N, strideX ), mask, strideMask, stride2offset( N, strideMask ) ); // eslint-disable-line max-len
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// EXPORTS //
|
|
55
|
+
|
|
56
|
+
module.exports = snanmskrange;
|
|
@@ -0,0 +1,55 @@
|
|
|
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 according to a mask, ignoring `NaN` values.
|
|
30
|
+
*
|
|
31
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
32
|
+
* @param {Float32Array} x - input array
|
|
33
|
+
* @param {integer} strideX - `x` stride length
|
|
34
|
+
* @param {Uint8Array} mask - mask array
|
|
35
|
+
* @param {integer} strideMask - `mask` stride length
|
|
36
|
+
* @returns {number} range
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var Float32Array = require( '@stdlib/array-float32' );
|
|
40
|
+
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
41
|
+
*
|
|
42
|
+
* var x = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
|
|
43
|
+
* var mask = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
|
|
44
|
+
*
|
|
45
|
+
* var v = snanmskrange( x.length, x, 1, mask, 1 );
|
|
46
|
+
* // returns 4.0
|
|
47
|
+
*/
|
|
48
|
+
function snanmskrange( N, x, strideX, mask, strideMask ) {
|
|
49
|
+
return addon( N, x, strideX, mask, strideMask );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// EXPORTS //
|
|
54
|
+
|
|
55
|
+
module.exports = snanmskrange;
|