-
-
Notifications
You must be signed in to change notification settings - Fork 932
build: add scaffolding to generate math/special/* packages
#8139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/dtype_ndarray_mappings.json
Show resolved
Hide resolved
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: skipped
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: passed
- task: lint_repl_help
status: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: missing_dependencies
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: skipped
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
| // for ( i = 0; i < dataKeys.length; i++ ) { | ||
|
|
||
| // dataKey = dataKeys[ i ]; | ||
| dataKey = '@stdlib/math/base/special/acosd'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing initially, I didn't generate all of the packages using the for loop. Instead, I have hardcoded acosd, to generate it.
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: skipped
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
|
Getting some CI failures which might be arising from |
|
@gunjjoshi Yes, I'll try and take a look at |
|
/stdlib merge |
Coverage Report
The above coverage report was generated for the changes in this PR. |
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/README__md.txt
Show resolved
Hide resolved
| Parameters | ||
| ---------- | ||
| x: ndarray | ||
| Input array. Must have a numeric or "generic" data type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gunjjoshi Looks like we need an "input policy phrase" here. "numeric" is not true for all apis (e.g., those not supporting complex input dtypes).
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| import { typedndarray, {{NDARRAY_IMPORT_TYPES}}, genericndarray, RealAndGenericDataType as DataType, Order } from '@stdlib/types/ndarray'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct. RealAndGenericDataType will not be correct for all APIs. opts.dtype is subject to the output dtype policy.
| * var arr = ndarray2array( y ); | ||
| * // returns {{JS_EXAMPLE_RESULTS_2X2}} | ||
| */ | ||
| ( x: InputArray, options?: Options ): typedndarray<number>; // FIXME: we lose type specificity here, as the output ndarray data type is determined according to the output data type policy in conjunction with the `dtype` option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct. E.g., what happens if a unary function returns a complex number? Meaning, number is not always correct. I don't have a great solution for this. We may need to do conditional overloads. Meaning, for those apis accepting and returning complex numbers, we may need an overload for when x is a complex array, as then the output should also be a complex array. In short, the structure of this file depends on the output dtype policy.
| 'dtype': 'float64' | ||
| }); | ||
|
|
||
| {{ALIAS}}( x ); // $ExpectType typedndarray<number> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing. The output array may or may not contain numbers depending on the API and the input array dtype.
| 'dtype': 'float64' | ||
| }); | ||
|
|
||
| {{ALIAS}}.assign( x, x ); // $ExpectType float64ndarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works so long as an api accepts floating-point ndarrays. That may not always be true. The use of float64 throughout this file and examples assumes floating-point support.
| var ndarray2array = require( '@stdlib/ndarray/to-array' ); | ||
| var array = require( '@stdlib/ndarray/array' ); | ||
|
|
||
| var x = array( {{JS_EXAMPLE_VALUES_2X2}} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little tricky, as it assumes that x is allowed to be a float64 array. I am not sure that will always be the case. E.g., we could have a ufunc which only accept integer arrays or complex number arrays, etc. I am not sure the most robust solution here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that, for all ufuncs in math special, we will support float64, float32, and generic?
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__js.txt
Outdated
Show resolved
Hide resolved
...node_modules/@stdlib/_tools/scaffold/math-special-unary/data/test/test__main__native__js.txt
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,12 @@ | |||
| { | |||
| "input_dtypes": { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed during a previous call, you can build out this table for completeness to include other dtype mappings.
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/generate_files.js
Outdated
Show resolved
Hide resolved
| matches = result.reorderedMatches; | ||
|
|
||
| cOut = header; | ||
| cOut += Object.keys( uniqueIncludes ).join( '\n' ) + '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gunjjoshi Use @stdlib/utils/keys.
|
|
||
| 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gunjjoshi Use uppercase string utility. stdlib/string/base/uppercase.
|
|
||
| // Generate types.js: | ||
| jsOut = generateTypesFile( matches, header ); | ||
| writeFileSync( join( destDir, 'lib/types.js' ), jsOut, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You make heavy use of string concatenation to generate entire files, including license headers. I wonder if we could use template files with handlebar template strings {{}} similar to what we do for other files. That might reduce the visual noise in this file.
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/output_policy_phrases.json
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js
Outdated
Show resolved
Hide resolved
| v = values[ i ]; | ||
| results = func( v ); | ||
| results = round( results * 100 ) / 100; // Rounding results to 2 decimal places | ||
| vals.push( '~' + results.toString() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you only want to round if the result is not exact (i.e., an integer value). Otherwise, if results are exact, you don't need a ~. Furthermore, if integer-valued, you also need to include trailing .0 characters to the results if the array type is floating-point.
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js
Show resolved
Hide resolved
|
|
||
| // Using the scalar kernels to compute the dependencies: | ||
| scalarKernels = funcData.scalar_kernels; | ||
| keys = Object.keys( scalarKernels ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use utils/keys.
|
|
||
| for ( i = 0; i < keys.length; i++ ) { | ||
| kernelPath = scalarKernels[ keys[ i ] ]; | ||
| if ( kernelPath.startsWith( '/' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string/[base/]starts-with.
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js
Outdated
Show resolved
Hide resolved
| pkgDesc = 'Compute the ' + o.short_desc + ' for each element in an ndarray.'; | ||
| moduleDesc = 'Compute the ' + o.short_desc + '.'; | ||
| mainDesc = 'Computes the ' + o.short_desc + ' for each element in an ndarray.'; | ||
| testDesc = 'computes the ' + o.short_desc + ' for each element in an ndarray'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me: what is our plan for functions like round?
| keywords = keywords.concat( o.extra_keywords ); | ||
| } | ||
| envs.push( 'KEYWORDS=\'' + keywords.join( ',' ) + '\'' ); | ||
| envs.push( 'YEAR=\'' + new Date().getFullYear() + '\'' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use time/current-year.
| /* | ||
| * For the first iteration: | ||
| * | ||
| * allowedCasts = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'float32' and 'float64' are not mostly safe casts for 'complex64'
| // Remove the dtypes which are not allowed for output, according to the output policy: | ||
| filtered = []; | ||
| for ( k = 0; k < allowedCasts.length; k++ ) { | ||
| if ( odt.indexOf( allowedCasts[ k ] ) !== -1 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using array/base/assert/contains rather than indexOf here and elsewhere when searching for needles in arrays.
|
|
||
| // Extract the function name from the scalar kernel path and create C function name: | ||
| cFunctionName = scalarKernel.split( '/' ).pop(); // Get last part (Ex: 'acosd') | ||
| cFunctionName = 'stdlib_base_' + cFunctionName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't always correct. E.g., stdlib_base_float64_identity.
lib/node_modules/@stdlib/_tools/scaffold/math-special-unary/scripts/runner.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left an initial review. Main concerns revolve around edge cases.
Resolves None.
Description
This pull request:
math/special/*.Related Issues
None.
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers