Skip to content

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

sahil20021008
Copy link
Contributor

@sahil20021008 sahil20021008 commented Apr 26, 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: 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 ---

Resolves #1891 .

Description

What is the purpose of this pull request?

This pull request:

  • proposes adding C implementation of stdlib/math/base/special/heaviside. This includes benchmarks, examples, tests, README files, etc.

Related Issues

Does this pull request have any related issues?

This pull request:

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

---
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
---
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Apr 26, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Apr 26, 2025

Coverage Report

Package Statements Branches Functions Lines
math/base/special/heaviside $\color{green}232/232$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}232/232$
$\color{green}+100.00\%$

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
---
@gunjjoshi gunjjoshi changed the title feat: add c implementation of stdlib/math/base/special/heaviside feat: add C implementation for math/base/special/heaviside May 2, 2025
@@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2025 The Stdlib Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright (c) 2025 The Stdlib Authors.
Copyright (c) 2018 The Stdlib Authors.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2018 The Stdlib Authors.
# Copyright (c) 2025 The Stdlib Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2025 The Stdlib Authors.
# Copyright (c) 2018 The Stdlib Authors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2025 The Stdlib Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2025 The Stdlib Authors.
* Copyright (c) 2018 The Stdlib Authors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -23,7 +23,7 @@ import heaviside = require( './index' );

// The function returns a number...
{
heaviside( 3.141592653589793 ); // $ExpectType number
heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType number
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 25 to 27
* @param x input value
* @param continuity continuity option
* @return function value
Copy link
Member

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.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Evaluate the [Heaviside function][heaviside-function].
Evaluates the [Heaviside function][heaviside-function].

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### stdlib_base_heaviside( x )
#### stdlib_base_heaviside( x, continuity )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 58 to 73
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;
Copy link
Member

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.

Copy link
Contributor Author

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
---
Copy link
Contributor Author

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

@@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2025 The Stdlib Authors.
Copy link
Contributor Author

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 )
Copy link
Contributor Author

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].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2018 The Stdlib Authors.
# Copyright (c) 2025 The Stdlib Authors.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2025 The Stdlib Authors.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -23,7 +23,7 @@ import heaviside = require( './index' );

// The function returns a number...
{
heaviside( 3.141592653589793 ); // $ExpectType number
heaviside( 3.141592653589793, 'half-maximum' ); // $ExpectType number
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 25 to 27
* @param x input value
* @param continuity continuity option
* @return function value
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 58 to 73
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;
Copy link
Contributor Author

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

@sahil20021008
Copy link
Contributor Author

Receiving the following error while using git push. Not sure why this is happening

Compiling benchmark...
make[1]: Entering directory '/workspaces/stdlib/lib/node_modules/@stdlib/math/base/special/heaviside/benchmark/c'
benchmark.c:24:10: fatal error: stdlib/math/base/special/heaviside.h: No such file or directory
   24 | #include "stdlib/math/base/special/heaviside.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:105: benchmark.out] Error 1
make[1]: Leaving directory '/workspaces/stdlib/lib/node_modules/@stdlib/math/base/special/heaviside/benchmark/c'
Error when attempting to compile benchmark.
ERROR: An error was encountered during execution.

make: *** [/workspaces/stdlib/tools/make/lib/benchmark/c.mk:84: benchmark-c-files] Error 1

Encountered an error when running C benchmarks.

have used git push --no-verify for now.
Any idea what is the issue here?
I was not facing this error earlier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add C implementation for math/base/special/heaviside
3 participants