-
-
Notifications
You must be signed in to change notification settings - Fork 993
feat: add C implementation for math/base/special/heaviside
#6823
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: passed
- task: lint_package_json
status: passed
- 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: 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: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
---
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: passed
- task: lint_c_examples
status: passed
- 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
---
math/base/special/heaviside
| @license Apache-2.0 | ||
| Copyright (c) 2018 The Stdlib Authors. | ||
| Copyright (c) 2025 The Stdlib Authors. |
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.
| Copyright (c) 2025 The Stdlib Authors. | |
| Copyright (c) 2018 The Stdlib Authors. |
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.
We can avoid updating copyright years for pre-existing files.
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.
Done
| # @license Apache-2.0 | ||
| # | ||
| # Copyright (c) 2018 The Stdlib Authors. | ||
| # Copyright (c) 2025 The Stdlib Authors. |
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.
| # Copyright (c) 2025 The Stdlib Authors. | |
| # Copyright (c) 2018 The Stdlib Authors. |
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.
Done
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2018 The Stdlib Authors. | ||
| * Copyright (c) 2025 The Stdlib Authors. |
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.
| * Copyright (c) 2025 The Stdlib Authors. | |
| * Copyright (c) 2018 The Stdlib Authors. |
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.
Done
| // The function returns a number... | ||
| { | ||
| heaviside( 3.141592653589793 ); // $ExpectType number | ||
| heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType 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.
I don't think this is necessary, @sahil20021008. We want to demonstrate the default case here, without the second argument, such as the function is discontinuous at 0.
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 can revert this change.
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.
Done
| * @param x input value | ||
| * @param continuity continuity option | ||
| * @return function value |
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.
The indentation is off 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.
Done
|
|
||
| #### stdlib_base_heaviside( x ) | ||
|
|
||
| Evaluate the [Heaviside function][heaviside-function]. |
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.
| Evaluate the [Heaviside function][heaviside-function]. | |
| Evaluates the [Heaviside function][heaviside-function]. |
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.
Done
| #include "stdlib/math/base/special/heaviside.h" | ||
| ``` | ||
|
|
||
| #### stdlib_base_heaviside( x ) |
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.
| #### stdlib_base_heaviside( x ) | |
| #### stdlib_base_heaviside( x, continuity ) |
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.
Done
| if ( stdlib_base_is_nan( x )) { | ||
| return 0.0/0.0; | ||
| } | ||
| if ( x > 0.0 ) { | ||
| return 1.0; | ||
| } | ||
| if ( x == 0.0 ) { | ||
| if ( continuity == 0 ) { | ||
| return 0.0; | ||
| }else if ( continuity == 1 ) { | ||
| return 1.0; | ||
| }else if ( continuity == 2 ) { | ||
| return 0.5; | ||
| } | ||
| // Default behaviour is discontinuity | ||
| return 0.0/0.0; |
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.
Spacing is off at certain places here, will need to be fixed.
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.
Not exactly sure where the placing has to be improved
For now, I have fixed placing at line 58, but please lmk if changes required anywhere else also.
Thanks
---
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: passed
- 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: passed
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
sahil20021008
left a comment
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.
Hi @gunjjoshi
I have addressed your review comments.
| @license Apache-2.0 | ||
| Copyright (c) 2018 The Stdlib Authors. | ||
| Copyright (c) 2025 The Stdlib Authors. |
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.
Done
| #include "stdlib/math/base/special/heaviside.h" | ||
| ``` | ||
|
|
||
| #### stdlib_base_heaviside( x ) |
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.
Done
|
|
||
| #### stdlib_base_heaviside( x ) | ||
|
|
||
| Evaluate the [Heaviside function][heaviside-function]. |
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.
Done
| # @license Apache-2.0 | ||
| # | ||
| # Copyright (c) 2018 The Stdlib Authors. | ||
| # Copyright (c) 2025 The Stdlib Authors. |
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.
Done
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2018 The Stdlib Authors. | ||
| * Copyright (c) 2025 The Stdlib Authors. |
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.
Done
| // The function returns a number... | ||
| { | ||
| heaviside( 3.141592653589793 ); // $ExpectType number | ||
| heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType 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.
Done
| * @param x input value | ||
| * @param continuity continuity option | ||
| * @return function value |
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.
Done
| if ( stdlib_base_is_nan( x )) { | ||
| return 0.0/0.0; | ||
| } | ||
| if ( x > 0.0 ) { | ||
| return 1.0; | ||
| } | ||
| if ( x == 0.0 ) { | ||
| if ( continuity == 0 ) { | ||
| return 0.0; | ||
| }else if ( continuity == 1 ) { | ||
| return 1.0; | ||
| }else if ( continuity == 2 ) { | ||
| return 0.5; | ||
| } | ||
| // Default behaviour is discontinuity | ||
| return 0.0/0.0; |
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.
Not exactly sure where the placing has to be improved
For now, I have fixed placing at line 58, but please lmk if changes required anywhere else also.
Thanks
|
Receiving the following error while using have used |
---
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:
Resolves #1891 .
Description
This pull request:
stdlib/math/base/special/heaviside. This includes benchmarks, examples, tests, README files, etc.Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers