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

Failure in differentiating call expression to a function object #625

Closed
vaithak opened this issue Sep 5, 2023 · 0 comments · Fixed by #626
Closed

Failure in differentiating call expression to a function object #625

vaithak opened this issue Sep 5, 2023 · 0 comments · Fixed by #626

Comments

@vaithak
Copy link
Collaborator

vaithak commented Sep 5, 2023

Results in the following assertion failure:

ReverseModeVisitor.cpp:1463: clad::StmtDiff clad::ReverseModeVisitor::VisitCallExpr(const clang::CallExpr*): Assertion `!utils::isArrayOrPointerType(arg->getType()) && "Arguments passed by pointers should be covered in pass by " "reference calls"' failed.

Minimal reproducible example (taken from #618) :

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

struct FunObj {
   double operator()(double *x, size_t n)
   {  double ret = 0;
      for (size_t i = 0; i < n; i++) {
         ret += (i+1) * x[i];
      }
      return ret;
   }
};

double f(double *x, size_t n){
  FunObj f_obj;
  return f_obj(x, n);
}

int main() {
   size_t n = 3;
   double x[] = {1.0, 2.0, 3.0};
   double fx = f(x, n);
   std::cout << "f(x, n) = " << fx << "\n";

   auto f_dx = clad::gradient(f, "x");
   double dx[] = {0.0, 0.0, 0.0};
   clad::array_ref<double> dx_ref(dx, n);
   f_dx.execute(x, n, dx_ref);

   for(size_t i = 0; i < n; ++i)
      std::cout << "df/dx[" << i << "] = " << dx[i] << "\n";
   return 0;
}
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 a pull request may close this issue.

1 participant