Skip to content
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

Add support for std::get and template arguments in pushforwards/pullbacks #1095

Open
gojakuch opened this issue Sep 15, 2024 · 0 comments
Open

Comments

@gojakuch
Copy link
Collaborator

currently, if there's a function accepting a template argument that cannot be resolved automatically by inferring it from its arguments (like std::get for example), it's not possible to use the automatically generated pushforward/pullback for it:

#include "clad/Differentiator/Differentiator.h"
#include <iostream>

template<int N>
double take(double x, double y) {
    return 0;
}
template<>
double take<0>(double x, double y) {
    return x;
}
template<>
double take<1>(double x, double y) {
    return y;
}

double fn(double u) {
    double a = take<0>(u, 2*u);
    double b = take<1>(u, 2*u);
    return a+b; // = 3*u
}

int main() {
    auto df = clad::differentiate(fn, "u");
    std::cout << "f(3)=" << fn(3.0);
    std::cout << "; df(3)=" << df.execute(3.0) << '\n';
}

expected output:
f(3)=9; df(3)=3
output:
f(3)=9; df(3)=2

while Clad does create two different pushforwards for these specialisations, it only calls one of them, failing to distinguish between those.

std::get when used as std::get<10>(my_tuple), for instance, would cause this too, which is why it's important to solve this issue to fully support STL or even tuples.

this must be solved in both fwd and rvs modes in a way that also allows custom derivatives to be provided for these functions.

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

No branches or pull requests

1 participant