@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/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/ndarray.js", "../lib/resolve_output_dtype.js", "../lib/defaults.json", "../lib/validate_table.js", "../lib/policies.json", "../lib/validate_options.js", "../lib/validate.js", "../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 ndarray = require( '@stdlib/ndarray-ctor' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar copy = require( '@stdlib/array-base-copy-indexed' );\n\n\n// MAIN //\n\n/**\n* Applies a function to an ndarray.\n*\n* @private\n* @param {Function} fcn - function to apply\n* @param {ndarray} x - input array\n* @param {string} ydtype - output array data type\n* @param {string} yorder - output array order\n* @returns {ndarray} output array\n*/\nfunction ndarrayfcn( fcn, x, ydtype, yorder ) {\n\tvar shape;\n\tvar buf;\n\tvar y;\n\n\t// Check if we were provided a zero-dimensional array...\n\tshape = copy( x.shape ); // Note: we need to copy the shape to avoid a shared shape object between `x` and `y` which could lead to unintended mutations (e.g., if either `x` or `y` is reshaped)\n\tif ( shape.length === 0 ) {\n\t\tbuf = buffer( ydtype, 1 );\n\t\ty = ndarray( ydtype, buf, [], [ 0 ], 0, yorder );\n\t} else {\n\t\tbuf = buffer( ydtype, x.length || numel( shape ) ); // WARNING: `x.length` is a property found on ndarray instances, but not strictly necessary to describe an ndarray; accordingly, used here to avoid unnecessary computation, but a potential source of bugs if provided an ndarray-like object having a `length` property which is not equal to the product of the dimensions.\n\t\ty = ndarray( ydtype, buf, shape, shape2strides( shape, yorder ), 0, yorder ); // eslint-disable-line max-len\n\t}\n\tfcn( x, y );\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ndarrayfcn;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Resolves an output array data type.\n*\n* @private\n* @param {string} xdtype - input array data type\n* @param {string} policy - policy determining an output array data type\n* @throws {Error} unsupported policy\n* @returns {string} output array data type\n*/\nfunction resolve( xdtype, policy ) {\n\tswitch ( policy ) {\n\tcase 'same':\n\t\treturn xdtype;\n\tcase 'floating-point':\n\t\t// 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.\n\t\tif (\n\t\t\txdtype === 'float64' ||\n\t\t\txdtype === 'float32' ||\n\t\t\txdtype === 'generic' ||\n\t\t\txdtype === 'complex128' ||\n\t\t\txdtype === 'complex64'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'float64'; // TODO: constants/math/default-real-floating-point-dtype?\n\tcase 'real floating-point':\n\t\tif (\n\t\t\txdtype === 'float64' ||\n\t\t\txdtype === 'float32' ||\n\t\t\txdtype === 'generic'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'float64';\n\tcase 'complex floating-point':\n\t\tif (\n\t\t\txdtype === 'complex128' ||\n\t\t\txdtype === 'complex64'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'complex128'; // TODO: constants/math/default-complex-floating-point-dtype?\n\tdefault:\n\t\tthrow new Error( format( 'invalid option. Unsupported policy for determining an output array data type. Option: `%s`.', policy ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = resolve;\n", "{\n\t\"output_dtype_policy\": \"floating-point\"\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isNull = require( '@stdlib/assert-is-null' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates a resolution table object.\n*\n* @private\n* @param {Object} out - destination object\n* @param {Object} table - resolution table object\n* @param {(Function|null)} [table.number] - function to invoke upon receiving a number\n* @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number\n* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object\n* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var out = {};\n* var table = {\n* 'number': null,\n* 'complex': null,\n* 'array': null,\n* 'ndarray': null\n* };\n* var err = validate( out, table );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( out, table ) {\n\tvar fields;\n\tvar tmp;\n\tvar key;\n\tvar i;\n\n\tif ( !isPlainObject( table ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Resolution table must be an object. Value: `%s`.', table ) );\n\t}\n\tfields = objectKeys( out );\n\tfor ( i = 0; i < fields.length; i++ ) {\n\t\tkey = fields[ i ];\n\t\tif ( hasOwnProp( table, key ) ) {\n\t\t\ttmp = table[ key ];\n\t\t\tif ( !isFunction( tmp ) && !isNull( tmp ) ) {\n\t\t\t\treturn new TypeError( format( 'invalid argument. Resolution table `%s` field value must be either a function or null. Value: `%s`.', key, tmp ) );\n\t\t\t}\n\t\t\tout[ key ] = tmp;\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "[\n\t\"same\",\n\t\"floating-point\",\n \"real floating-point\",\n \"complex floating-point\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/assert-contains' );\nvar format = require( '@stdlib/string-format' );\nvar POLICIES = require( './policies.json' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Object} options - options\n* @param {string} [options.output_dtype_policy] - policy for determining the output array data type\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'output_dtype_policy': 'float'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isPlainObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'output_dtype_policy' ) ) {\n\t\topts.policy = options.output_dtype_policy;\n\t\tif ( !contains( POLICIES, opts.policy ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported output array data type policy. Option: `%s`.', 'output_dtype_policy', opts.policy ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/assert-contains' );\nvar orders = require( '@stdlib/ndarray-orders' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar ORDERS = orders();\nvar DTYPES = dtypes();\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Object} options - options\n* @param {string} [options.dtype] - output array data type\n* @param {string} [options.order] - output array order\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'order': 'row-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isPlainObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( DTYPES, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'dtype', opts.dtype ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !contains( ORDERS, opts.order ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar dtype = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayfcn = require( './ndarray.js' );\nvar odtype = require( './resolve_output_dtype.js' );\nvar defaults = require( './defaults.json' );\nvar validateTable = require( './validate_table.js' );\nvar validateOptions = require( './validate_options.js' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function which dispatches to specified functions based on input argument types.\n*\n* @param {Object} table - resolution table object\n* @param {(Function|null)} [table.number] - function to invoke upon receiving a number\n* @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number\n* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object\n* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object\n* @param {Options} [options] - options\n* @param {string} [options.output_dtype_policy='floating-point'] - policy for determining the output array data type\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} first argument must have valid table fields\n* @throws {Error} each table field value must be either a function or `null`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} dispatch function\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var strided = require( '@stdlib/math-strided-special-abs' );\n* var dispatcher = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var nd = dispatcher( unary, types, data, 2, 1, 1 );\n*\n* var table = {\n* 'number': base,\n* 'complex': null,\n* 'array': strided,\n* 'ndarray': nd\n* };\n*\n* var abs = dispatch( table, {\n* 'output_dtype_policy': 'same'\n* });\n*\n* var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );\n*\n* var y = abs( x );\n* // returns <Float64Array>[ 1.0, 2.0, 3.0 ]\n*/\nfunction dispatch( table, options ) {\n\tvar OPTS;\n\tvar err;\n\tvar fcn;\n\tvar t;\n\n\tt = {\n\t\t'number': null,\n\t\t'complex': null,\n\t\t'array': null,\n\t\t'ndarray': null\n\t};\n\terr = validateTable( t, table );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\tOPTS = {\n\t\t'policy': defaults.output_dtype_policy\n\t};\n\tif ( arguments.length > 1 ) {\n\t\terr = validateOptions( OPTS, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tfcn = dispatcher;\n\tsetReadOnly( fcn, 'assign', assign );\n\treturn fcn;\n\n\t/**\n\t* Function interface which performs dispatch.\n\t*\n\t* @private\n\t* @param {(ndarray|Collection|number|Complex)} x - input value\n\t* @param {Options} [options] - options\n\t* @param {string} [options.dtype] - output array data type\n\t* @param {string} [options.order] - output array order (row-major or column-major)\n\t* @throws {TypeError} first argument must be a supported data type\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {(ndarray|Collection|number|Complex)} results\n\t*/\n\tfunction dispatcher( x ) {\n\t\tvar xdtype;\n\t\tvar ydtype;\n\t\tvar opts;\n\t\tvar err;\n\t\tvar y;\n\t\tif ( isNumber( x ) ) {\n\t\t\tif ( t.number ) {\n\t\t\t\treturn t.number( x );\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. Providing a number is not supported.' );\n\t\t}\n\t\tif ( isComplexLike( x ) ) {\n\t\t\tif ( t.complex ) {\n\t\t\t\treturn t.complex( x );\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. Providing a complex number is not supported.' );\n\t\t}\n\t\topts = {};\n\t\tif ( arguments.length > 1 ) {\n\t\t\terr = validate( opts, arguments[ 1 ] );\n\t\t\tif ( err ) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\tif ( isndarrayLike( x ) ) {\n\t\t\tif ( t.ndarray === null ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Providing an ndarray is not supported.' );\n\t\t\t}\n\t\t\tydtype = opts.dtype || odtype( x.dtype, OPTS.policy );\n\t\t\treturn ndarrayfcn( t.ndarray, x, ydtype, opts.order || x.order );\n\t\t}\n\t\tif ( isCollection( x ) ) {\n\t\t\tif ( t.array === null ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Providing an array-like object is not supported.' );\n\t\t\t}\n\t\t\txdtype = dtype( x ) || 'generic';\n\t\t\tydtype = opts.dtype || odtype( xdtype, OPTS.policy );\n\t\t\ty = buffer( ydtype, x.length );\n\t\t\tt.array( x.length, xdtype, x, 1, ydtype, y, 1 );\n\t\t\treturn y;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );\n\t}\n\n\t/**\n\t* Function interface which performs dispatch and assigns results to a provided output array.\n\t*\n\t* @private\n\t* @param {(ndarray|Collection)} x - input array\n\t* @param {(ndarray|Collection)} y - output array\n\t* @throws {TypeError} first argument must be a supported data type\n\t* @throws {TypeError} second argument must be a supported data type\n\t* @throws {TypeError} first and second argument must be the same \"kind\" (i.e., either both ndarrays or both collections)\n\t* @throws {RangeError} output array must have sufficient elements\n\t* @throws {Error} unable to broadcast the input array against the output array\n\t* @returns {(ndarray|Collection)} output array\n\t*/\n\tfunction assign( x, y ) {\n\t\tvar xsh;\n\t\tvar ysh;\n\t\tvar i;\n\t\tif ( isndarrayLike( x ) ) {\n\t\t\tif ( isndarrayLike( y ) ) {\n\t\t\t\txsh = x.shape;\n\t\t\t\tysh = y.shape;\n\n\t\t\t\t// Check whether we need to broadcast `x`...\n\t\t\t\tif ( xsh.length === ysh.length ) {\n\t\t\t\t\tfor ( i = 0; i < xsh.length; i++ ) {\n\t\t\t\t\t\t// Check whether dimensions match...\n\t\t\t\t\t\tif ( xsh[ i ] !== ysh[ i ] ) {\n\t\t\t\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...\n\t\t\t\t\t\t\tx = broadcast( x, ysh );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// If we are provided arrays with different ranks (i.e., number of dimensions), assume we need to broadcast, delegating to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...\n\t\t\t\t\tx = broadcast( x, ysh );\n\t\t\t\t}\n\t\t\t\tt.ndarray( x, y );\n\t\t\t\treturn y;\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. If the first argument is an ndarray, the second argument must be an ndarray.' );\n\t\t}\n\t\tif ( isCollection( x ) ) {\n\t\t\tif ( isCollection( y ) ) {\n\t\t\t\tif ( y.length !== x.length ) {\n\t\t\t\t\tthrow new RangeError( 'invalid argument. Output array must have the same number of elements (i.e., length) as the input array.' );\n\t\t\t\t}\n\t\t\t\tt.array( x.length, dtype( x ) || 'generic', x, 1, dtype( y ) || 'generic', y, 1 );\n\t\t\t\treturn y;\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.' );\n\t\t}\n\t\tif ( isNumber( x ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Providing a number is not supported. Consider providing a zero-dimensional ndarray containing the numeric value.' );\n\t\t}\n\t\tif ( isComplexLike( x ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Providing a complex number is not supported. Consider providing a zero-dimensional ndarray containing the complex number value.' );\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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* Return a function which dispatches to specified functions based on input argument types.\n*\n* @module @stdlib/math-tools-unary\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var strided = require( '@stdlib/math-strided-special-abs' );\n* var dispatcher = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/math-tools-unary' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var nd = dispatcher( unary, types, data, 2, 1, 1 );\n*\n* var table = {\n* 'number': base,\n* 'complex': null,\n* 'array': strided,\n* 'ndarray': nd\n* };\n*\n* var abs = dispatch( table );\n*\n* var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );\n* var y = abs( x );\n* // returns <Float64Array>[ 1.0, 2.0, 3.0 ]\n*/\n\n// MAIN //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,sBAAuB,EAC1CC,EAAS,QAAS,6BAA8B,EAChDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAO,QAAS,iCAAkC,EAetD,SAASC,EAAYC,EAAKC,EAAGC,EAAQC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAGJ,OAAAF,EAAQN,EAAMG,EAAE,KAAM,EACjBG,EAAM,SAAW,GACrBC,EAAMV,EAAQO,EAAQ,CAAE,EACxBI,EAAIZ,EAASQ,EAAQG,EAAK,CAAC,EAAG,CAAE,CAAE,EAAG,EAAGF,CAAO,IAE/CE,EAAMV,E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GM,CAAI,EAEvB,OAAAT,EAAE,QAASG,EAAGI,CAAE,EACTA,CACR,CACA,MAAM,IAAI,UAAW,gGAAiG,CACvH,CACA,GAAKxB,EAAcoB,CAAE,EAAI,CACxB,GAAKpB,EAAcwB,CAAE,EAAI,CACxB,GAAKA,EAAE,SAAWJ,EAAE,OACnB,MAAM,IAAI,WAAY,yGAA0G,EAEjI,OAAAH,EAAE,MAAOG,EAAE,OAAQnB,EAAOmB,CAAE,GAAK,UAAWA,EAAG,EAAGnB,EAAOuB,CAAE,GAAK,UAAWA,EAAG,CAAE,EACzEA,CACR,CACA,MAAM,IAAI,UAAW,oHAAqH,CAC3I,CACA,MAAK3B,EAAUuB,CAAE,EACV,IAAI,UAAW,oIAAqI,EAEtJtB,EAAesB,CAAE,EACf,IAAI,UAAW,mJAAoJ,EAEpK,IAAI,UAAWhB,EAAQ,wFAAyFgB,CAAE,CAAE,CAC3H,CACD,CAKAzB,EAAO,QAAUgB,KCvLjB,IAAIiB,GAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_ndarray", "__commonJSMin", "exports", "module", "ndarray", "buffer", "shape2strides", "numel", "copy", "ndarrayfcn", "fcn", "x", "ydtype", "yorder", "shape", "buf", "y", "require_resolve_output_dtype", "__commonJSMin", "exports", "module", "format", "resolve", "xdtype", "policy", "require_defaults", "__commonJSMin", "exports", "module", "require_validate_table", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "isFunction", "isNull", "objectKeys", "format", "validate", "out", "table", "fields", "tmp", "key", "require_policies", "__commonJSMin", "exports", "module", "require_validate_options", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "contains", "format", "POLICIES", "validate", "opts", "options", "require_validate", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "contains", "orders", "dtypes", "format", "ORDERS", "DTYPES", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNumber", "isComplexLike", "isndarrayLike", "isCollection", "dtype", "buffer", "broadcast", "format", "ndarrayfcn", "odtype", "defaults", "validateTable", "validateOptions", "validate", "dispatch", "table", "options", "OPTS", "err", "fcn", "t", "dispatcher", "assign", "x", "xdtype", "ydtype", "opts", "y", "xsh", "ysh", "i", "main"]
3
+ "sources": ["../lib/validate.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar orders = require( '@stdlib/ndarray-orders' );\nvar join = require( '@stdlib/array-base-join' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Object} options - options\n* @param {*} [options.dtype] - output array data type\n* @param {string} [options.order] - output array order\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var opts = {};\n* var options = {\n* 'order': 'row-major'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isPlainObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, String( opts.dtype ) ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'order', join( orders(), '\", \"' ), opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isInputCastingPolicy = require( '@stdlib/ndarray-base-assert-is-input-casting-policy' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar unaryOutputDataType = require( '@stdlib/ndarray-base-unary-output-dtype' );\nvar unaryInputCastingDataType = require( '@stdlib/ndarray-base-unary-input-casting-dtype' );\nvar baseAssign = require( '@stdlib/ndarray-base-assign' );\nvar baseEmpty = require( '@stdlib/ndarray-base-empty' );\nvar maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar empty = require( '@stdlib/ndarray-empty' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function which performs element-wise computation.\n*\n* @param {Function} fcn - function which applies a unary function to each element in an ndarray\n* @param {ArrayLikeObject<StringArray>} idtypes - list containing lists of supported input data types for each ndarray argument\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - dispatch policies\n* @param {string} policies.output - output data type policy\n* @param {string} policies.casting - input ndarray casting policy\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @returns {Function} function which performs element-wise computation\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var dispatcher = dispatch( unary, types, data, 2, 1, 1 );\n*\n* var idt = [ 'float64', 'float32', 'generic' ];\n* var odt = idt;\n*\n* var policies = {\n* 'output': 'real_and_generic',\n* 'casting': 'none'\n* };\n* var abs = factory( dispatcher, [ idt ], odt, policies );\n*\n* var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );\n* // returns <ndarray>\n*\n* var y = abs( x );\n* // returns <ndarray>\n*\n* var arr = ndarray2array( y );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]\n*/\nfunction factory( fcn, idtypes, odtypes, policies ) {\n\tvar POLICIES;\n\tvar dt;\n\tvar i;\n\tif ( !isFunction( fcn ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\tif ( !isInputCastingPolicy( policies.casting ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported casting policy. Value: `%s`.', policies.casting ) );\n\t}\n\tPOLICIES = {\n\t\t'output': policies.output,\n\t\t'casting': policies.casting\n\t};\n\tsetReadOnly( unary, 'assign', assign );\n\treturn unary;\n\n\t/**\n\t* Performs element-wise computation.\n\t*\n\t* @private\n\t* @param {ndarray} x - input array\n\t* @param {Options} [options] - options\n\t* @param {*} [options.dtype] - output array data type\n\t* @param {string} [options.order] - output array order\n\t* @throws {TypeError} first argument must be an ndarray\n\t* @throws {TypeError} first argument must have a supported data type\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndarray} output array\n\t*/\n\tfunction unary( x ) {\n\t\tvar opts;\n\t\tvar err;\n\t\tvar xsh;\n\t\tvar ord;\n\t\tvar xdt;\n\t\tvar ydt;\n\t\tvar tmp;\n\t\tvar dt;\n\t\tvar y;\n\n\t\tif ( !isndarrayLike( x ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t\t}\n\t\txdt = getDType( x );\n\t\tif ( !contains( idtypes[ 0 ], xdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must have one of the following data types: \"%s\". Data type: `%s`.', join( idtypes[ 0 ], '\", \"' ), xdt ) );\n\t\t}\n\t\topts = {};\n\t\tif ( arguments.length > 1 ) {\n\t\t\terr = validate( opts, odtypes, arguments[ 1 ] );\n\t\t\tif ( err ) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\txsh = getShape( x );\n\t\tord = getOrder( x );\n\n\t\t// Initialize an output array:\n\t\tydt = opts.dtype || unaryOutputDataType( xdt, POLICIES.output );\n\t\ty = empty( xsh, {\n\t\t\t'dtype': ydt,\n\t\t\t'order': opts.order || ord\n\t\t});\n\n\t\t// Determine whether we need to cast the input ndarray...\n\t\tdt = unaryInputCastingDataType( xdt, ydt, POLICIES.casting );\n\t\tif ( xdt !== dt ) {\n\t\t\t// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility\n\t\t\ttmp = baseEmpty( dt, xsh, ord );\n\t\t\tbaseAssign( [ x, tmp ] );\n\t\t\tx = tmp;\n\t\t}\n\t\tfcn( x, y );\n\t\treturn y;\n\t}\n\n\t/**\n\t* Performs element-wise computation and assigns results to a provided output ndarray.\n\t*\n\t* @private\n\t* @param {ndarray} x - input array\n\t* @param {ndarray} y - output array\n\t* @throws {TypeError} first argument must be an ndarray\n\t* @throws {TypeError} first argument must have a supported data type\n\t* @throws {TypeError} second argument must be an ndarray\n\t* @throws {Error} unable to broadcast the input array against the output array\n\t* @returns {ndarray} output array\n\t*/\n\tfunction assign( x, y ) {\n\t\tvar xdt;\n\t\tvar tmp;\n\t\tvar dt;\n\n\t\tif ( !isndarrayLike( x ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t\t}\n\t\tif ( !isndarrayLike( y ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) );\n\t\t}\n\t\t// Validate the input ndarray data type in order to maintain similar behavior to above...\n\t\txdt = getDType( x );\n\t\tif ( !contains( idtypes[ 0 ], xdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must have one of the following data types: \"%s\". Data type: `%s`.', join( idtypes[ 0 ], '\", \"' ), xdt ) );\n\t\t}\n\t\t// Determine whether we need to cast the input ndarray...\n\t\tdt = unaryInputCastingDataType( xdt, getDType( y ), POLICIES.casting );\n\t\tif ( xdt !== dt ) {\n\t\t\t// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility\n\t\t\ttmp = baseEmpty( dt, getShape( x ), getOrder( x ) );\n\t\t\tbaseAssign( [ x, tmp ] );\n\t\t\tx = tmp;\n\t\t}\n\t\tfcn( maybeBroadcastArray( x, getShape( y ) ), y );\n\t\treturn y;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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* Return a function which performs element-wise computation by applying a unary function to each element in an input ndarray.\n*\n* @module @stdlib/math-tools-unary\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var factory = require( '@stdlib/math-tools-unary' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var dispatcher = dispatch( unary, types, data, 2, 1, 1 );\n*\n* var idt = [ 'float64', 'float32', 'generic' ];\n* var odt = idt;\n*\n* var policies = {\n* 'output': 'real_and_generic',\n* 'casting': 'none'\n* };\n* var abs = factory( dispatcher, [ idt ], odt, policies );\n*\n* var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );\n* // returns <ndarray>\n*\n* var y = abs( x );\n* // returns <ndarray>\n*\n* var arr = ndarray2array( y );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]\n*/\n\n// MAIN //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,sCAAuC,EAC1DC,EAAW,QAAS,oCAAqC,EACzDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,yBAA0B,EAC1CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMV,EAAeU,CAAQ,EAGxBT,EAAYS,EA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AE,EAAGA,CAAE,EACzCA,CACR,CACD,CAKAzC,EAAO,QAAUuB,KCtLjB,IAAImB,GAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_validate", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "isOrder", "contains", "orders", "join", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isndarrayLike", "isFunction", "isObject", "isCollection", "isOutputDataTypePolicy", "isInputCastingPolicy", "isDataType", "contains", "unaryOutputDataType", "unaryInputCastingDataType", "baseAssign", "baseEmpty", "maybeBroadcastArray", "getShape", "getOrder", "getDType", "empty", "everyBy", "join", "format", "validate", "factory", "fcn", "idtypes", "odtypes", "policies", "POLICIES", "dt", "i", "unary", "assign", "x", "opts", "err", "xsh", "ord", "xdt", "ydt", "tmp", "y", "main"]
7
7
  }
@@ -21,213 +21,127 @@
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
23
  import { ArrayLike } from '@stdlib/types/array';
24
- import { ndarray } from '@stdlib/types/ndarray';
25
-
26
- /**
27
- * Function which operates on a number.
28
- *
29
- * @param x - input value
30
- * @returns return value
24
+ import { OutputPolicy, InputCastingPolicy, DataType, Order, typedndarray } from '@stdlib/types/ndarray';/**
25
+ * Input array.
31
26
  */
32
- type ScalarFunction = ( x: number ) => number; // FIXME: add complex number support
27
+ type InputArray<T> = typedndarray<T>;
33
28
 
34
29
  /**
35
- * Function which operates on each element in a strided input array `x` and assigns the results to elements in a strided output array `y`.
36
- *
37
- * @param N - number of indexed elements
38
- * @param x - input array
39
- * @param strideX - `x` stride length
40
- * @param y - destination array
41
- * @param strideY - `y` stride length
42
- * @returns `y` or `undefined`
30
+ * Output array.
43
31
  */
44
- type StridedArrayFunction = ( N: number, x: ArrayLike<number>, strideX: number, y: ArrayLike<number>, strideY: number ) => ArrayLike<number> | void;
32
+ type OutputArray<U> = typedndarray<U>;
45
33
 
46
34
  /**
47
- * Function which operates on each element in a strided input array `x` and assigns the results to elements in a strided output array `y` using alternative (i.e., ndarray) indexing semantics.
48
- *
49
- * @param N - number of indexed elements
50
- * @param x - input array
51
- * @param strideX - `x` stride length
52
- * @param offsetX - starting index for `x`
53
- * @param y - destination array
54
- * @param strideY - `y` stride length
55
- * @param offsetY - starting index for `y`
56
- * @returns `y` or `undefined`
35
+ * Interface defining options.
57
36
  */
58
- type StridedArrayFunctionWithOffsets = ( N: number, x: ArrayLike<number>, strideX: number, offsetX: number, y: ArrayLike<number>, strideY: number, offsetY: number ) => ArrayLike<number> | void;
37
+ interface Options {
38
+ /**
39
+ * Output array data type.
40
+ */
41
+ dtype?: DataType;
59
42
 
60
- /**
61
- * Interface describing a resolution table object.
62
- */
63
- interface Table {
64
43
  /**
65
- * Strided look-up table for scalar arguments.
66
- *
67
- * ## Notes
68
- *
69
- * - The strided look-up table should be comprised as follows:
70
- *
71
- * ```text
72
- * [ <dtype>, <fcn>, <dtype>, <fcn>, ... ]
73
- * ```
44
+ * Output array order.
74
45
  */
75
- scalar?: ArrayLike<string | ScalarFunction>;
46
+ order?: Order;
47
+ }
76
48
 
49
+ /**
50
+ * Dispatch policies.
51
+ */
52
+ interface Policies {
77
53
  /**
78
- * Strided look-up table for array-like object arguments.
79
- *
80
- * ## Notes
81
- *
82
- * - The strided look-up table should be comprised as follows:
83
- *
84
- * ```text
85
- * [ <dtype>, <fcn>, <dtype>, <fcn>, ... ]
86
- * ```
54
+ * Output data type policy.
87
55
  */
88
- array?: ArrayLike<string | StridedArrayFunction>;
56
+ output: OutputPolicy;
89
57
 
90
58
  /**
91
- * Strided look-up table for ndarray arguments.
92
- *
93
- * ## Notes
94
- *
95
- * - The strided look-up table should be comprised as follows:
96
- *
97
- * ```text
98
- * [ <dtype>, <fcn>, <dtype>, <fcn>, ... ]
99
- * ```
59
+ * Input ndarray casting policy.
100
60
  */
101
- ndarray?: ArrayLike<string | StridedArrayFunctionWithOffsets>;
61
+ casting: InputCastingPolicy;
102
62
  }
103
63
 
104
64
  /**
105
- * Interface describing a function which dispatches to a specific function based on input argument types.
65
+ * Unary function.
66
+ *
67
+ * @param x - input ndarray
68
+ * @param y - output ndarray
69
+ * @returns result
106
70
  */
107
- interface DispatchFunction {
108
- /**
109
- * Dispatches to a function which operates on a number.
110
- *
111
- * @param x - input value
112
- * @returns return value
113
- *
114
- * @example
115
- * var nabs = require( '@stdlib/math-base-special-abs' );
116
- *
117
- * var table = {
118
- * 'scalar': [
119
- * 'number', nabs
120
- * ]
121
- * };
122
- *
123
- * var abs = dispatch( table );
124
- *
125
- * var y = abs( -1.0 );
126
- * // returns 1.0
127
- */
128
- ( x: number ): number;
71
+ type UnaryFunction<T = unknown, U = unknown> = ( x: InputArray<T>, y: OutputArray<U> ) => OutputArray<U> | void;
129
72
 
73
+ /**
74
+ * Interface for performing element-wise computation.
75
+ */
76
+ interface Unary {
130
77
  /**
131
- * Dispatches to a function which operates on an ndarray.
132
- *
133
- * @param x - input value
134
- * @returns return value
135
- *
136
- * @example
137
- * var dabs = require( '@stdlib/math-strided-special-dabs' );
138
- * var sabs = require( '@stdlib/math-strided-special-sabs' );
139
- * var gabs = require( '@stdlib/math-strided-special-abs' );
140
- * var array = require( '@stdlib/ndarray-array' );
78
+ * Performs element-wise computation.
141
79
  *
142
- * var table = {
143
- * 'ndarray': [
144
- * 'float64', dabs.ndarray,
145
- * 'float32', sabs.ndarray,
146
- * 'generic', gabs.ndarray
147
- * ]
148
- * };
149
- *
150
- * var abs = dispatch( table );
151
- *
152
- * var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
153
- * var y = abs( x );
154
- * // returns <ndarray>
155
- *
156
- * var v = y.get( 0, 1 );
157
- * // returns 2.0
80
+ * @param x - input array
81
+ * @param options - options
82
+ * @returns output array
158
83
  */
159
- ( x: ndarray ): ndarray;
84
+ <T = unknown, U = unknown>( x: InputArray<T>, options?: Options ): OutputArray<U>; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. In principle, as well, based on the policy, it is possible to know more exactly which `InputArray` types are actually allowed.
160
85
 
161
86
  /**
162
- * Dispatches to a function which operates on an array-like object.
163
- *
164
- * @param x - input value
165
- * @returns return value
166
- *
167
- * @example
168
- * var dabs = require( '@stdlib/math-strided-special-dabs' );
169
- * var sabs = require( '@stdlib/math-strided-special-sabs' );
170
- * var gabs = require( '@stdlib/math-strided-special-abs' );
171
- * var Float64Array = require( '@stdlib/array-float64' );
87
+ * Performs element-wise computation and assigns results to a provided output ndarray.
172
88
  *
173
- * var table = {
174
- * 'array': [
175
- * 'float64', dabs,
176
- * 'float32', sabs,
177
- * 'generic', gabs
178
- * ]
179
- * };
180
- *
181
- * var abs = dispatch( table );
182
- *
183
- * var x = new Float64Array( [ -1.0, -2.0 ] );
184
- * var y = abs( x );
185
- * // returns <Float64Array>[ 1.0, 2.0 ]
89
+ * @param x - input array
90
+ * @param y - output array
91
+ * @returns output array
186
92
  */
187
- ( x: ArrayLike<number> ): ArrayLike<number>;
93
+ assign<T = unknown, U = unknown, V extends OutputArray<U> = OutputArray<U>>( x: InputArray<T>, y: V ): V;
188
94
  }
189
95
 
190
96
  /**
191
- * Returns a function which dispatches to specified functions based on input argument types.
97
+ * Returns a function which performs element-wise computation.
192
98
  *
193
- * @param table - resolution table object
194
- * @throws must provide valid table fields
195
- * @throws table field values must be array-like objects having an even number of elements
196
- * @throws table field values must consist of dtype-function pairs
197
- * @returns dispatch function
99
+ * @param fcn - function applies a unary function to each element in an ndarray
100
+ * @param idtypes - list containing lists of supported input data types for each ndarray argument
101
+ * @param odtypes - list of supported output data types
102
+ * @param policies - dispatch policies
103
+ * @returns function which performs element-wise computation
198
104
  *
199
105
  * @example
200
- * var nabs = require( '@stdlib/math-base-special-abs' );
201
- * var dabs = require( '@stdlib/math-strided-special-dabs' );
202
- * var sabs = require( '@stdlib/math-strided-special-sabs' );
203
- * var gabs = require( '@stdlib/math-strided-special-abs' );
204
- * var Float64Array = require( '@stdlib/array-float64' );
106
+ * var base = require( '@stdlib/math-base-special-abs' );
107
+ * var dispatch = require( '@stdlib/ndarray-dispatch' );
108
+ * var unary = require( '@stdlib/ndarray-base-unary' );
109
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
110
+ * var array = require( '@stdlib/ndarray-array' );
111
+ *
112
+ * var types = [
113
+ * 'float64', 'float64',
114
+ * 'float32', 'float32',
115
+ * 'generic', 'generic'
116
+ * ];
117
+ * var data = [
118
+ * base,
119
+ * base,
120
+ * base
121
+ * ];
122
+ * var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
205
123
  *
206
- * var table = {
207
- * 'scalar': [
208
- * 'number', nabs
209
- * ],
210
- * 'array': [
211
- * 'float64', dabs,
212
- * 'float32', sabs,
213
- * 'generic', gabs
214
- * ],
215
- * 'ndarray': [
216
- * 'float64', dabs.ndarray,
217
- * 'float32', sabs.ndarray,
218
- * 'generic', gabs.ndarray
219
- * ]
124
+ * var idt = [ 'float64', 'float32', 'generic' ];
125
+ * var odt = idt;
126
+ *
127
+ * var policies = {
128
+ * 'output': 'real_and_generic',
129
+ * 'casting': 'none'
220
130
  * };
131
+ * var abs = factory( dispatcher, [ idt ], odt, policies );
221
132
  *
222
- * var abs = dispatch( table );
133
+ * var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
134
+ * // returns <ndarray>
223
135
  *
224
- * var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );
225
136
  * var y = abs( x );
226
- * // returns <Float64Array>[ 1.0, 2.0, 3.0 ]
137
+ * // returns <ndarray>
138
+ *
139
+ * var arr = ndarray2array( y );
140
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
227
141
  */
228
- declare function dispatch( table: Table ): DispatchFunction;
142
+ declare function factory<T = unknown, U = unknown>( fcn: UnaryFunction<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policies: Policies ): Unary;
229
143
 
230
144
 
231
145
  // EXPORTS //
232
146
 
233
- export = dispatch;
147
+ export = factory;
package/lib/index.js CHANGED
@@ -19,17 +19,17 @@
19
19
  'use strict';
20
20
 
21
21
  /**
22
- * Return a function which dispatches to specified functions based on input argument types.
22
+ * Return a function which performs element-wise computation by applying a unary function to each element in an input ndarray.
23
23
  *
24
24
  * @module @stdlib/math-tools-unary
25
25
  *
26
26
  * @example
27
27
  * var base = require( '@stdlib/math-base-special-abs' );
28
- * var strided = require( '@stdlib/math-strided-special-abs' );
29
- * var dispatcher = require( '@stdlib/ndarray-dispatch' );
28
+ * var dispatch = require( '@stdlib/ndarray-dispatch' );
30
29
  * var unary = require( '@stdlib/ndarray-base-unary' );
31
- * var Float64Array = require( '@stdlib/array-float64' );
32
- * var dispatch = require( '@stdlib/math-tools-unary' );
30
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
31
+ * var array = require( '@stdlib/ndarray-array' );
32
+ * var factory = require( '@stdlib/math-tools-unary' );
33
33
  *
34
34
  * var types = [
35
35
  * 'float64', 'float64',
@@ -41,20 +41,25 @@
41
41
  * base,
42
42
  * base
43
43
  * ];
44
- * var nd = dispatcher( unary, types, data, 2, 1, 1 );
44
+ * var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
45
45
  *
46
- * var table = {
47
- * 'number': base,
48
- * 'complex': null,
49
- * 'array': strided,
50
- * 'ndarray': nd
46
+ * var idt = [ 'float64', 'float32', 'generic' ];
47
+ * var odt = idt;
48
+ *
49
+ * var policies = {
50
+ * 'output': 'real_and_generic',
51
+ * 'casting': 'none'
51
52
  * };
53
+ * var abs = factory( dispatcher, [ idt ], odt, policies );
52
54
  *
53
- * var abs = dispatch( table );
55
+ * var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
56
+ * // returns <ndarray>
54
57
  *
55
- * var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );
56
58
  * var y = abs( x );
57
- * // returns <Float64Array>[ 1.0, 2.0, 3.0 ]
59
+ * // returns <ndarray>
60
+ *
61
+ * var arr = ndarray2array( y );
62
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
58
63
  */
59
64
 
60
65
  // MAIN //