Skip to content

fix #1698 - Add a way to specify non-differentiability of pre-existing functions in forward mode#1703

Open
Lucky-Lodhi2004 wants to merge 5 commits intovgvassilev:masterfrom
Lucky-Lodhi2004:specify-non-differentiability
Open

fix #1698 - Add a way to specify non-differentiability of pre-existing functions in forward mode#1703
Lucky-Lodhi2004 wants to merge 5 commits intovgvassilev:masterfrom
Lucky-Lodhi2004:specify-non-differentiability

Conversation

@Lucky-Lodhi2004
Copy link
Copy Markdown
Contributor

This PR adds support for void pushforward functions in forward mode. When a pushforward function returns void, it signals that the original function is non-differentiable. Clad will now treat such functions as constant (derivative = 0) while still calling the original function.

Changes include updates in DiffPlanner.cpp and BaseForwardModeVisitor to handle void pushforwards correctly. I have added a new test (ForwardMode/VoidPushforward.C) to verify this behavior.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread lib/Differentiator/DiffPlanner.cpp Outdated
const auto* FTP = dTy->getAs<FunctionProtoType>();

for (LookupResult::iterator I = Found.begin(), E = Found.end(); I != E; ++I) {
FunctionDecl* FD = dyn_cast<FunctionDecl>(I.getDecl());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]

Suggested change
FunctionDecl* FD = dyn_cast<FunctionDecl>(I.getDecl());
auto* FD = dyn_cast<FunctionDecl>(I.getDecl());

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/Differentiator/DiffPlanner.cpp 85.71% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev vgvassilev force-pushed the specify-non-differentiability branch from dae6ee9 to 7f303a9 Compare February 3, 2026 09:35
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev vgvassilev force-pushed the specify-non-differentiability branch from 7f303a9 to 3b600b0 Compare February 3, 2026 11:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

clang-tidy review says "All clean, LGTM! 👍"

@parth-07
Copy link
Copy Markdown
Collaborator

parth-07 commented Feb 3, 2026

How will we specify the non-differentiability of void functions? Perhaps it would be better to have a dedicated type for this such as:

clad::NonDiff fn_pushforward(...) { ... }

@vgvassilev vgvassilev force-pushed the specify-non-differentiability branch from 3b600b0 to 07e681a Compare February 18, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants