Following on from #2994 and possibly related to #2914:
#include <vector>
#include <cassert>
extern int enzyme_out;
extern int enzyme_const;
template < typename return_type, typename ... T >
return_type __enzyme_autodiff(void*, T ... );
struct DataStructure
{
const std::vector<double> m_vec{};
DataStructure(const std::vector<double>& V): m_vec{V} {};
double multiplyAndSumBy(double num) const;
};
double DataStructure::multiplyAndSumBy(double num) const
{
double sum{0};
for (double element: m_vec)
sum += num*element;
return sum;
}
double calculate(double num, const DataStructure& DS) {return DS.multiplyAndSumBy(num);}
int main()
{
const DataStructure DS{{1, 2, 3}};
const DataStructure DSCopy{DS};
double num{2};
double grad{
__enzyme_autodiff<double>((void*)calculate, enzyme_out, num, enzyme_const, &DS)
};
assert(DS.m_vec==DSCopy.m_vec && "const object mutated!");
return 0;
}
Looks like enzyme is definitely modifying const objects passed to differentiated functions.
If there is anything i can do to help, I really like this library and would love to start contributing.
Following on from #2994 and possibly related to #2914:
Looks like enzyme is definitely modifying const objects passed to differentiated functions.
If there is anything i can do to help, I really like this library and would love to start contributing.