@stdlib/math-special-abs 0.2.1 → 0.3.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2021 The Stdlib Authors.
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -20,25 +20,38 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var base = require( '@stdlib/math-base-special-abs' );
24
- var strided = require( '@stdlib/math-strided-special-abs' );
25
- var dispatcher = require( '@stdlib/ndarray-dispatch' );
26
- var unary = require( '@stdlib/ndarray-base-unary' );
27
- var types = require( './types.json' );
28
- var meta = require( './meta.json' );
29
- var data = require( './data.js' );
23
+ var dtypes = require( '@stdlib/ndarray-dtypes' );
30
24
 
31
25
 
32
26
  // MAIN //
33
27
 
34
- var table = {
35
- 'number': base,
36
- 'complex': null,
37
- 'array': strided,
38
- 'ndarray': dispatcher( unary, types, data, meta.nargs, meta.nin, meta.nout )
28
+ var config = {
29
+ // Total number of ndarray arguments:
30
+ 'nargs': 2,
31
+
32
+ // Number of input ndarray arguments:
33
+ 'nin': 1,
34
+
35
+ // Number of output ndarray arguments:
36
+ 'nout': 1,
37
+
38
+ // List of supported input ndarray data types:
39
+ 'idtypes': dtypes( 'numeric_and_generic' ),
40
+
41
+ // List of supported output ndarray data types:
42
+ 'odtypes': dtypes( 'real_and_generic' ),
43
+
44
+ // Dispatch policies:
45
+ 'policies': {
46
+ // Output data type policy:
47
+ 'output': 'real_and_generic',
48
+
49
+ // Input ndarray casting policy:
50
+ 'casting': 'none'
51
+ }
39
52
  };
40
53
 
41
54
 
42
55
  // EXPORTS //
43
56
 
44
- module.exports = table;
57
+ module.exports = config;
package/lib/data.js CHANGED
@@ -25,7 +25,11 @@
25
25
  var abs = require( '@stdlib/math-base-special-abs' );
26
26
  var absf = require( '@stdlib/math-base-special-absf' );
27
27
  var labs = require( '@stdlib/math-base-special-labs' );
28
- var identity = require( '@stdlib/math-base-special-identity' );
28
+ var cabs = require( '@stdlib/math-base-special-cabs' );
29
+ var cabsf = require( '@stdlib/math-base-special-cabsf' );
30
+ var identityUint32 = require( '@stdlib/number-uint32-base-identity' );
31
+ var identityUint16 = require( '@stdlib/number-uint16-base-identity' );
32
+ var identityUint8 = require( '@stdlib/number-uint8-base-identity' );
29
33
 
30
34
 
31
35
  // MAIN //
@@ -39,12 +43,21 @@ var data = [
39
43
 
40
44
  // float32
41
45
  absf,
42
- absf,
43
- absf,
46
+ abs,
47
+ abs,
44
48
 
45
49
  // generic
46
50
  abs,
47
51
 
52
+ // complex128
53
+ cabs,
54
+ cabs,
55
+
56
+ // complex64
57
+ cabsf,
58
+ cabs,
59
+ cabs,
60
+
48
61
  // int32
49
62
  labs,
50
63
  labs,
@@ -52,60 +65,60 @@ var data = [
52
65
  labs,
53
66
 
54
67
  // int16
55
- abs,
56
- abs,
57
- abs,
58
- abs,
59
- abs,
60
- abs,
61
- abs,
68
+ labs,
69
+ labs,
70
+ labs,
71
+ labs,
72
+ labs,
73
+ labs,
74
+ labs,
62
75
 
63
76
  // int8
64
- abs,
65
- abs,
66
- abs,
67
- abs,
68
- abs,
69
- abs,
70
- abs,
71
- abs,
72
- abs,
73
- abs,
77
+ labs,
78
+ labs,
79
+ labs,
80
+ labs,
81
+ labs,
82
+ labs,
83
+ labs,
84
+ labs,
85
+ labs,
86
+ labs,
74
87
 
75
88
  // uint32
76
- identity,
77
- identity,
78
- identity,
89
+ identityUint32,
90
+ identityUint32,
91
+ identityUint32,
79
92
 
80
93
  // uint16
81
- identity,
82
- identity,
83
- identity,
84
- identity,
85
- identity,
86
- identity,
94
+ identityUint16,
95
+ identityUint16,
96
+ identityUint16,
97
+ identityUint16,
98
+ identityUint16,
99
+ identityUint16,
87
100
 
88
101
  // uint8
89
- identity,
90
- identity,
91
- identity,
92
- identity,
93
- identity,
94
- identity,
95
- identity,
96
- identity,
97
- identity,
102
+ identityUint8,
103
+ identityUint8,
104
+ identityUint8,
105
+ identityUint8,
106
+ identityUint8,
107
+ identityUint8,
108
+ identityUint8,
109
+ identityUint8,
110
+ identityUint8,
98
111
 
99
112
  // uint8c
100
- identity,
101
- identity,
102
- identity,
103
- identity,
104
- identity,
105
- identity,
106
- identity,
107
- identity,
108
- identity
113
+ identityUint8,
114
+ identityUint8,
115
+ identityUint8,
116
+ identityUint8,
117
+ identityUint8,
118
+ identityUint8,
119
+ identityUint8,
120
+ identityUint8,
121
+ identityUint8
109
122
  ];
110
123
 
111
124
 
package/lib/index.js CHANGED
@@ -24,29 +24,7 @@
24
24
  * @module @stdlib/math-special-abs
25
25
  *
26
26
  * @example
27
- * var abs = require( '@stdlib/math-special-abs' );
28
- *
29
- * var y = abs( -1.0 );
30
- * // returns 1.0
31
- *
32
- * @example
33
- * var Float64Array = require( '@stdlib/array-float64' );
34
- * var abs = require( '@stdlib/math-special-abs' );
35
- *
36
- * var x = new Float64Array( [ 1.0, -1.0, 0.0 ] );
37
- *
38
- * var y = abs( x );
39
- * // returns <Float64Array>[ 1.0, 1.0, 0.0 ]
40
- *
41
- * @example
42
- * var abs = require( '@stdlib/math-special-abs' );
43
- *
44
- * var x = [ 1.0, -1.0, 0.0 ];
45
- *
46
- * var y = abs( x );
47
- * // returns [ 1.0, 1.0, 0.0 ]
48
- *
49
- * @example
27
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
50
28
  * var array = require( '@stdlib/ndarray-array' );
51
29
  * var abs = require( '@stdlib/math-special-abs' );
52
30
  *
@@ -56,8 +34,8 @@
56
34
  * var y = abs( x );
57
35
  * // returns <ndarray>
58
36
  *
59
- * var v = y.get( 0, 1 );
60
- * // 2.0
37
+ * var arr = ndarray2array( y );
38
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
61
39
  */
62
40
 
63
41
  // MODULES //
package/lib/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2021 The Stdlib Authors.
4
+ * Copyright (c) 2020 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,20 +16,53 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ /* eslint-disable max-len */
20
+
19
21
  'use strict';
20
22
 
21
23
  // MODULES //
22
24
 
25
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
23
26
  var setProps = require( '@stdlib/ndarray-base-meta-data-props' );
24
- var meta = require( './meta.json' );
27
+ var ufunc = require( '@stdlib/math-tools-unary' );
28
+ var unary = require( '@stdlib/ndarray-base-unary' );
29
+ var data = require( './data.js' );
25
30
  var types = require( './types.json' );
26
- var abs = require( './abs.js' );
31
+ var config = require( './config.js' );
27
32
 
28
33
 
29
34
  // MAIN //
30
35
 
31
- setProps( meta, types, abs );
32
- setProps( meta, types, abs.assign );
36
+ /**
37
+ * Computes the absolute value for each element in an ndarray.
38
+ *
39
+ * @name abs
40
+ * @type {Function}
41
+ * @param {ndarray} x - input ndarray
42
+ * @param {Options} [options] - options
43
+ * @param {string} [options.order] - output array order
44
+ * @param {*} [options.dtype] - output array dtype
45
+ * @throws {TypeError} first argument must be an ndarray-like object
46
+ * @throws {TypeError} options argument must be an object
47
+ * @throws {TypeError} must provide valid options
48
+ * @returns {ndarray} output ndarray
49
+ *
50
+ * @example
51
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
52
+ * var array = require( '@stdlib/ndarray-array' );
53
+ *
54
+ * var x = array( [ [ 1.0, -2.0 ], [ -3.0, 4.0 ] ] );
55
+ * // returns <ndarray>
56
+ *
57
+ * var y = abs( x );
58
+ * // returns <ndarray>
59
+ *
60
+ * var arr = ndarray2array( y );
61
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
62
+ */
63
+ var abs = ufunc( dispatch( unary, types, data, config.nargs, config.nin, config.nout ), [ config.idtypes ], config.odtypes, config.policies );
64
+ setProps( config, types, abs );
65
+ setProps( config, types, abs.assign );
33
66
 
34
67
 
35
68
  // EXPORTS //
package/lib/native.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2021 The Stdlib Authors.
4
+ * Copyright (c) 2020 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,20 +16,53 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ /* eslint-disable max-len */
20
+
19
21
  'use strict';
20
22
 
21
23
  // MODULES //
22
24
 
25
+ var dispatch = require( '@stdlib/ndarray-base-unary-addon-dispatch' );
23
26
  var setProps = require( '@stdlib/ndarray-base-meta-data-props' );
24
- var meta = require( './meta.json' );
27
+ var ufunc = require( '@stdlib/math-tools-unary' );
28
+ var addon = require( './../src/addon.node' );
25
29
  var types = require( './types.json' );
26
- var abs = require( './abs.native.js' );
30
+ var config = require( './config.js' );
31
+ var fallback = require( './main.js' ).assign;
27
32
 
28
33
 
29
34
  // MAIN //
30
35
 
31
- setProps( meta, types, abs );
32
- setProps( meta, types, abs.assign );
36
+ /**
37
+ * Computes the absolute value for each element in an ndarray.
38
+ *
39
+ * @name abs
40
+ * @type {Function}
41
+ * @param {ndarray} x - input ndarray
42
+ * @param {Options} [options] - options
43
+ * @param {string} [options.order] - output array order
44
+ * @param {*} [options.dtype] - output array dtype
45
+ * @throws {TypeError} first argument must be an ndarray-like object
46
+ * @throws {TypeError} options argument must be an object
47
+ * @throws {TypeError} must provide valid options
48
+ * @returns {ndarray} output ndarray
49
+ *
50
+ * @example
51
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
52
+ * var array = require( '@stdlib/ndarray-array' );
53
+ *
54
+ * var x = array( [ [ 1.0, -2.0 ], [ -3.0, 4.0 ] ] );
55
+ * // returns <ndarray>
56
+ *
57
+ * var y = abs( x );
58
+ * // returns <ndarray>
59
+ *
60
+ * var arr = ndarray2array( y );
61
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
62
+ */
63
+ var abs = ufunc( dispatch( addon, fallback ), [ config.idtypes ], config.odtypes, config.policies );
64
+ setProps( config, types, abs );
65
+ setProps( config, types, abs.assign );
33
66
 
34
67
 
35
68
  // EXPORTS //
package/lib/types.js CHANGED
@@ -31,70 +31,78 @@ var dtypes = require( '@stdlib/ndarray-dtypes' );
31
31
 
32
32
  // MAIN //
33
33
 
34
+ // Type signatures...
34
35
  var types = [
35
- dtypes.float64, dtypes.float64,
36
- dtypes.float64, dtypes.generic,
37
-
38
- dtypes.float32, dtypes.float32,
39
- dtypes.float32, dtypes.float64,
40
- dtypes.float32, dtypes.generic,
41
-
42
- dtypes.generic, dtypes.generic,
43
-
44
- dtypes.int32, dtypes.int32,
45
- dtypes.int32, dtypes.uint32,
46
- dtypes.int32, dtypes.float64,
47
- dtypes.int32, dtypes.generic,
48
-
49
- dtypes.int16, dtypes.int16,
50
- dtypes.int16, dtypes.int32,
51
- dtypes.int16, dtypes.uint16,
52
- dtypes.int16, dtypes.uint32,
53
- dtypes.int16, dtypes.float32,
54
- dtypes.int16, dtypes.float64,
55
- dtypes.int16, dtypes.generic,
56
-
57
- dtypes.int8, dtypes.int8,
58
- dtypes.int8, dtypes.int16,
59
- dtypes.int8, dtypes.int32,
60
- dtypes.int8, dtypes.uint8,
61
- dtypes.int8, dtypes.uint8c,
62
- dtypes.int8, dtypes.uint16,
63
- dtypes.int8, dtypes.uint32,
64
- dtypes.int8, dtypes.float32,
65
- dtypes.int8, dtypes.float64,
66
- dtypes.int8, dtypes.generic,
67
-
68
- dtypes.uint32, dtypes.uint32,
69
- dtypes.uint32, dtypes.float64,
70
- dtypes.uint32, dtypes.generic,
71
-
72
- dtypes.uint16, dtypes.int32,
73
- dtypes.uint16, dtypes.uint16,
74
- dtypes.uint16, dtypes.uint32,
75
- dtypes.uint16, dtypes.float32,
76
- dtypes.uint16, dtypes.float64,
77
- dtypes.uint16, dtypes.generic,
78
-
79
- dtypes.uint8, dtypes.int16,
80
- dtypes.uint8, dtypes.int32,
81
- dtypes.uint8, dtypes.uint8,
82
- dtypes.uint8, dtypes.uint8c,
83
- dtypes.uint8, dtypes.uint16,
84
- dtypes.uint8, dtypes.uint32,
85
- dtypes.uint8, dtypes.float32,
86
- dtypes.uint8, dtypes.float64,
87
- dtypes.uint8, dtypes.generic,
88
-
89
- dtypes.uint8c, dtypes.int16,
90
- dtypes.uint8c, dtypes.int32,
91
- dtypes.uint8c, dtypes.uint8,
92
- dtypes.uint8c, dtypes.uint8c,
93
- dtypes.uint8c, dtypes.uint16,
94
- dtypes.uint8c, dtypes.uint32,
95
- dtypes.uint8c, dtypes.float32,
96
- dtypes.uint8c, dtypes.float64,
97
- dtypes.uint8c, dtypes.generic
36
+ dtypes.float64.enum, dtypes.float64.enum,
37
+ dtypes.float64.enum, dtypes.generic.enum,
38
+
39
+ dtypes.float32.enum, dtypes.float32.enum,
40
+ dtypes.float32.enum, dtypes.float64.enum,
41
+ dtypes.float32.enum, dtypes.generic.enum,
42
+
43
+ dtypes.generic.enum, dtypes.generic.enum,
44
+
45
+ dtypes.complex128.enum, dtypes.float64.enum,
46
+ dtypes.complex128.enum, dtypes.generic.enum,
47
+
48
+ dtypes.complex64.enum, dtypes.float32.enum,
49
+ dtypes.complex64.enum, dtypes.float64.enum,
50
+ dtypes.complex64.enum, dtypes.generic.enum,
51
+
52
+ dtypes.int32.enum, dtypes.int32.enum,
53
+ dtypes.int32.enum, dtypes.uint32.enum,
54
+ dtypes.int32.enum, dtypes.float64.enum,
55
+ dtypes.int32.enum, dtypes.generic.enum,
56
+
57
+ dtypes.int16.enum, dtypes.int16.enum,
58
+ dtypes.int16.enum, dtypes.int32.enum,
59
+ dtypes.int16.enum, dtypes.uint16.enum,
60
+ dtypes.int16.enum, dtypes.uint32.enum,
61
+ dtypes.int16.enum, dtypes.float32.enum,
62
+ dtypes.int16.enum, dtypes.float64.enum,
63
+ dtypes.int16.enum, dtypes.generic.enum,
64
+
65
+ dtypes.int8.enum, dtypes.int8.enum,
66
+ dtypes.int8.enum, dtypes.int16.enum,
67
+ dtypes.int8.enum, dtypes.int32.enum,
68
+ dtypes.int8.enum, dtypes.uint8.enum,
69
+ dtypes.int8.enum, dtypes.uint8c.enum,
70
+ dtypes.int8.enum, dtypes.uint16.enum,
71
+ dtypes.int8.enum, dtypes.uint32.enum,
72
+ dtypes.int8.enum, dtypes.float32.enum,
73
+ dtypes.int8.enum, dtypes.float64.enum,
74
+ dtypes.int8.enum, dtypes.generic.enum,
75
+
76
+ dtypes.uint32.enum, dtypes.uint32.enum,
77
+ dtypes.uint32.enum, dtypes.float64.enum,
78
+ dtypes.uint32.enum, dtypes.generic.enum,
79
+
80
+ dtypes.uint16.enum, dtypes.int32.enum,
81
+ dtypes.uint16.enum, dtypes.uint16.enum,
82
+ dtypes.uint16.enum, dtypes.uint32.enum,
83
+ dtypes.uint16.enum, dtypes.float32.enum,
84
+ dtypes.uint16.enum, dtypes.float64.enum,
85
+ dtypes.uint16.enum, dtypes.generic.enum,
86
+
87
+ dtypes.uint8.enum, dtypes.int16.enum,
88
+ dtypes.uint8.enum, dtypes.int32.enum,
89
+ dtypes.uint8.enum, dtypes.uint8.enum,
90
+ dtypes.uint8.enum, dtypes.uint8c.enum,
91
+ dtypes.uint8.enum, dtypes.uint16.enum,
92
+ dtypes.uint8.enum, dtypes.uint32.enum,
93
+ dtypes.uint8.enum, dtypes.float32.enum,
94
+ dtypes.uint8.enum, dtypes.float64.enum,
95
+ dtypes.uint8.enum, dtypes.generic.enum,
96
+
97
+ dtypes.uint8c.enum, dtypes.int16.enum,
98
+ dtypes.uint8c.enum, dtypes.int32.enum,
99
+ dtypes.uint8c.enum, dtypes.uint8.enum,
100
+ dtypes.uint8c.enum, dtypes.uint8c.enum,
101
+ dtypes.uint8c.enum, dtypes.uint16.enum,
102
+ dtypes.uint8c.enum, dtypes.uint32.enum,
103
+ dtypes.uint8c.enum, dtypes.float32.enum,
104
+ dtypes.uint8c.enum, dtypes.float64.enum,
105
+ dtypes.uint8c.enum, dtypes.generic.enum
98
106
  ];
99
107
 
100
108
 
package/lib/types.json CHANGED
@@ -1 +1 @@
1
- [11,11,11,15,10,10,10,11,10,15,15,15,6,6,6,7,6,11,6,15,4,4,4,6,4,5,4,7,4,10,4,11,4,15,1,1,1,4,1,6,1,2,1,3,1,5,1,7,1,10,1,11,1,15,7,7,7,11,7,15,5,6,5,5,5,7,5,10,5,11,5,15,2,4,2,6,2,2,2,3,2,5,2,7,2,10,2,11,2,15,3,4,3,6,3,2,3,3,3,5,3,7,3,10,3,11,3,15]
1
+ [12,12,12,17,11,11,11,12,11,17,17,17,15,12,15,17,14,11,14,12,14,17,6,6,6,7,6,12,6,17,4,4,4,6,4,5,4,7,4,11,4,12,4,17,1,1,1,4,1,6,1,2,1,3,1,5,1,7,1,11,1,12,1,17,7,7,7,12,7,17,5,6,5,5,5,7,5,11,5,12,5,17,2,4,2,6,2,2,2,3,2,5,2,7,2,11,2,12,2,17,3,4,3,6,3,2,3,3,3,5,3,7,3,11,3,12,3,17]
package/manifest.json CHANGED
@@ -1,44 +1,47 @@
1
1
  {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [],
28
- "include": [
29
- "./include"
30
- ],
31
- "libraries": [],
32
- "libpath": [],
33
- "dependencies": [
34
- "@stdlib/math-base-special-abs",
35
- "@stdlib/math-base-special-absf",
36
- "@stdlib/math-base-special-labs",
37
- "@stdlib/ndarray-base-function-object",
38
- "@stdlib/ndarray-base-napi-unary",
39
- "@stdlib/ndarray-base-unary",
40
- "@stdlib/ndarray-dtypes"
41
- ]
42
- }
43
- ]
2
+ "options": {},
3
+ "fields": [
4
+ {
5
+ "field": "src",
6
+ "resolve": true,
7
+ "relative": true
8
+ },
9
+ {
10
+ "field": "include",
11
+ "resolve": true,
12
+ "relative": true
13
+ },
14
+ {
15
+ "field": "libraries",
16
+ "resolve": false,
17
+ "relative": false
18
+ },
19
+ {
20
+ "field": "libpath",
21
+ "resolve": true,
22
+ "relative": false
23
+ }
24
+ ],
25
+ "confs": [
26
+ {
27
+ "src": [],
28
+ "include": [
29
+ "./include"
30
+ ],
31
+ "libraries": [],
32
+ "libpath": [],
33
+ "dependencies": [
34
+ "@stdlib/math-base-special-abs",
35
+ "@stdlib/math-base-special-absf",
36
+ "@stdlib/math-base-special-labs",
37
+ "@stdlib/number-uint32-base-identity",
38
+ "@stdlib/number-uint16-base-identity",
39
+ "@stdlib/number-uint8-base-identity",
40
+ "@stdlib/ndarray-base-function-object",
41
+ "@stdlib/ndarray-base-napi-unary",
42
+ "@stdlib/ndarray-base-unary",
43
+ "@stdlib/ndarray-dtypes"
44
+ ]
45
+ }
46
+ ]
44
47
  }