adventure is a fast and lightweight C++20 library providing reverse-mode automatic differentiation using Jacobi tapes and expression templates.
- first-order reverse-mode derivatives using Jacobi tapes
- expression templates
- thread-local tapes
- header-only
- C++20
- Include
adventure/variable.hppand use theadventure::VariableAPI:
#include <iostream>
#include "adventure/variable.hpp"
namespace ad = adventure;
int main() {
ad::Variable<double> x(2.0);
ad::register_input(x);
ad::Variable<double> y = x * x;
ad::register_output(y);
y.grad() = 1.0; // seed output
ad::backward<double>(); // compute adjoints
double dx = x.grad(); // gradient dy/dx
std::cout << "x.grad() = " << dx << std::endl;
}Configure and build in a separate directory:
cmake -S . -B build
cmake --build buildAfter building, run the tests with ctest:
ctest --test-dir build --output-on-failureBenchmarks are optional but enabled by default. After building, run the
benchmark executables in build/benchmarks/ (e.g. benchmark_ad).
adventure is licensed under the Apache License, Version 2.0 (see LICENSE).
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.