@stdlib/math-tools-unary 0.2.2 → 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.
- package/NOTICE +1 -1
- package/README.md +220 -189
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -18
- package/dist/index.js.map +4 -4
- package/docs/types/index.d.ts +80 -166
- package/lib/index.js +19 -14
- package/lib/main.js +153 -149
- package/lib/validate.js +13 -15
- package/package.json +21 -17
- package/lib/defaults.json +0 -3
- package/lib/ndarray.js +0 -63
- package/lib/policies.json +0 -6
- package/lib/resolve_output_dtype.js +0 -78
- package/lib/validate_options.js +0 -67
- package/lib/validate_table.js +0 -84
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 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 format = require( '@stdlib/string-format' );
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// MAIN //
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Resolves an output array data type.
|
|
30
|
-
*
|
|
31
|
-
* @private
|
|
32
|
-
* @param {string} xdtype - input array data type
|
|
33
|
-
* @param {string} policy - policy determining an output array data type
|
|
34
|
-
* @throws {Error} unsupported policy
|
|
35
|
-
* @returns {string} output array data type
|
|
36
|
-
*/
|
|
37
|
-
function resolve( xdtype, policy ) {
|
|
38
|
-
switch ( policy ) {
|
|
39
|
-
case 'same':
|
|
40
|
-
return xdtype;
|
|
41
|
-
case 'floating-point':
|
|
42
|
-
// TODO: we may want to delegate checking for a floating-point dtype to a utility function/package (e.g., isFloatDtype), in order to centralize logic for testing whether a dtype is "floating-point". Otherwise, this will be yet another place to update logic should we ever add, e.g., a `float128` or `float16` dtype.
|
|
43
|
-
if (
|
|
44
|
-
xdtype === 'float64' ||
|
|
45
|
-
xdtype === 'float32' ||
|
|
46
|
-
xdtype === 'generic' ||
|
|
47
|
-
xdtype === 'complex128' ||
|
|
48
|
-
xdtype === 'complex64'
|
|
49
|
-
) {
|
|
50
|
-
return xdtype;
|
|
51
|
-
}
|
|
52
|
-
return 'float64'; // TODO: constants/math/default-real-floating-point-dtype?
|
|
53
|
-
case 'real floating-point':
|
|
54
|
-
if (
|
|
55
|
-
xdtype === 'float64' ||
|
|
56
|
-
xdtype === 'float32' ||
|
|
57
|
-
xdtype === 'generic'
|
|
58
|
-
) {
|
|
59
|
-
return xdtype;
|
|
60
|
-
}
|
|
61
|
-
return 'float64';
|
|
62
|
-
case 'complex floating-point':
|
|
63
|
-
if (
|
|
64
|
-
xdtype === 'complex128' ||
|
|
65
|
-
xdtype === 'complex64'
|
|
66
|
-
) {
|
|
67
|
-
return xdtype;
|
|
68
|
-
}
|
|
69
|
-
return 'complex128'; // TODO: constants/math/default-complex-floating-point-dtype?
|
|
70
|
-
default:
|
|
71
|
-
throw new Error( format( 'invalid option. Unsupported policy for determining an output array data type. Option: `%s`.', policy ) );
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// EXPORTS //
|
|
77
|
-
|
|
78
|
-
module.exports = resolve;
|
package/lib/validate_options.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
-
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
|
-
var contains = require( '@stdlib/assert-contains' );
|
|
26
|
-
var format = require( '@stdlib/string-format' );
|
|
27
|
-
var POLICIES = require( './policies.json' );
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// MAIN //
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Validates function options.
|
|
34
|
-
*
|
|
35
|
-
* @private
|
|
36
|
-
* @param {Object} opts - destination object
|
|
37
|
-
* @param {Object} options - options
|
|
38
|
-
* @param {string} [options.output_dtype_policy] - policy for determining the output array data type
|
|
39
|
-
* @returns {(Error|null)} null or an error object
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* var opts = {};
|
|
43
|
-
* var options = {
|
|
44
|
-
* 'output_dtype_policy': 'float'
|
|
45
|
-
* };
|
|
46
|
-
* var err = validate( opts, options );
|
|
47
|
-
* if ( err ) {
|
|
48
|
-
* throw err;
|
|
49
|
-
* }
|
|
50
|
-
*/
|
|
51
|
-
function validate( opts, options ) {
|
|
52
|
-
if ( !isPlainObject( options ) ) {
|
|
53
|
-
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
54
|
-
}
|
|
55
|
-
if ( hasOwnProp( options, 'output_dtype_policy' ) ) {
|
|
56
|
-
opts.policy = options.output_dtype_policy;
|
|
57
|
-
if ( !contains( POLICIES, opts.policy ) ) {
|
|
58
|
-
return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported output array data type policy. Option: `%s`.', 'output_dtype_policy', opts.policy ) );
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// EXPORTS //
|
|
66
|
-
|
|
67
|
-
module.exports = validate;
|
package/lib/validate_table.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
-
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
|
-
var isFunction = require( '@stdlib/assert-is-function' );
|
|
26
|
-
var isNull = require( '@stdlib/assert-is-null' );
|
|
27
|
-
var objectKeys = require( '@stdlib/utils-keys' );
|
|
28
|
-
var format = require( '@stdlib/string-format' );
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// MAIN //
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Validates a resolution table object.
|
|
35
|
-
*
|
|
36
|
-
* @private
|
|
37
|
-
* @param {Object} out - destination object
|
|
38
|
-
* @param {Object} table - resolution table object
|
|
39
|
-
* @param {(Function|null)} [table.number] - function to invoke upon receiving a number
|
|
40
|
-
* @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number
|
|
41
|
-
* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object
|
|
42
|
-
* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object
|
|
43
|
-
* @returns {(Error|null)} null or an error object
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* var out = {};
|
|
47
|
-
* var table = {
|
|
48
|
-
* 'number': null,
|
|
49
|
-
* 'complex': null,
|
|
50
|
-
* 'array': null,
|
|
51
|
-
* 'ndarray': null
|
|
52
|
-
* };
|
|
53
|
-
* var err = validate( out, table );
|
|
54
|
-
* if ( err ) {
|
|
55
|
-
* throw err;
|
|
56
|
-
* }
|
|
57
|
-
*/
|
|
58
|
-
function validate( out, table ) {
|
|
59
|
-
var fields;
|
|
60
|
-
var tmp;
|
|
61
|
-
var key;
|
|
62
|
-
var i;
|
|
63
|
-
|
|
64
|
-
if ( !isPlainObject( table ) ) {
|
|
65
|
-
return new TypeError( format( 'invalid argument. Resolution table must be an object. Value: `%s`.', table ) );
|
|
66
|
-
}
|
|
67
|
-
fields = objectKeys( out );
|
|
68
|
-
for ( i = 0; i < fields.length; i++ ) {
|
|
69
|
-
key = fields[ i ];
|
|
70
|
-
if ( hasOwnProp( table, key ) ) {
|
|
71
|
-
tmp = table[ key ];
|
|
72
|
-
if ( !isFunction( tmp ) && !isNull( tmp ) ) {
|
|
73
|
-
return new TypeError( format( 'invalid argument. Resolution table `%s` field value must be either a function or null. Value: `%s`.', key, tmp ) );
|
|
74
|
-
}
|
|
75
|
-
out[ key ] = tmp;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// EXPORTS //
|
|
83
|
-
|
|
84
|
-
module.exports = validate;
|