diff --git a/lib/node_modules/@stdlib/math/base/special/sin/package.json b/lib/node_modules/@stdlib/math/base/special/sin/package.json index c407ebd5202f..7f377e131081 100644 --- a/lib/node_modules/@stdlib/math/base/special/sin/package.json +++ b/lib/node_modules/@stdlib/math/base/special/sin/package.json @@ -63,5 +63,78 @@ "trigonometry", "radians", "angle" - ] + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "sin", + "alias": "sin", + "pkg_desc": "compute the sine of a number", + "desc": "computes the sine of a number", + "short_desc": "sine value", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + }, + "example_values": [ + 64, + 27, + 0, + 0.1, + -9, + 8, + -1, + 125, + -10.2, + 11.3, + -12.4, + 3.5, + -1.6, + 15.7, + -16, + 17.9, + -188, + 19.11, + -200, + 21.15 + ] + } + ], + "output_policy": "same", + "returns": { + "desc": "sine value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + } + }, + "keywords": [ + "abs", + "absolute", + "magnitude" + ], + "extra_keywords": [] + } + } } diff --git a/lib/node_modules/@stdlib/math/base/special/sqrt/package.json b/lib/node_modules/@stdlib/math/base/special/sqrt/package.json index 949ffa145e87..2e48013743c3 100644 --- a/lib/node_modules/@stdlib/math/base/special/sqrt/package.json +++ b/lib/node_modules/@stdlib/math/base/special/sqrt/package.json @@ -63,5 +63,80 @@ "root", "power", "number" - ] + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "sqrt", + "alias": "sqrt", + "pkg_desc": "round toward positive infinity", + "desc": "rounds toward positive infinity", + "short_desc": "ceil value", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + }, + "example_values": [ + 64, + 27, + 0, + 0.1, + -9, + 8, + -1, + 125, + -10.2, + 11.3, + -12.4, + 3.5, + -1.6, + 15.7, + -16, + 17.9, + -188, + 19.11, + -200, + 21.15 + ] + } + ], + "output_policy": "same", + "returns": { + "desc": "absolute value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + } + }, + "keywords": [ + "abs", + "absolute", + "magnitude" + ], + "extra_keywords": [ + "math.abs" + ] + } + } } diff --git a/lib/node_modules/@stdlib/math/base/special/sqrtf/package.json b/lib/node_modules/@stdlib/math/base/special/sqrtf/package.json index 70c0cea65789..a744b64da3e5 100644 --- a/lib/node_modules/@stdlib/math/base/special/sqrtf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/sqrtf/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/math/base/special/sqrtf", + "name": "@stdlib/math/base/special/cceil", "version": "0.0.0", - "description": "Compute the principal square root of a single-precision floating-point number.", + "description": "Round each component of a double-precision complex floating-point number toward positive infinity.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -56,12 +56,90 @@ "stdmath", "mathematics", "math", - "math.sqrtf", - "sqrtf", - "principal", - "square", - "root", - "power", + "math.ceil", + "ceil", + "cceil", + "round", + "integer", + "nearest", + "value", + "complex", + "cmplx", "number" - ] + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "sqrtf", + "alias": "sqrtf", + "pkg_desc": "round toward positive infinity", + "desc": "rounds toward positive infinity", + "short_desc": "ceil value", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float32" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + }, + "example_values": [ + 64, + 27, + 0, + 0.1, + -9, + 8, + -1, + 125, + -10.2, + 11.3, + -12.4, + 3.5, + -1.6, + 15.7, + -16, + 17.9, + -188, + 19.11, + -200, + 21.15 + ] + } + ], + "output_policy": "same", + "returns": { + "desc": "absolute value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float32" + } + }, + "keywords": [ + "abs", + "absolute", + "magnitude" + ], + "extra_keywords": [ + "math.abs" + ] + } + } } diff --git a/lib/node_modules/@stdlib/math/special/scripts/dtype_hierarchy.js b/lib/node_modules/@stdlib/math/special/scripts/dtype_hierarchy.js new file mode 100644 index 000000000000..90799c47f3ac --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/scripts/dtype_hierarchy.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Dtype precision hierarchy. +* +* @type {Object} +*/ +var DTYPE_HIERARCHY = { + 'int8': 1, + 'uint8': 1, + 'int16': 2, + 'uint16': 2, + 'int32': 3, + 'uint32': 3, + 'float32': 4, + 'float64': 5, + 'generic': 6 +}; + + +// EXPORTS // + +module.exports = DTYPE_HIERARCHY; diff --git a/lib/node_modules/@stdlib/math/special/scripts/function_database.json b/lib/node_modules/@stdlib/math/special/scripts/function_database.json new file mode 100644 index 000000000000..7df060a5803d --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/scripts/function_database.json @@ -0,0 +1,23 @@ +{ + "sqrt": { + "input_dtypes": "real_and_generic", + "output_dtypes": "real_floating_point", + "output_policy": "real_floating_point", + "scalar_kernels": { + "float32": "@stdlib/math/base/special/sqrtf", + "float64": "@stdlib/math/base/special/sqrt", + "generic": "@stdlib/math/base/special/sqrt" + } + }, + "sin": { + "input_dtypes": "real_and_generic", + "output_dtypes": "real_floating_point", + "output_policy": "real_floating_point", + "scalar_kernels": { + "float32": "@stdlib/math/base/special/sinf", + "float64": "@stdlib/math/base/special/sin", + "generic": "@stdlib/math/base/special/sin" + } + } +} + diff --git a/lib/node_modules/@stdlib/math/special/sin/lib/types.js b/lib/node_modules/@stdlib/math/special/sin/lib/types.js new file mode 100644 index 000000000000..ba8b4897156e --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/lib/types.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* This is a generated file. Do not edit directly. */ + +/* eslint-disable array-element-newline */ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); + + +// MAIN // + +var types = [ + // float32 (2) + dtypes.float32, dtypes.float32, + dtypes.float32, dtypes.float64, + + // float64 (1) + dtypes.float64, dtypes.float64, + + // int16 (2) + dtypes.int16, dtypes.float32, + dtypes.int16, dtypes.float64, + + // int32 (1) + dtypes.int32, dtypes.float64, + + // int8 (2) + dtypes.int8, dtypes.float32, + dtypes.int8, dtypes.float64, + + // uint16 (2) + dtypes.uint16, dtypes.float32, + dtypes.uint16, dtypes.float64, + + // uint32 (1) + dtypes.uint32, dtypes.float64, + + // uint8 (2) + dtypes.uint8, dtypes.float32, + dtypes.uint8, dtypes.float64 +]; + + +// EXPORTS // + +module.exports = types; diff --git a/lib/node_modules/@stdlib/math/special/sin/package.json b/lib/node_modules/@stdlib/math/special/sin/package.json new file mode 100644 index 000000000000..38c8f0e87423 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/math/special/sin", + "version": "0.0.0", + "description": "Compute the sine of a number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "math.sin", + "sin", + "sine", + "trig", + "trigonometry", + "radians", + "angle" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/math/special/sin/scripts/config.js b/lib/node_modules/@stdlib/math/special/sin/scripts/config.js new file mode 100644 index 000000000000..13d8ee48102b --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/scripts/config.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Configuration object. +* +* @private +* @type {Object} +*/ +var config = { + 'input_dtypes': 'real_and_generic', + 'output_dtypes': 'real_floating_point', + 'excluded_dtypes': [ 'float16', 'uint8c' ] +}; + + +// EXPORTS // + +module.exports = config; diff --git a/lib/node_modules/@stdlib/math/special/sin/scripts/generate_files.js b/lib/node_modules/@stdlib/math/special/sin/scripts/generate_files.js new file mode 100644 index 000000000000..7828f33b516f --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/scripts/generate_files.js @@ -0,0 +1,285 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var join = require( 'path' ).join; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var licenseHeader = require( '@stdlib/_tools/licenses/header' ); +var currentYear = require( '@stdlib/time/current-year' ); +var generateMatchesTable = require( './script.js' ); +var pkg = require( './../package.json' ); + + +// FUNCTIONS // + +/** +* Groups matches by input data type. +* +* @private +* @param {Array} matches - array of match entries +* @returns {Object} object containing grouped matches, input types array, and reordered matches +*/ +function groupMatchesByInputType( matches ) { + var reorderedMatches = []; + var inputTypes = []; + var inputType; + var grouped = {}; + var i; + var j; + + for ( i = 0; i < matches.length; i++ ) { + inputType = matches[ i ][ 0 ]; + if ( !grouped[ inputType ] ) { + grouped[ inputType ] = []; + inputTypes.push( inputType ); + } + grouped[ inputType ].push( matches[ i ][ 1 ] ); + } + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + for ( j = 0; j < matches.length; j++ ) { + if ( matches[ j ][ 0 ] === inputType ) { + reorderedMatches.push( matches[ j ] ); + } + } + } + + return { + 'grouped': grouped, + 'inputTypes': inputTypes, + 'reorderedMatches': reorderedMatches + }; +} + +/** +* Generates the types.js file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @returns {string} types.js file content +*/ +function generateTypesFile( matches, header ) { + var outputTypes; + var inputTypes; + var inputType; + var grouped; + var result; + var jsOut; + var i; + var j; + + jsOut = header; + jsOut += '\n'; + jsOut += '/* eslint-disable array-element-newline */\n\n'; + jsOut += '\'use strict\';\n\n'; + jsOut += '// MODULES //\n\n'; + jsOut += 'var dtypes = require( \'@stdlib/ndarray/dtypes\' );\n\n\n'; + jsOut += '// MAIN //\n\n'; + jsOut += 'var types = [\n'; + + // Group matches by input dtype... + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + inputTypes = result.inputTypes; + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + jsOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + jsOut += '\tdtypes.' + inputType + ', dtypes.' + outputTypes[ j ]; + if ( i < inputTypes.length - 1 || j < outputTypes.length - 1 ) { + jsOut += ',\n'; + } else { + jsOut += '\n'; + } + } + + // Add blank line between input type groups ( except for the last one )... + if ( i < inputTypes.length - 1 ) { + jsOut += '\n'; + } + } + + jsOut += '];\n\n\n'; + jsOut += '// EXPORTS //\n\n'; + jsOut += 'module.exports = types;\n'; + return jsOut; +} + +/** +* Generates the addon.c file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @param {string} basePkg - base package name +* @returns {string} addon.c file content +*/ +function generateAddonFile( matches, header, basePkg ) { + var uniqueIncludes; + var functionIndex; + var outputTypes; + var includeKey; + var inputType; + var grouped; + var result; + var cOut; + var i; + var j; + + // Generate unique includes... + uniqueIncludes = {}; + for ( i = 0; i < matches.length; i++ ) { + includeKey = matches[ i ][ 6 ].replace( 'stdlib_base_', '' ); + uniqueIncludes[ '#include "stdlib/math/base/special/' + includeKey + '.h"' ] = true; + } + + // Group matches by input type... + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + matches = result.reorderedMatches; + + cOut = header; + cOut += Object.keys( uniqueIncludes ).join( '\n' ) + '\n'; + cOut += '#include "stdlib/ndarray/base/function_object.h"\n'; + cOut += '#include "stdlib/ndarray/base/napi/unary.h"\n'; + cOut += '#include "stdlib/ndarray/base/unary.h"\n'; + cOut += '#include "stdlib/ndarray/dtypes.h"\n'; + cOut += '#include \n\n'; + cOut += '// Define an interface name:\n'; + cOut += 'static const char name[] = "stdlib_ndarray_' + basePkg + '";\n\n'; + cOut += '// Define a list of ndarray functions:\n'; + cOut += 'static ndarrayFcn functions[] = {\n'; + + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t' + matches[ functionIndex ][ 7 ] + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define the array of input and output ndarray types:\n'; + cOut += 'static int32_t types[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\tSTDLIB_NDARRAY_' + matches[ functionIndex ][ 0 ].toUpperCase() + ', STDLIB_NDARRAY_' + matches[ functionIndex ][ 1 ].toUpperCase() + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define a list of ndarray function "data" (in this case, callbacks):\n'; + cOut += 'static void *data[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t(void *)' + matches[ functionIndex ][ 6 ] + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Create an ndarray function object:\n'; + cOut += 'static const struct ndarrayFunctionObject obj = {\n'; + cOut += '\t// ndarray function name:\n'; + cOut += '\tname,\n\n'; + cOut += '\t// Number of input ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Number of output ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Total number of ndarray arguments (nin + nout):\n'; + cOut += '\t2,\n\n'; + cOut += '\t// Array containing ndarray functions:\n'; + cOut += '\tfunctions,\n\n'; + cOut += '\t// Number of ndarray functions:\n'; + cOut += '\t' + matches.length + ',\n\n'; + cOut += '\t// Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of ndarray argument types for a corresponding ndarray function:\n'; + cOut += '\ttypes,\n\n'; + cOut += '\t// Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions):\n'; + cOut += '\tdata\n'; + cOut += '};\n\n'; + cOut += 'STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj )\n'; + return cOut; +} + + +// MAIN // + +/** +* Main execution function. +* +* @private +*/ +function main() { + var basePkg; + var matches; + var header; + var jsOut; + var cOut; + + // Generate and filter matches table: + matches = generateMatchesTable(); + + // Extract package information: + basePkg = pkg.name.split( '/' ).pop(); + + // Generate license header: + header = licenseHeader( 'Apache-2.0', 'js', { + 'year': currentYear(), + 'copyright': 'The Stdlib Authors' + }); + header += '\n/* This is a generated file. Do not edit directly. */\n'; + + // Generate types.js: + jsOut = generateTypesFile( matches, header ); + writeFileSync( join( __dirname, '../lib/types.js' ), jsOut, { + 'encoding': 'utf8' + }); + + // Generate addon.c: + cOut = generateAddonFile( matches, header, basePkg ); + writeFileSync( join( __dirname, '../src/addon.c' ), cOut, { + 'encoding': 'utf8' + }); +} + + +// MAIN // + +main(); diff --git a/lib/node_modules/@stdlib/math/special/sin/scripts/get_dtypes.js b/lib/node_modules/@stdlib/math/special/sin/scripts/get_dtypes.js new file mode 100644 index 000000000000..f961d1011401 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/scripts/get_dtypes.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var findPkgs = require( '@stdlib/_tools/pkgs/find' ).sync; +var rootDir = require( '@stdlib/_tools/utils/root-dir' ); +var readJSON = require( '@stdlib/fs/read-json' ).sync; + + +// VARIABLES // + +var ROOT_DIR = rootDir(); +var jsonOpts = { + 'encoding': 'utf8' +}; + + +// FUNCTIONS // + +/** +* Returns the input and output dtypes for a given package by reading scaffold metadata. +* +* @private +* @param {string} pkgPath - package path +* @returns {Array} input and output dtypes +* +* @example +* var dtypes = getDtypes( '@stdlib/math/base/special/sqrt' ); +* // returns [ 'float64', 'float64' ] +* +* @example +* var dtypes = getDtypes( '@stdlib/math/base/special/sqrtf' ); +* // returns [ 'float32', 'float32' ] +*/ +function getDtypes( pkgPath ) { + var outputDtype; + var inputDtype; + var aliasName; + var path; + var json; + var pkg; + var out; + var o; + + // Extract alias name from package path: + aliasName = pkgPath.split( '/' ).pop(); + + // Find the package: + pkg = findPkgs({ + 'dir': ROOT_DIR, + 'pattern': '**/math/base/special/' + aliasName + '/package.json' // Currently we are looking only in `math/base/special/` + }); + + if ( pkg.length === 0 ) { + return []; + } + + // Get the metadata: + path = resolve( ROOT_DIR, pkg[ 0 ] ); + json = readJSON( resolve( path, 'package.json' ), jsonOpts ); + o = json.__stdlib__; // eslint-disable-line no-underscore-dangle + if ( o && o.scaffold && o.scaffold.parameters.length >= 1 ) { + out = o.scaffold; + } + + // Extract input and output dtypes: + inputDtype = out.parameters[ 0 ].type.dtype; + outputDtype = out.returns.type.dtype; + + return [ inputDtype, outputDtype ]; +} + + +// EXPORTS // + +module.exports = getDtypes; diff --git a/lib/node_modules/@stdlib/math/special/sin/scripts/map_to_scalar_kernel.js b/lib/node_modules/@stdlib/math/special/sin/scripts/map_to_scalar_kernel.js new file mode 100644 index 000000000000..74a3929877f2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/scripts/map_to_scalar_kernel.js @@ -0,0 +1,178 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); +var format = require( '@stdlib/string/format' ); +var DTYPE_HIERARCHY = require( '@stdlib/math/special/scripts/dtype_hierarchy.js' ); + + +// FUNCTIONS // + +/** +* Maps dtype pairs to appropriate scalar functions. +* +* ## Note +* +* - The function returns an array with the following structure: +* +* ```text +* --------------------------------------------------------------------------------- +* Array: | kernel | cFunc | ndarrayKernel | match | +* --------------------------------------------------------------------------------- +* | | | | +* | | | | +* V V V V +* Example: '@stdlib/math/base/ 'stdlib_base_sqrt' 'stdlib_ndarray_ ['float64', +* special/sqrt' f_d_as_d_d' 'float64'] +* ``` +* +* @private +* @param {Array} iopair - input-output dtype pair +* @param {Array} iodt - array of available scalar kernel dtypes +* @param {Object} scalarKernels - scalar kernels object +* @returns {Array} mapping result +* +* @example +* var iopair = [ 'float32', 'float64' ]; +* var iodt = [ +* [ 'float32', 'float32' ], +* [ 'float64', 'float64' ] +* ]; +* var scalarKernels = { +* 'float32': '@stdlib/math/base/special/sqrtf', +* 'float64': '@stdlib/math/base/special/sqrt' +* }; +* +* var result = mapToScalarKernel( iopair, iodt, scalarKernels ); +* // returns [ '@stdlib/math/base/special/sqrt', 'stdlib_base_sqrt', 'stdlib_ndarray_f_d_as_d_d', [ 'float64', 'float64' ] ] +*/ +function mapToScalarKernel( iopair, iodt, scalarKernels ) { + var ndarrayKernel; + var precision1; + var precision2; + var matchChar1; + var matchChar2; + var outputChar; + var cFuncName; + var inputChar; + var kernel; + var match; + var dtype; + var i; + + inputChar = dtypeChar( iopair[ 0 ] ); + outputChar = dtypeChar( iopair[ 1 ] ); + + // For generic input, always use highest precision kernel + if ( iopair[ 0 ] === 'generic' ) { + kernel = scalarKernels.float64 || scalarKernels.generic; + cFuncName = 'stdlib_base_' + kernel.split( '/' ).pop(); + ndarrayKernel = format( 'stdlib_ndarray_%s_%s_as_d_d', inputChar, outputChar ); + + return [ kernel, cFuncName, ndarrayKernel, [ 'float64', 'float64' ] ]; + } + + // Priority 1: Look for exact match in available scalar kernel dtypes: + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 0 ] && + iodt[ i ][ 1 ] === iopair[ 1 ] ) { + match = iodt[ i ]; + break; + } + } + + // Priority 2: Look for higher precision matches to break ties: + if ( !match ) { + /* + * Always prefer computing at higher precision: + * - For cases like ['float32', 'float64'], prefer computing at float64: f_d_as_d_d + * - For cases like ['int8', 'float32'], prefer computing at float32: s_f_as_f_f + */ + + // Get higher precision dtype using hierarchy table: + if ( iopair[ 0 ] === iopair[ 1 ] ) { + dtype = iopair[ 0 ]; + } else { + precision1 = DTYPE_HIERARCHY[ iopair[ 0 ] ] || 0; + precision2 = DTYPE_HIERARCHY[ iopair[ 1 ] ] || 0; + dtype = ( precision2 > precision1 ) ? iopair[ 1 ] : iopair[ 0 ]; + } + + // First try: Look for (higher_precision_dtype, higher_precision_dtype)... + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === dtype && iodt[ i ][ 1 ] === dtype ) { + match = iodt[ i ]; + break; + } + } + + // Second try: Look for (input_dtype, input_dtype) if higher precision not found... + if ( !match ) { + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 0 ] && + iodt[ i ][ 1 ] === iopair[ 0 ] ) { + match = iodt[ i ]; + break; + } + } + } + + // Third try: Look for (output_dtype, output_dtype)... + if ( !match ) { + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 1 ] && + iodt[ i ][ 1 ] === iopair[ 1 ] ) { + match = iodt[ i ]; + break; + } + } + } + } + + if ( match ) { + // Get the scalar kernel package + kernel = scalarKernels[ match[ 1 ] ]; + + // Generate C function name + cFuncName = 'stdlib_base_' + kernel.split( '/' ).pop(); + + // Generate ndarray kernel name + if ( match[ 0 ] === iopair[ 0 ] && match[ 1 ] === iopair[ 1 ] ) { + // Exact match + ndarrayKernel = format( 'stdlib_ndarray_%s_%s', inputChar, outputChar ); + } else { + // Promotion case + matchChar1 = dtypeChar( match[ 0 ] ); + matchChar2 = dtypeChar( match[ 1 ] ); + ndarrayKernel = format( 'stdlib_ndarray_%s_%s_as_%s_%s', inputChar, outputChar, matchChar1, matchChar2 ); + } + + return [ kernel, cFuncName, ndarrayKernel, match ]; + } + + return []; +} + + +// EXPORTS // + +module.exports = mapToScalarKernel; diff --git a/lib/node_modules/@stdlib/math/special/sin/scripts/script.js b/lib/node_modules/@stdlib/math/special/sin/scripts/script.js new file mode 100644 index 000000000000..99d479a116d9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/scripts/script.js @@ -0,0 +1,255 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var basename = require( 'path' ).basename; +var join = require( 'path' ).join; +var db = require( '@stdlib/math/special/scripts/function_database.json' ); +var cartesianProduct = require( '@stdlib/array/cartesian-product' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var DTYPE_HIERARCHY = require( '@stdlib/math/special/scripts/dtype_hierarchy.js' ); +var NDARRAY_KERNELS = require( '@stdlib/ndarray/base/unary/data/function_list.json' ); +var mapToScalarKernel = require( './map_to_scalar_kernel.js' ); +var getDtypes = require( './get_dtypes.js' ); +var config = require( './config.js' ); + + +// VARIABLES // + +var DTYPES = {}; +var basePkg = basename( join( __dirname, '..' ) ); + + +// MAIN // + +/** +* Main execution sequence. +* +* ## Note +* +* - The function generates an array of matches, where each match is an array of the following format: +* +* ```text +* ---------------------------------------------------------------------------------------------------------------------------------------- +* Array: | input_dtype | output_dtype | package | needs_to_promote | promoted_input_dtype | promoted_output_dtype | c_function_name | loop_kernel | +* ---------------------------------------------------------------------------------------------------------------------------------------- +* | | | | | | | | +* | | | | | | | | +* V V | V V V | V +* Example: 'float32' 'float64' | true 'float64' 'float64' | 'stdlib_ndarray_f_d_as_d_d' +* V V +* '@stdlib/math/base/special/sqrt' 'stdlib_base_sqrt' +* ``` +* +* @private +* @returns {Array} array of mappings +*/ +function main() { + var outputPrecision; + var needsPromotion; + var inputPrecision; + var outputDtype; + var inputDtype; + var filtered = []; + var mappings; + var kernels = []; + var iopairs; + var mapping; + var iodt = []; + var seen = {}; + var odt; + var idt; + var out; + var obj; + var dt; + var k; + var i; + + // Resolve list of input dtypes: + idt = dtypes( config.input_dtypes ); + filtered = []; + for ( i = 0; i < idt.length; i++ ) { + if ( config.excluded_dtypes.indexOf( idt[ i ] ) === -1 ) { // Exclude irrelevant dtypes + filtered.push( idt[ i ] ); + } + } + idt = filtered; + + /* + For example, we'll have: + idt = [ + 'float32', + 'float64', + 'int16', + 'int32', + 'int8', + 'uint16', + 'uint32', + 'uint8', + 'generic' + ] + */ + + // Resolve the list of output dtypes: + odt = dtypes( config.output_dtypes ); + filtered = []; + for ( i = 0; i < odt.length; i++ ) { + if ( config.excluded_dtypes.indexOf( odt[ i ] ) === -1 ) { // Exclude irrelevant dtypes + filtered.push( odt[ i ] ); + } + } + odt = filtered; + + /* + For example, we'll have: + odt = [ + 'float32', + 'float64' + ] + */ + + // Computing the Cartesian product of input and output dtypes: + iopairs = cartesianProduct( idt, odt ); + + /* + For example, we'll have: + iopairs = [ + [ 'float32', 'float32' ], + [ 'float32', 'float64' ], + [ 'float64', 'float32' ], + [ 'float64', 'float64' ], + ... + ] + */ + + // Filter based on dtype hierarchy: + for ( i = 0; i < iopairs.length; i++ ) { + inputDtype = iopairs[ i ][ 0 ]; + outputDtype = iopairs[ i ][ 1 ]; + inputPrecision = DTYPE_HIERARCHY[ inputDtype ] || 0; + outputPrecision = DTYPE_HIERARCHY[ outputDtype ] || 0; + + // Only allow upcasts (higher or equal precision) or same dtype or generic source: + if ( inputDtype === outputDtype || inputDtype === 'generic' || outputPrecision >= inputPrecision ) { + filtered.push( iopairs[ i ] ); + } + } + iopairs = filtered; + + /* + For example, we'll have: + iopairs = [ + [ 'float32', 'float32' ], + [ 'float32', 'float64' ], + [ 'float64', 'float64' ], + ... + ] + */ + + // Get the list of dtypes with scalar math kernels: + obj = db[ basePkg ]; + + /* + For example, we'll have: + obj = { + "input_dtypes": "real_and_generic", + "output_dtypes": "real_floating_point", + "output_policy": "real_floating_point", + "scalar_kernels": { + "float32": "@stdlib/math/base/special/sqrtf", + "float64": "@stdlib/math/base/special/sqrt", + "generic": "@stdlib/math/base/special/sqrt" + } + } + */ + + /* + Available scalar kernel dtypes: + objectKeys( obj.scalar_kernels ) = [ + 'float32', + 'float64' + ] + */ + + // Build a list of scalar kernels based on output dtype: + for ( i = 0; iopairs && i < iopairs.length; i++ ) { + out = iopairs[ i ][ 1 ]; + + // For generic input, always use highest precision kernel: + if ( iopairs[ i ][ 0 ] === 'generic' ) { + k = obj.scalar_kernels.float64 || obj.scalar_kernels.generic; + } else { + k = obj.scalar_kernels[ out ] || obj.scalar_kernels.generic; + } + + if ( k && !seen[ k ] ) { + seen[ k ] = true; + kernels.push( k ); + } + } + + // Resolve the input-output dtypes for each unique scalar kernel: + iodt = []; + for ( i = 0; i < kernels.length; i++ ) { + if ( DTYPES[ kernels[ i ] ] ) { + iodt.push( DTYPES[ kernels[ i ] ] ); + continue; + } + dt = getDtypes( kernels[ i ] ); + DTYPES[ kernels[ i ] ] = dt; + iodt.push( dt ); + } + + // Map dtype pairs to appropriate scalar functions based on prioritization rules: + mappings = []; + for ( i = 0; i < iopairs.length; i++ ) { + mapping = mapToScalarKernel( iopairs[ i ], iodt, obj.scalar_kernels ); + if ( mapping && mapping.length === 4 ) { + // Verify that the ndarray kernel exists in the function list + if ( NDARRAY_KERNELS.indexOf( mapping[ 2 ] ) !== -1 ) { + // Check if promotion is needed... + needsPromotion = mapping[ 3 ][ 0 ] !== iopairs[ i ][ 0 ] || + mapping[ 3 ][ 1 ] !== iopairs[ i ][ 1 ]; + + // [ input_dtype, output_dtype, package, needs_to_promote, promoted_input_dtype, promoted_output_dtype, c_function_name, loop_kernel ]... + mappings.push([ iopairs[ i ][ 0 ], iopairs[ i ][ 1 ], mapping[ 0 ], needsPromotion, ( needsPromotion ) ? mapping[ 3 ][ 0 ] : null, ( needsPromotion ) ? mapping[ 3 ][ 1 ] : null, mapping[ 1 ], mapping[ 2 ] ]); // eslint-disable-line max-len + } + } + } + + /* + For example, we'll have: + mappings = [ + [ 'int8', 'float32', '@stdlib/math/base/special/sqrtf', true, 'float32', 'float32', 'stdlib_base_sqrtf', 'stdlib_ndarray_s_f_as_f_f' ], + [ 'float32', 'float32', '@stdlib/math/base/special/sqrtf', false, null, null, 'stdlib_base_sqrtf', 'stdlib_ndarray_f_f' ], + [ 'float32', 'float64', '@stdlib/math/base/special/sqrt', true, 'float64', 'float64', 'stdlib_base_sqrt', 'stdlib_ndarray_f_d_as_d_d' ], + [ 'float64', 'float64', '@stdlib/math/base/special/sqrt', false, null, null, 'stdlib_base_sqrt', 'stdlib_ndarray_d_d' ], + ... + ] + */ + + return mappings; +} + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/special/sin/src/addon.c b/lib/node_modules/@stdlib/math/special/sin/src/addon.c new file mode 100644 index 000000000000..250c7b5bbe43 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sin/src/addon.c @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* This is a generated file. Do not edit directly. */ +#include "stdlib/math/base/special/sinf.h" +#include "stdlib/math/base/special/sin.h" +#include "stdlib/ndarray/base/function_object.h" +#include "stdlib/ndarray/base/napi/unary.h" +#include "stdlib/ndarray/base/unary.h" +#include "stdlib/ndarray/dtypes.h" +#include + +// Define an interface name: +static const char name[] = "stdlib_ndarray_sin"; + +// Define a list of ndarray functions: +static ndarrayFcn functions[] = { + // float32 (2) + stdlib_ndarray_f_f, + stdlib_ndarray_f_d_as_d_d, + + // float64 (1) + stdlib_ndarray_d_d, + + // int16 (2) + stdlib_ndarray_k_f_as_f_f, + stdlib_ndarray_k_d_as_d_d, + + // int32 (1) + stdlib_ndarray_i_d_as_d_d, + + // int8 (2) + stdlib_ndarray_s_f_as_f_f, + stdlib_ndarray_s_d_as_d_d, + + // uint16 (2) + stdlib_ndarray_t_f_as_f_f, + stdlib_ndarray_t_d_as_d_d, + + // uint32 (1) + stdlib_ndarray_u_d_as_d_d, + + // uint8 (2) + stdlib_ndarray_b_f_as_f_f, + stdlib_ndarray_b_d_as_d_d, + +}; + +// Define the array of input and output ndarray types: +static int32_t types[] = { + // float32 (2) + STDLIB_NDARRAY_FLOAT32, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_FLOAT32, STDLIB_NDARRAY_FLOAT64, + + // float64 (1) + STDLIB_NDARRAY_FLOAT64, STDLIB_NDARRAY_FLOAT64, + + // int16 (2) + STDLIB_NDARRAY_INT16, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_INT16, STDLIB_NDARRAY_FLOAT64, + + // int32 (1) + STDLIB_NDARRAY_INT32, STDLIB_NDARRAY_FLOAT64, + + // int8 (2) + STDLIB_NDARRAY_INT8, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_INT8, STDLIB_NDARRAY_FLOAT64, + + // uint16 (2) + STDLIB_NDARRAY_UINT16, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_UINT16, STDLIB_NDARRAY_FLOAT64, + + // uint32 (1) + STDLIB_NDARRAY_UINT32, STDLIB_NDARRAY_FLOAT64, + + // uint8 (2) + STDLIB_NDARRAY_UINT8, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_UINT8, STDLIB_NDARRAY_FLOAT64, + +}; + +// Define a list of ndarray function "data" (in this case, callbacks): +static void *data[] = { + // float32 (2) + (void *)stdlib_base_sinf, + (void *)stdlib_base_sin, + + // float64 (1) + (void *)stdlib_base_sin, + + // int16 (2) + (void *)stdlib_base_sinf, + (void *)stdlib_base_sin, + + // int32 (1) + (void *)stdlib_base_sin, + + // int8 (2) + (void *)stdlib_base_sinf, + (void *)stdlib_base_sin, + + // uint16 (2) + (void *)stdlib_base_sinf, + (void *)stdlib_base_sin, + + // uint32 (1) + (void *)stdlib_base_sin, + + // uint8 (2) + (void *)stdlib_base_sinf, + (void *)stdlib_base_sin, + +}; + +// Create an ndarray function object: +static const struct ndarrayFunctionObject obj = { + // ndarray function name: + name, + + // Number of input ndarrays: + 1, + + // Number of output ndarrays: + 1, + + // Total number of ndarray arguments (nin + nout): + 2, + + // Array containing ndarray functions: + functions, + + // Number of ndarray functions: + 13, + + // Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of ndarray argument types for a corresponding ndarray function: + types, + + // Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions): + data +}; + +STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj ) diff --git a/lib/node_modules/@stdlib/math/special/sqrt/lib/types.js b/lib/node_modules/@stdlib/math/special/sqrt/lib/types.js new file mode 100644 index 000000000000..ba8b4897156e --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/lib/types.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* This is a generated file. Do not edit directly. */ + +/* eslint-disable array-element-newline */ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); + + +// MAIN // + +var types = [ + // float32 (2) + dtypes.float32, dtypes.float32, + dtypes.float32, dtypes.float64, + + // float64 (1) + dtypes.float64, dtypes.float64, + + // int16 (2) + dtypes.int16, dtypes.float32, + dtypes.int16, dtypes.float64, + + // int32 (1) + dtypes.int32, dtypes.float64, + + // int8 (2) + dtypes.int8, dtypes.float32, + dtypes.int8, dtypes.float64, + + // uint16 (2) + dtypes.uint16, dtypes.float32, + dtypes.uint16, dtypes.float64, + + // uint32 (1) + dtypes.uint32, dtypes.float64, + + // uint8 (2) + dtypes.uint8, dtypes.float32, + dtypes.uint8, dtypes.float64 +]; + + +// EXPORTS // + +module.exports = types; diff --git a/lib/node_modules/@stdlib/math/special/sqrt/package.json b/lib/node_modules/@stdlib/math/special/sqrt/package.json new file mode 100644 index 000000000000..b44a99001fdf --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/package.json @@ -0,0 +1,57 @@ +{ + "name": "@stdlib/math/special/sqrt", + "version": "0.0.0", + "description": "Compute the square root.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/math/special/sqrt/scripts/config.js b/lib/node_modules/@stdlib/math/special/sqrt/scripts/config.js new file mode 100644 index 000000000000..13d8ee48102b --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/scripts/config.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Configuration object. +* +* @private +* @type {Object} +*/ +var config = { + 'input_dtypes': 'real_and_generic', + 'output_dtypes': 'real_floating_point', + 'excluded_dtypes': [ 'float16', 'uint8c' ] +}; + + +// EXPORTS // + +module.exports = config; diff --git a/lib/node_modules/@stdlib/math/special/sqrt/scripts/generate_files.js b/lib/node_modules/@stdlib/math/special/sqrt/scripts/generate_files.js new file mode 100644 index 000000000000..7828f33b516f --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/scripts/generate_files.js @@ -0,0 +1,285 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var join = require( 'path' ).join; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var licenseHeader = require( '@stdlib/_tools/licenses/header' ); +var currentYear = require( '@stdlib/time/current-year' ); +var generateMatchesTable = require( './script.js' ); +var pkg = require( './../package.json' ); + + +// FUNCTIONS // + +/** +* Groups matches by input data type. +* +* @private +* @param {Array} matches - array of match entries +* @returns {Object} object containing grouped matches, input types array, and reordered matches +*/ +function groupMatchesByInputType( matches ) { + var reorderedMatches = []; + var inputTypes = []; + var inputType; + var grouped = {}; + var i; + var j; + + for ( i = 0; i < matches.length; i++ ) { + inputType = matches[ i ][ 0 ]; + if ( !grouped[ inputType ] ) { + grouped[ inputType ] = []; + inputTypes.push( inputType ); + } + grouped[ inputType ].push( matches[ i ][ 1 ] ); + } + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + for ( j = 0; j < matches.length; j++ ) { + if ( matches[ j ][ 0 ] === inputType ) { + reorderedMatches.push( matches[ j ] ); + } + } + } + + return { + 'grouped': grouped, + 'inputTypes': inputTypes, + 'reorderedMatches': reorderedMatches + }; +} + +/** +* Generates the types.js file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @returns {string} types.js file content +*/ +function generateTypesFile( matches, header ) { + var outputTypes; + var inputTypes; + var inputType; + var grouped; + var result; + var jsOut; + var i; + var j; + + jsOut = header; + jsOut += '\n'; + jsOut += '/* eslint-disable array-element-newline */\n\n'; + jsOut += '\'use strict\';\n\n'; + jsOut += '// MODULES //\n\n'; + jsOut += 'var dtypes = require( \'@stdlib/ndarray/dtypes\' );\n\n\n'; + jsOut += '// MAIN //\n\n'; + jsOut += 'var types = [\n'; + + // Group matches by input dtype... + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + inputTypes = result.inputTypes; + + for ( i = 0; i < inputTypes.length; i++ ) { + inputType = inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + jsOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + jsOut += '\tdtypes.' + inputType + ', dtypes.' + outputTypes[ j ]; + if ( i < inputTypes.length - 1 || j < outputTypes.length - 1 ) { + jsOut += ',\n'; + } else { + jsOut += '\n'; + } + } + + // Add blank line between input type groups ( except for the last one )... + if ( i < inputTypes.length - 1 ) { + jsOut += '\n'; + } + } + + jsOut += '];\n\n\n'; + jsOut += '// EXPORTS //\n\n'; + jsOut += 'module.exports = types;\n'; + return jsOut; +} + +/** +* Generates the addon.c file content. +* +* @private +* @param {Array} matches - array of match entries +* @param {string} header - license header +* @param {string} basePkg - base package name +* @returns {string} addon.c file content +*/ +function generateAddonFile( matches, header, basePkg ) { + var uniqueIncludes; + var functionIndex; + var outputTypes; + var includeKey; + var inputType; + var grouped; + var result; + var cOut; + var i; + var j; + + // Generate unique includes... + uniqueIncludes = {}; + for ( i = 0; i < matches.length; i++ ) { + includeKey = matches[ i ][ 6 ].replace( 'stdlib_base_', '' ); + uniqueIncludes[ '#include "stdlib/math/base/special/' + includeKey + '.h"' ] = true; + } + + // Group matches by input type... + result = groupMatchesByInputType( matches ); + grouped = result.grouped; + matches = result.reorderedMatches; + + cOut = header; + cOut += Object.keys( uniqueIncludes ).join( '\n' ) + '\n'; + cOut += '#include "stdlib/ndarray/base/function_object.h"\n'; + cOut += '#include "stdlib/ndarray/base/napi/unary.h"\n'; + cOut += '#include "stdlib/ndarray/base/unary.h"\n'; + cOut += '#include "stdlib/ndarray/dtypes.h"\n'; + cOut += '#include \n\n'; + cOut += '// Define an interface name:\n'; + cOut += 'static const char name[] = "stdlib_ndarray_' + basePkg + '";\n\n'; + cOut += '// Define a list of ndarray functions:\n'; + cOut += 'static ndarrayFcn functions[] = {\n'; + + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t' + matches[ functionIndex ][ 7 ] + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define the array of input and output ndarray types:\n'; + cOut += 'static int32_t types[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\tSTDLIB_NDARRAY_' + matches[ functionIndex ][ 0 ].toUpperCase() + ', STDLIB_NDARRAY_' + matches[ functionIndex ][ 1 ].toUpperCase() + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Define a list of ndarray function "data" (in this case, callbacks):\n'; + cOut += 'static void *data[] = {\n'; + functionIndex = 0; + for ( i = 0; i < result.inputTypes.length; i++ ) { + inputType = result.inputTypes[ i ]; + outputTypes = grouped[ inputType ]; + + cOut += '\t// ' + inputType + ' (' + outputTypes.length + ')\n'; + for ( j = 0; j < outputTypes.length; j++ ) { + cOut += '\t(void *)' + matches[ functionIndex ][ 6 ] + ',\n'; + functionIndex += 1; + } + cOut += '\n'; + } + cOut += '};\n\n'; + cOut += '// Create an ndarray function object:\n'; + cOut += 'static const struct ndarrayFunctionObject obj = {\n'; + cOut += '\t// ndarray function name:\n'; + cOut += '\tname,\n\n'; + cOut += '\t// Number of input ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Number of output ndarrays:\n'; + cOut += '\t1,\n\n'; + cOut += '\t// Total number of ndarray arguments (nin + nout):\n'; + cOut += '\t2,\n\n'; + cOut += '\t// Array containing ndarray functions:\n'; + cOut += '\tfunctions,\n\n'; + cOut += '\t// Number of ndarray functions:\n'; + cOut += '\t' + matches.length + ',\n\n'; + cOut += '\t// Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of ndarray argument types for a corresponding ndarray function:\n'; + cOut += '\ttypes,\n\n'; + cOut += '\t// Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions):\n'; + cOut += '\tdata\n'; + cOut += '};\n\n'; + cOut += 'STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj )\n'; + return cOut; +} + + +// MAIN // + +/** +* Main execution function. +* +* @private +*/ +function main() { + var basePkg; + var matches; + var header; + var jsOut; + var cOut; + + // Generate and filter matches table: + matches = generateMatchesTable(); + + // Extract package information: + basePkg = pkg.name.split( '/' ).pop(); + + // Generate license header: + header = licenseHeader( 'Apache-2.0', 'js', { + 'year': currentYear(), + 'copyright': 'The Stdlib Authors' + }); + header += '\n/* This is a generated file. Do not edit directly. */\n'; + + // Generate types.js: + jsOut = generateTypesFile( matches, header ); + writeFileSync( join( __dirname, '../lib/types.js' ), jsOut, { + 'encoding': 'utf8' + }); + + // Generate addon.c: + cOut = generateAddonFile( matches, header, basePkg ); + writeFileSync( join( __dirname, '../src/addon.c' ), cOut, { + 'encoding': 'utf8' + }); +} + + +// MAIN // + +main(); diff --git a/lib/node_modules/@stdlib/math/special/sqrt/scripts/get_dtypes.js b/lib/node_modules/@stdlib/math/special/sqrt/scripts/get_dtypes.js new file mode 100644 index 000000000000..f961d1011401 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/scripts/get_dtypes.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var findPkgs = require( '@stdlib/_tools/pkgs/find' ).sync; +var rootDir = require( '@stdlib/_tools/utils/root-dir' ); +var readJSON = require( '@stdlib/fs/read-json' ).sync; + + +// VARIABLES // + +var ROOT_DIR = rootDir(); +var jsonOpts = { + 'encoding': 'utf8' +}; + + +// FUNCTIONS // + +/** +* Returns the input and output dtypes for a given package by reading scaffold metadata. +* +* @private +* @param {string} pkgPath - package path +* @returns {Array} input and output dtypes +* +* @example +* var dtypes = getDtypes( '@stdlib/math/base/special/sqrt' ); +* // returns [ 'float64', 'float64' ] +* +* @example +* var dtypes = getDtypes( '@stdlib/math/base/special/sqrtf' ); +* // returns [ 'float32', 'float32' ] +*/ +function getDtypes( pkgPath ) { + var outputDtype; + var inputDtype; + var aliasName; + var path; + var json; + var pkg; + var out; + var o; + + // Extract alias name from package path: + aliasName = pkgPath.split( '/' ).pop(); + + // Find the package: + pkg = findPkgs({ + 'dir': ROOT_DIR, + 'pattern': '**/math/base/special/' + aliasName + '/package.json' // Currently we are looking only in `math/base/special/` + }); + + if ( pkg.length === 0 ) { + return []; + } + + // Get the metadata: + path = resolve( ROOT_DIR, pkg[ 0 ] ); + json = readJSON( resolve( path, 'package.json' ), jsonOpts ); + o = json.__stdlib__; // eslint-disable-line no-underscore-dangle + if ( o && o.scaffold && o.scaffold.parameters.length >= 1 ) { + out = o.scaffold; + } + + // Extract input and output dtypes: + inputDtype = out.parameters[ 0 ].type.dtype; + outputDtype = out.returns.type.dtype; + + return [ inputDtype, outputDtype ]; +} + + +// EXPORTS // + +module.exports = getDtypes; diff --git a/lib/node_modules/@stdlib/math/special/sqrt/scripts/map_to_scalar_kernel.js b/lib/node_modules/@stdlib/math/special/sqrt/scripts/map_to_scalar_kernel.js new file mode 100644 index 000000000000..74a3929877f2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/scripts/map_to_scalar_kernel.js @@ -0,0 +1,178 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); +var format = require( '@stdlib/string/format' ); +var DTYPE_HIERARCHY = require( '@stdlib/math/special/scripts/dtype_hierarchy.js' ); + + +// FUNCTIONS // + +/** +* Maps dtype pairs to appropriate scalar functions. +* +* ## Note +* +* - The function returns an array with the following structure: +* +* ```text +* --------------------------------------------------------------------------------- +* Array: | kernel | cFunc | ndarrayKernel | match | +* --------------------------------------------------------------------------------- +* | | | | +* | | | | +* V V V V +* Example: '@stdlib/math/base/ 'stdlib_base_sqrt' 'stdlib_ndarray_ ['float64', +* special/sqrt' f_d_as_d_d' 'float64'] +* ``` +* +* @private +* @param {Array} iopair - input-output dtype pair +* @param {Array} iodt - array of available scalar kernel dtypes +* @param {Object} scalarKernels - scalar kernels object +* @returns {Array} mapping result +* +* @example +* var iopair = [ 'float32', 'float64' ]; +* var iodt = [ +* [ 'float32', 'float32' ], +* [ 'float64', 'float64' ] +* ]; +* var scalarKernels = { +* 'float32': '@stdlib/math/base/special/sqrtf', +* 'float64': '@stdlib/math/base/special/sqrt' +* }; +* +* var result = mapToScalarKernel( iopair, iodt, scalarKernels ); +* // returns [ '@stdlib/math/base/special/sqrt', 'stdlib_base_sqrt', 'stdlib_ndarray_f_d_as_d_d', [ 'float64', 'float64' ] ] +*/ +function mapToScalarKernel( iopair, iodt, scalarKernels ) { + var ndarrayKernel; + var precision1; + var precision2; + var matchChar1; + var matchChar2; + var outputChar; + var cFuncName; + var inputChar; + var kernel; + var match; + var dtype; + var i; + + inputChar = dtypeChar( iopair[ 0 ] ); + outputChar = dtypeChar( iopair[ 1 ] ); + + // For generic input, always use highest precision kernel + if ( iopair[ 0 ] === 'generic' ) { + kernel = scalarKernels.float64 || scalarKernels.generic; + cFuncName = 'stdlib_base_' + kernel.split( '/' ).pop(); + ndarrayKernel = format( 'stdlib_ndarray_%s_%s_as_d_d', inputChar, outputChar ); + + return [ kernel, cFuncName, ndarrayKernel, [ 'float64', 'float64' ] ]; + } + + // Priority 1: Look for exact match in available scalar kernel dtypes: + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 0 ] && + iodt[ i ][ 1 ] === iopair[ 1 ] ) { + match = iodt[ i ]; + break; + } + } + + // Priority 2: Look for higher precision matches to break ties: + if ( !match ) { + /* + * Always prefer computing at higher precision: + * - For cases like ['float32', 'float64'], prefer computing at float64: f_d_as_d_d + * - For cases like ['int8', 'float32'], prefer computing at float32: s_f_as_f_f + */ + + // Get higher precision dtype using hierarchy table: + if ( iopair[ 0 ] === iopair[ 1 ] ) { + dtype = iopair[ 0 ]; + } else { + precision1 = DTYPE_HIERARCHY[ iopair[ 0 ] ] || 0; + precision2 = DTYPE_HIERARCHY[ iopair[ 1 ] ] || 0; + dtype = ( precision2 > precision1 ) ? iopair[ 1 ] : iopair[ 0 ]; + } + + // First try: Look for (higher_precision_dtype, higher_precision_dtype)... + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === dtype && iodt[ i ][ 1 ] === dtype ) { + match = iodt[ i ]; + break; + } + } + + // Second try: Look for (input_dtype, input_dtype) if higher precision not found... + if ( !match ) { + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 0 ] && + iodt[ i ][ 1 ] === iopair[ 0 ] ) { + match = iodt[ i ]; + break; + } + } + } + + // Third try: Look for (output_dtype, output_dtype)... + if ( !match ) { + for ( i = 0; i < iodt.length; i++ ) { + if ( iodt[ i ][ 0 ] === iopair[ 1 ] && + iodt[ i ][ 1 ] === iopair[ 1 ] ) { + match = iodt[ i ]; + break; + } + } + } + } + + if ( match ) { + // Get the scalar kernel package + kernel = scalarKernels[ match[ 1 ] ]; + + // Generate C function name + cFuncName = 'stdlib_base_' + kernel.split( '/' ).pop(); + + // Generate ndarray kernel name + if ( match[ 0 ] === iopair[ 0 ] && match[ 1 ] === iopair[ 1 ] ) { + // Exact match + ndarrayKernel = format( 'stdlib_ndarray_%s_%s', inputChar, outputChar ); + } else { + // Promotion case + matchChar1 = dtypeChar( match[ 0 ] ); + matchChar2 = dtypeChar( match[ 1 ] ); + ndarrayKernel = format( 'stdlib_ndarray_%s_%s_as_%s_%s', inputChar, outputChar, matchChar1, matchChar2 ); + } + + return [ kernel, cFuncName, ndarrayKernel, match ]; + } + + return []; +} + + +// EXPORTS // + +module.exports = mapToScalarKernel; diff --git a/lib/node_modules/@stdlib/math/special/sqrt/scripts/script.js b/lib/node_modules/@stdlib/math/special/sqrt/scripts/script.js new file mode 100644 index 000000000000..99d479a116d9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/scripts/script.js @@ -0,0 +1,255 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var basename = require( 'path' ).basename; +var join = require( 'path' ).join; +var db = require( '@stdlib/math/special/scripts/function_database.json' ); +var cartesianProduct = require( '@stdlib/array/cartesian-product' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var DTYPE_HIERARCHY = require( '@stdlib/math/special/scripts/dtype_hierarchy.js' ); +var NDARRAY_KERNELS = require( '@stdlib/ndarray/base/unary/data/function_list.json' ); +var mapToScalarKernel = require( './map_to_scalar_kernel.js' ); +var getDtypes = require( './get_dtypes.js' ); +var config = require( './config.js' ); + + +// VARIABLES // + +var DTYPES = {}; +var basePkg = basename( join( __dirname, '..' ) ); + + +// MAIN // + +/** +* Main execution sequence. +* +* ## Note +* +* - The function generates an array of matches, where each match is an array of the following format: +* +* ```text +* ---------------------------------------------------------------------------------------------------------------------------------------- +* Array: | input_dtype | output_dtype | package | needs_to_promote | promoted_input_dtype | promoted_output_dtype | c_function_name | loop_kernel | +* ---------------------------------------------------------------------------------------------------------------------------------------- +* | | | | | | | | +* | | | | | | | | +* V V | V V V | V +* Example: 'float32' 'float64' | true 'float64' 'float64' | 'stdlib_ndarray_f_d_as_d_d' +* V V +* '@stdlib/math/base/special/sqrt' 'stdlib_base_sqrt' +* ``` +* +* @private +* @returns {Array} array of mappings +*/ +function main() { + var outputPrecision; + var needsPromotion; + var inputPrecision; + var outputDtype; + var inputDtype; + var filtered = []; + var mappings; + var kernels = []; + var iopairs; + var mapping; + var iodt = []; + var seen = {}; + var odt; + var idt; + var out; + var obj; + var dt; + var k; + var i; + + // Resolve list of input dtypes: + idt = dtypes( config.input_dtypes ); + filtered = []; + for ( i = 0; i < idt.length; i++ ) { + if ( config.excluded_dtypes.indexOf( idt[ i ] ) === -1 ) { // Exclude irrelevant dtypes + filtered.push( idt[ i ] ); + } + } + idt = filtered; + + /* + For example, we'll have: + idt = [ + 'float32', + 'float64', + 'int16', + 'int32', + 'int8', + 'uint16', + 'uint32', + 'uint8', + 'generic' + ] + */ + + // Resolve the list of output dtypes: + odt = dtypes( config.output_dtypes ); + filtered = []; + for ( i = 0; i < odt.length; i++ ) { + if ( config.excluded_dtypes.indexOf( odt[ i ] ) === -1 ) { // Exclude irrelevant dtypes + filtered.push( odt[ i ] ); + } + } + odt = filtered; + + /* + For example, we'll have: + odt = [ + 'float32', + 'float64' + ] + */ + + // Computing the Cartesian product of input and output dtypes: + iopairs = cartesianProduct( idt, odt ); + + /* + For example, we'll have: + iopairs = [ + [ 'float32', 'float32' ], + [ 'float32', 'float64' ], + [ 'float64', 'float32' ], + [ 'float64', 'float64' ], + ... + ] + */ + + // Filter based on dtype hierarchy: + for ( i = 0; i < iopairs.length; i++ ) { + inputDtype = iopairs[ i ][ 0 ]; + outputDtype = iopairs[ i ][ 1 ]; + inputPrecision = DTYPE_HIERARCHY[ inputDtype ] || 0; + outputPrecision = DTYPE_HIERARCHY[ outputDtype ] || 0; + + // Only allow upcasts (higher or equal precision) or same dtype or generic source: + if ( inputDtype === outputDtype || inputDtype === 'generic' || outputPrecision >= inputPrecision ) { + filtered.push( iopairs[ i ] ); + } + } + iopairs = filtered; + + /* + For example, we'll have: + iopairs = [ + [ 'float32', 'float32' ], + [ 'float32', 'float64' ], + [ 'float64', 'float64' ], + ... + ] + */ + + // Get the list of dtypes with scalar math kernels: + obj = db[ basePkg ]; + + /* + For example, we'll have: + obj = { + "input_dtypes": "real_and_generic", + "output_dtypes": "real_floating_point", + "output_policy": "real_floating_point", + "scalar_kernels": { + "float32": "@stdlib/math/base/special/sqrtf", + "float64": "@stdlib/math/base/special/sqrt", + "generic": "@stdlib/math/base/special/sqrt" + } + } + */ + + /* + Available scalar kernel dtypes: + objectKeys( obj.scalar_kernels ) = [ + 'float32', + 'float64' + ] + */ + + // Build a list of scalar kernels based on output dtype: + for ( i = 0; iopairs && i < iopairs.length; i++ ) { + out = iopairs[ i ][ 1 ]; + + // For generic input, always use highest precision kernel: + if ( iopairs[ i ][ 0 ] === 'generic' ) { + k = obj.scalar_kernels.float64 || obj.scalar_kernels.generic; + } else { + k = obj.scalar_kernels[ out ] || obj.scalar_kernels.generic; + } + + if ( k && !seen[ k ] ) { + seen[ k ] = true; + kernels.push( k ); + } + } + + // Resolve the input-output dtypes for each unique scalar kernel: + iodt = []; + for ( i = 0; i < kernels.length; i++ ) { + if ( DTYPES[ kernels[ i ] ] ) { + iodt.push( DTYPES[ kernels[ i ] ] ); + continue; + } + dt = getDtypes( kernels[ i ] ); + DTYPES[ kernels[ i ] ] = dt; + iodt.push( dt ); + } + + // Map dtype pairs to appropriate scalar functions based on prioritization rules: + mappings = []; + for ( i = 0; i < iopairs.length; i++ ) { + mapping = mapToScalarKernel( iopairs[ i ], iodt, obj.scalar_kernels ); + if ( mapping && mapping.length === 4 ) { + // Verify that the ndarray kernel exists in the function list + if ( NDARRAY_KERNELS.indexOf( mapping[ 2 ] ) !== -1 ) { + // Check if promotion is needed... + needsPromotion = mapping[ 3 ][ 0 ] !== iopairs[ i ][ 0 ] || + mapping[ 3 ][ 1 ] !== iopairs[ i ][ 1 ]; + + // [ input_dtype, output_dtype, package, needs_to_promote, promoted_input_dtype, promoted_output_dtype, c_function_name, loop_kernel ]... + mappings.push([ iopairs[ i ][ 0 ], iopairs[ i ][ 1 ], mapping[ 0 ], needsPromotion, ( needsPromotion ) ? mapping[ 3 ][ 0 ] : null, ( needsPromotion ) ? mapping[ 3 ][ 1 ] : null, mapping[ 1 ], mapping[ 2 ] ]); // eslint-disable-line max-len + } + } + } + + /* + For example, we'll have: + mappings = [ + [ 'int8', 'float32', '@stdlib/math/base/special/sqrtf', true, 'float32', 'float32', 'stdlib_base_sqrtf', 'stdlib_ndarray_s_f_as_f_f' ], + [ 'float32', 'float32', '@stdlib/math/base/special/sqrtf', false, null, null, 'stdlib_base_sqrtf', 'stdlib_ndarray_f_f' ], + [ 'float32', 'float64', '@stdlib/math/base/special/sqrt', true, 'float64', 'float64', 'stdlib_base_sqrt', 'stdlib_ndarray_f_d_as_d_d' ], + [ 'float64', 'float64', '@stdlib/math/base/special/sqrt', false, null, null, 'stdlib_base_sqrt', 'stdlib_ndarray_d_d' ], + ... + ] + */ + + return mappings; +} + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/special/sqrt/src/addon.c b/lib/node_modules/@stdlib/math/special/sqrt/src/addon.c new file mode 100644 index 000000000000..bd7cada61ec3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/special/sqrt/src/addon.c @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* This is a generated file. Do not edit directly. */ +#include "stdlib/math/base/special/sqrtf.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/ndarray/base/function_object.h" +#include "stdlib/ndarray/base/napi/unary.h" +#include "stdlib/ndarray/base/unary.h" +#include "stdlib/ndarray/dtypes.h" +#include + +// Define an interface name: +static const char name[] = "stdlib_ndarray_sqrt"; + +// Define a list of ndarray functions: +static ndarrayFcn functions[] = { + // float32 (2) + stdlib_ndarray_f_f, + stdlib_ndarray_f_d_as_d_d, + + // float64 (1) + stdlib_ndarray_d_d, + + // int16 (2) + stdlib_ndarray_k_f_as_f_f, + stdlib_ndarray_k_d_as_d_d, + + // int32 (1) + stdlib_ndarray_i_d_as_d_d, + + // int8 (2) + stdlib_ndarray_s_f_as_f_f, + stdlib_ndarray_s_d_as_d_d, + + // uint16 (2) + stdlib_ndarray_t_f_as_f_f, + stdlib_ndarray_t_d_as_d_d, + + // uint32 (1) + stdlib_ndarray_u_d_as_d_d, + + // uint8 (2) + stdlib_ndarray_b_f_as_f_f, + stdlib_ndarray_b_d_as_d_d, + +}; + +// Define the array of input and output ndarray types: +static int32_t types[] = { + // float32 (2) + STDLIB_NDARRAY_FLOAT32, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_FLOAT32, STDLIB_NDARRAY_FLOAT64, + + // float64 (1) + STDLIB_NDARRAY_FLOAT64, STDLIB_NDARRAY_FLOAT64, + + // int16 (2) + STDLIB_NDARRAY_INT16, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_INT16, STDLIB_NDARRAY_FLOAT64, + + // int32 (1) + STDLIB_NDARRAY_INT32, STDLIB_NDARRAY_FLOAT64, + + // int8 (2) + STDLIB_NDARRAY_INT8, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_INT8, STDLIB_NDARRAY_FLOAT64, + + // uint16 (2) + STDLIB_NDARRAY_UINT16, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_UINT16, STDLIB_NDARRAY_FLOAT64, + + // uint32 (1) + STDLIB_NDARRAY_UINT32, STDLIB_NDARRAY_FLOAT64, + + // uint8 (2) + STDLIB_NDARRAY_UINT8, STDLIB_NDARRAY_FLOAT32, + STDLIB_NDARRAY_UINT8, STDLIB_NDARRAY_FLOAT64, + +}; + +// Define a list of ndarray function "data" (in this case, callbacks): +static void *data[] = { + // float32 (2) + (void *)stdlib_base_sqrtf, + (void *)stdlib_base_sqrt, + + // float64 (1) + (void *)stdlib_base_sqrt, + + // int16 (2) + (void *)stdlib_base_sqrtf, + (void *)stdlib_base_sqrt, + + // int32 (1) + (void *)stdlib_base_sqrt, + + // int8 (2) + (void *)stdlib_base_sqrtf, + (void *)stdlib_base_sqrt, + + // uint16 (2) + (void *)stdlib_base_sqrtf, + (void *)stdlib_base_sqrt, + + // uint32 (1) + (void *)stdlib_base_sqrt, + + // uint8 (2) + (void *)stdlib_base_sqrtf, + (void *)stdlib_base_sqrt, + +}; + +// Create an ndarray function object: +static const struct ndarrayFunctionObject obj = { + // ndarray function name: + name, + + // Number of input ndarrays: + 1, + + // Number of output ndarrays: + 1, + + // Total number of ndarray arguments (nin + nout): + 2, + + // Array containing ndarray functions: + functions, + + // Number of ndarray functions: + 13, + + // Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of ndarray argument types for a corresponding ndarray function: + types, + + // Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions): + data +}; + +STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj ) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary/data/function_list.json b/lib/node_modules/@stdlib/ndarray/base/unary/data/function_list.json new file mode 100644 index 000000000000..e969cc38f887 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary/data/function_list.json @@ -0,0 +1,147 @@ +[ + "stdlib_ndarray_b_b", + "stdlib_ndarray_b_b_as_u_u", + "stdlib_ndarray_b_c", + "stdlib_ndarray_b_c_as_b_c", + "stdlib_ndarray_b_c_as_c_c", + "stdlib_ndarray_b_c_as_z_z", + "stdlib_ndarray_b_d", + "stdlib_ndarray_b_d_as_b_d", + "stdlib_ndarray_b_d_as_d_d", + "stdlib_ndarray_b_f", + "stdlib_ndarray_b_f_as_b_f", + "stdlib_ndarray_b_f_as_d_d", + "stdlib_ndarray_b_f_as_f_f", + "stdlib_ndarray_b_i", + "stdlib_ndarray_b_i_as_b_i", + "stdlib_ndarray_b_i_as_i_i", + "stdlib_ndarray_b_k", + "stdlib_ndarray_b_k_as_b_k", + "stdlib_ndarray_b_k_as_i_i", + "stdlib_ndarray_b_k_as_k_k", + "stdlib_ndarray_b_t", + "stdlib_ndarray_b_t_as_b_t", + "stdlib_ndarray_b_t_as_t_t", + "stdlib_ndarray_b_t_as_u_u", + "stdlib_ndarray_b_u", + "stdlib_ndarray_b_u_as_b_u", + "stdlib_ndarray_b_u_as_u_u", + "stdlib_ndarray_b_z", + "stdlib_ndarray_b_z_as_b_z", + "stdlib_ndarray_b_z_as_z_z", + "stdlib_ndarray_c_c", + "stdlib_ndarray_c_c_as_z_z", + "stdlib_ndarray_c_f_as_c_f", + "stdlib_ndarray_c_z", + "stdlib_ndarray_c_z_as_c_z", + "stdlib_ndarray_c_z_as_z_z", + "stdlib_ndarray_d_d", + "stdlib_ndarray_d_i_as_d_i", + "stdlib_ndarray_d_z", + "stdlib_ndarray_d_z_as_d_z", + "stdlib_ndarray_d_z_as_z_z", + "stdlib_ndarray_f_c", + "stdlib_ndarray_f_c_as_c_c", + "stdlib_ndarray_f_c_as_f_c", + "stdlib_ndarray_f_c_as_z_z", + "stdlib_ndarray_f_d", + "stdlib_ndarray_f_d_as_d_d", + "stdlib_ndarray_f_d_as_f_d", + "stdlib_ndarray_f_f", + "stdlib_ndarray_f_f_as_d_d", + "stdlib_ndarray_f_i_as_f_i", + "stdlib_ndarray_f_z", + "stdlib_ndarray_f_z_as_f_z", + "stdlib_ndarray_f_z_as_z_z", + "stdlib_ndarray_i_d", + "stdlib_ndarray_i_d_as_d_d", + "stdlib_ndarray_i_d_as_i_d", + "stdlib_ndarray_i_i", + "stdlib_ndarray_i_u", + "stdlib_ndarray_i_z", + "stdlib_ndarray_i_z_as_i_z", + "stdlib_ndarray_i_z_as_z_z", + "stdlib_ndarray_k_c", + "stdlib_ndarray_k_c_as_c_c", + "stdlib_ndarray_k_c_as_k_c", + "stdlib_ndarray_k_c_as_z_z", + "stdlib_ndarray_k_d", + "stdlib_ndarray_k_d_as_d_d", + "stdlib_ndarray_k_d_as_k_d", + "stdlib_ndarray_k_f", + "stdlib_ndarray_k_f_as_d_d", + "stdlib_ndarray_k_f_as_f_f", + "stdlib_ndarray_k_f_as_k_f", + "stdlib_ndarray_k_i", + "stdlib_ndarray_k_i_as_i_i", + "stdlib_ndarray_k_i_as_k_i", + "stdlib_ndarray_k_k", + "stdlib_ndarray_k_k_as_i_i", + "stdlib_ndarray_k_t", + "stdlib_ndarray_k_t_as_i_i", + "stdlib_ndarray_k_u", + "stdlib_ndarray_k_u_as_i_i", + "stdlib_ndarray_k_z", + "stdlib_ndarray_k_z_as_k_z", + "stdlib_ndarray_k_z_as_z_z", + "stdlib_ndarray_s_b", + "stdlib_ndarray_s_c", + "stdlib_ndarray_s_c_as_c_c", + "stdlib_ndarray_s_c_as_s_c", + "stdlib_ndarray_s_c_as_z_z", + "stdlib_ndarray_s_d", + "stdlib_ndarray_s_d_as_d_d", + "stdlib_ndarray_s_d_as_s_d", + "stdlib_ndarray_s_f", + "stdlib_ndarray_s_f_as_d_d", + "stdlib_ndarray_s_f_as_f_f", + "stdlib_ndarray_s_f_as_s_f", + "stdlib_ndarray_s_i", + "stdlib_ndarray_s_i_as_i_i", + "stdlib_ndarray_s_i_as_s_i", + "stdlib_ndarray_s_k", + "stdlib_ndarray_s_k_as_i_i", + "stdlib_ndarray_s_k_as_k_k", + "stdlib_ndarray_s_k_as_s_k", + "stdlib_ndarray_s_s", + "stdlib_ndarray_s_s_as_i_i", + "stdlib_ndarray_s_t", + "stdlib_ndarray_s_t_as_i_i", + "stdlib_ndarray_s_u", + "stdlib_ndarray_s_u_as_i_i", + "stdlib_ndarray_s_z", + "stdlib_ndarray_s_z_as_s_z", + "stdlib_ndarray_s_z_as_z_z", + "stdlib_ndarray_t_c", + "stdlib_ndarray_t_c_as_c_c", + "stdlib_ndarray_t_c_as_t_c", + "stdlib_ndarray_t_c_as_z_z", + "stdlib_ndarray_t_d", + "stdlib_ndarray_t_d_as_d_d", + "stdlib_ndarray_t_d_as_t_d", + "stdlib_ndarray_t_f", + "stdlib_ndarray_t_f_as_d_d", + "stdlib_ndarray_t_f_as_f_f", + "stdlib_ndarray_t_f_as_t_f", + "stdlib_ndarray_t_i", + "stdlib_ndarray_t_i_as_i_i", + "stdlib_ndarray_t_i_as_t_i", + "stdlib_ndarray_t_t", + "stdlib_ndarray_t_t_as_u_u", + "stdlib_ndarray_t_u", + "stdlib_ndarray_t_u_as_t_u", + "stdlib_ndarray_t_u_as_u_u", + "stdlib_ndarray_t_z", + "stdlib_ndarray_t_z_as_t_z", + "stdlib_ndarray_t_z_as_z_z", + "stdlib_ndarray_u_d", + "stdlib_ndarray_u_d_as_d_d", + "stdlib_ndarray_u_d_as_u_d", + "stdlib_ndarray_u_u", + "stdlib_ndarray_u_z", + "stdlib_ndarray_u_z_as_u_z", + "stdlib_ndarray_u_z_as_z_z", + "stdlib_ndarray_x_x", + "stdlib_ndarray_z_d_as_z_d", + "stdlib_ndarray_z_z" +]