Skip to content

Instantly share code, notes, and snippets.

@chvandorp
Created January 3, 2021 23:03
#ifndef AUTOGRAD_HPP_
#define AUTOGRAD_HPP_
#include "dual.hpp"
#include <functional>
#include <vector>
// simple 1D derivative
std::function<double(double)> derivative(std::function<Dual(Dual)> f);
// some shorthands
typedef std::vector<double> RealVec;
typedef std::vector<Dual> DualVec;
// gradient
std::function<RealVec(const RealVec&)> gradient(std::function<Dual(const DualVec&)> F);
// directional derivative
std::function<double(const RealVec&, const RealVec&)> grad_vec_prod(std::function<Dual(const DualVec&)> F);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment