Skip to content

Conversation

@gunjjoshi
Copy link
Member

Resolves None.

Description

What is the purpose of this pull request?

This pull request:

  • adds scaffold templates and scripts for generating packages in math/special/*.

Related Issues

Does this pull request have any related issues?

None.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Tools Issue or pull request related to project tooling. Needs Review A pull request which needs code review. labels Sep 24, 2025
@gunjjoshi gunjjoshi marked this pull request as draft September 24, 2025 16:38
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 24, 2025
---
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
---
---
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
---
Comment on lines +396 to +399
// for ( i = 0; i < dataKeys.length; i++ ) {

// dataKey = dataKeys[ i ];
dataKey = '@stdlib/math/base/special/acosd';
Copy link
Member Author

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
---
@gunjjoshi gunjjoshi marked this pull request as ready for review September 30, 2025 18:17
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 30, 2025
@gunjjoshi
Copy link
Member Author

gunjjoshi commented Sep 30, 2025

Getting some CI failures which might be arising from @stdlib/ndarray/base/unary, specifically from here: https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/ndarray/base/unary/src/c_d_as_z_d.c . Maybe, it must have stdlib_complex128_t instead of stdlib_complex64_t?

@kgryte
Copy link
Member

kgryte commented Oct 3, 2025

@gunjjoshi Yes, I'll try and take a look at ndarray/base/unary tonight.

@kgryte
Copy link
Member

kgryte commented Nov 5, 2025

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Nov 5, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Nov 5, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Nov 5, 2025

Coverage Report

Package Statements Branches Functions Lines
math/special/acosd $\color{green}349/349$
$color{green}+100.00%$
$\color{green}7/7$
$color{green}+100.00%$
$\color{green}0/0$
$color{green}+100.00%$
$\color{green}349/349$
$color{green}+100.00%$

The above coverage report was generated for the changes in this PR.

Parameters
----------
x: ndarray
Input array. Must have a numeric or "generic" data type.
Copy link
Member

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';
Copy link
Member

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
Copy link
Member

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>
Copy link
Member

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
Copy link
Member

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}} );
Copy link
Member

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.

Copy link
Member

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?

@@ -0,0 +1,12 @@
{
"input_dtypes": {
Copy link
Member

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.

matches = result.reorderedMatches;

cOut = header;
cOut += Object.keys( uniqueIncludes ).join( '\n' ) + '\n';
Copy link
Member

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();
Copy link
Member

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, {
Copy link
Member

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.

v = values[ i ];
results = func( v );
results = round( results * 100 ) / 100; // Rounding results to 2 decimal places
vals.push( '~' + results.toString() );
Copy link
Member

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.


// Using the scalar kernels to compute the dependencies:
scalarKernels = funcData.scalar_kernels;
keys = Object.keys( scalarKernels );
Copy link
Member

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( '/' ) ) {
Copy link
Member

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.

Comment on lines 425 to 428
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';
Copy link
Member

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() + '\'' );
Copy link
Member

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 = [
Copy link
Member

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 ) {
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

@kgryte kgryte left a 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.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Changes Pull request which needs changes before being merged. Tools Issue or pull request related to project tooling.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants