@stdlib/stats-strided-srangeabs 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) 2026 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 `srangeabs`.
23
+ */
24
+ interface Routine {
25
+ /**
26
+ * Computes the range of absolute values of a single-precision floating-point strided array.
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, 2.0 ] );
37
+ *
38
+ * var v = srangeabs( x.length, x, 1 );
39
+ * // returns 1.0
40
+ */
41
+ ( N: number, x: Float32Array, strideX: number ): number;
42
+
43
+ /**
44
+ * Computes the range of absolute values of a single-precision floating-point strided array 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, 2.0 ] );
56
+ *
57
+ * var v = srangeabs.ndarray( x.length, x, 1, 0 );
58
+ * // returns 1.0
59
+ */
60
+ ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number;
61
+ }
62
+
63
+ /**
64
+ * Computes the range of absolute values of a single-precision floating-point strided array.
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, 2.0 ] );
75
+ *
76
+ * var v = srangeabs( x.length, x, 1 );
77
+ * // returns 1.0
78
+ *
79
+ * @example
80
+ * var Float32Array = require( '@stdlib/array-float32' );
81
+ *
82
+ * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
83
+ *
84
+ * var v = srangeabs.ndarray( x.length, x, 1, 0 );
85
+ * // returns 1.0
86
+ */
87
+ declare var srangeabs: Routine;
88
+
89
+
90
+ // EXPORTS //
91
+
92
+ export = srangeabs;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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_SRANGEABS_H
20
+ #define STDLIB_STATS_STRIDED_SRANGEABS_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 absolute values of a single-precision floating-point strided array.
33
+ */
34
+ float API_SUFFIX(stdlib_strided_srangeabs)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
35
+
36
+ /**
37
+ * Computes the range of absolute values of a single-precision floating-point strided array using alternative indexing semantics.
38
+ */
39
+ float API_SUFFIX(stdlib_strided_srangeabs_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_SRANGEABS_H
package/lib/index.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 absolute values of a single-precision floating-point strided array.
23
+ *
24
+ * @module @stdlib/stats-strided-srangeabs
25
+ *
26
+ * @example
27
+ * var Float32Array = require( '@stdlib/array-float32' );
28
+ * var srangeabs = require( '@stdlib/stats-strided-srangeabs' );
29
+ *
30
+ * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
31
+ *
32
+ * var v = srangeabs( x.length, x, 1 );
33
+ * // returns 1.0
34
+ *
35
+ * @example
36
+ * var Float32Array = require( '@stdlib/array-float32' );
37
+ * var srangeabs = require( '@stdlib/stats-strided-srangeabs' );
38
+ *
39
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
40
+ *
41
+ * var v = srangeabs.ndarray( 4, x, 2, 1 );
42
+ * // returns 3.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 srangeabs;
56
+ var tmp = tryRequire( join( __dirname, './native.js' ) );
57
+ if ( isError( tmp ) ) {
58
+ srangeabs = main;
59
+ } else {
60
+ srangeabs = tmp;
61
+ }
62
+
63
+
64
+ // EXPORTS //
65
+
66
+ module.exports = srangeabs;
67
+
68
+ // exports: { "ndarray": "srangeabs.ndarray" }
package/lib/main.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 srangeabs = require( './srangeabs.js' );
25
+ var ndarray = require( './ndarray.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( srangeabs, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = srangeabs;
package/lib/native.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 srangeabs = require( './srangeabs.native.js' );
25
+ var ndarray = require( './ndarray.native.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( srangeabs, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = srangeabs;
package/lib/ndarray.js ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 absf = require( '@stdlib/math-base-special-absf' );
25
+ var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Computes the range of absolute values of a single-precision floating-point strided array.
32
+ *
33
+ * @param {PositiveInteger} N - number of indexed elements
34
+ * @param {Float32Array} x - input array
35
+ * @param {integer} strideX - stride length
36
+ * @param {NonNegativeInteger} offsetX - starting index
37
+ * @returns {number} range
38
+ *
39
+ * @example
40
+ * var Float32Array = require( '@stdlib/array-float32' );
41
+ *
42
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
43
+ *
44
+ * var v = srangeabs( 4, x, 2, 1 );
45
+ * // returns 3.0
46
+ */
47
+ function srangeabs( N, x, strideX, offsetX ) {
48
+ var max;
49
+ var min;
50
+ var ix;
51
+ var v;
52
+ var i;
53
+
54
+ if ( N <= 0 ) {
55
+ return NaN;
56
+ }
57
+ if ( N === 1 || strideX === 0 ) {
58
+ if ( isnanf( x[ offsetX ] ) ) {
59
+ return NaN;
60
+ }
61
+ return 0.0;
62
+ }
63
+ ix = offsetX;
64
+ v = x[ ix ];
65
+ if ( isnanf( v ) ) {
66
+ return v;
67
+ }
68
+ min = absf( v );
69
+ max = min;
70
+ for ( i = 1; i < N; i++ ) {
71
+ ix += strideX;
72
+ v = x[ ix ];
73
+ if ( isnanf( v ) ) {
74
+ return v;
75
+ }
76
+ v = absf( v );
77
+ if ( v < min ) {
78
+ min = v;
79
+ } else if ( v > max ) {
80
+ max = v;
81
+ }
82
+ }
83
+ return float64ToFloat32( max - min );
84
+ }
85
+
86
+
87
+ // EXPORTS //
88
+
89
+ module.exports = srangeabs;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 absolute values of a single-precision floating-point strided array.
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 ] );
41
+ *
42
+ * var v = srangeabs( 4, x, 2, 1 );
43
+ * // returns 3.0
44
+ */
45
+ function srangeabs( N, x, strideX, offsetX ) {
46
+ return addon.ndarray( N, x, strideX, offsetX );
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = srangeabs;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 absolute values of a single-precision floating-point strided array.
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, 2.0 ] );
41
+ *
42
+ * var v = srangeabs( x.length, x, 1 );
43
+ * // returns 1.0
44
+ */
45
+ function srangeabs( N, x, strideX ) {
46
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = srangeabs;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2026 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 absolute values of a single-precision floating-point strided array.
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 ] );
40
+ *
41
+ * var v = srangeabs( x.length, x, 1 );
42
+ * // returns 1.0
43
+ */
44
+ function srangeabs( N, x, strideX ) {
45
+ return addon( N, x, strideX );
46
+ }
47
+
48
+
49
+ // EXPORTS //
50
+
51
+ module.exports = srangeabs;
package/manifest.json ADDED
@@ -0,0 +1,107 @@
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/math-base-special-absf",
45
+ "@stdlib/napi-export",
46
+ "@stdlib/napi-argv",
47
+ "@stdlib/napi-argv-int64",
48
+ "@stdlib/napi-argv-strided-float32array",
49
+ "@stdlib/napi-create-double"
50
+ ]
51
+ },
52
+ {
53
+ "task": "benchmark",
54
+ "wasm": false,
55
+ "src": [
56
+ "./src/main.c"
57
+ ],
58
+ "include": [
59
+ "./include"
60
+ ],
61
+ "libraries": [],
62
+ "libpath": [],
63
+ "dependencies": [
64
+ "@stdlib/blas-base-shared",
65
+ "@stdlib/strided-base-stride2offset",
66
+ "@stdlib/math-base-assert-is-nanf",
67
+ "@stdlib/math-base-special-absf"
68
+ ]
69
+ },
70
+ {
71
+ "task": "examples",
72
+ "wasm": false,
73
+ "src": [
74
+ "./src/main.c"
75
+ ],
76
+ "include": [
77
+ "./include"
78
+ ],
79
+ "libraries": [],
80
+ "libpath": [],
81
+ "dependencies": [
82
+ "@stdlib/blas-base-shared",
83
+ "@stdlib/strided-base-stride2offset",
84
+ "@stdlib/math-base-assert-is-nanf",
85
+ "@stdlib/math-base-special-absf"
86
+ ]
87
+ },
88
+ {
89
+ "task": "",
90
+ "wasm": true,
91
+ "src": [
92
+ "./src/main.c"
93
+ ],
94
+ "include": [
95
+ "./include"
96
+ ],
97
+ "libraries": [],
98
+ "libpath": [],
99
+ "dependencies": [
100
+ "@stdlib/blas-base-shared",
101
+ "@stdlib/strided-base-stride2offset",
102
+ "@stdlib/math-base-assert-is-nanf",
103
+ "@stdlib/math-base-special-absf"
104
+ ]
105
+ }
106
+ ]
107
+ }