Invalid results in forward mode with the new C++ interface for a function returning a `std::array`
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 26
Description
The issue is probably due to my own inexperience.
The following snippet returns the value of the function rather than its derivative:
~~~~c++
const double x = 1.0;
const double dx = 1.0;
const auto c = [](const double& x) {
return std::array{std::cos(x), 2*std::sin(x)};
};
const auto dfdx = ::enzyme::get<0>(enzyme::autodiff<::enzyme::Forward>(
+c, ::enzyme::Duplicated{x, dx}));
std::cout << "dfdx:\n" << dfdx[0] << ", expected: " << -std::sin(1) << "\n"
<< dfdx[1] << ", expected: " << 2 * std::cos(1) << std::endl;
~~~~
In contrast, the old interface behaves correctly
~~~~c++
const auto dfdx_2 =
__enzyme_fwddiff>(+c, enzyme_dup, &x, &dx);
std::cout << "dfdx_2:\n" << dfdx_2[0] << ", expected: " << -std::sin(1) << "\n"
<< dfdx_2[1] << ", expected: " << 2 * std::cos(1) << std::endl;
~~~~
Any help would be appreciated ! @samuelpmish ?
P.S. `enzyme::autodiff<::enzyme::Forward>` works fine for scalar valuated functions.
Contributor guide
Assessment
This issue has not been assessed yet.