Fix typo in a variable name in example code.

* Rename df2dx2 to d2fdx2 - the appropriate naming for the second derivative

* Update CONTRIBUTING.md - add needed python packages, and a virtual-env hint
This commit is contained in:
Ravindra Jaju 2024-05-11 21:34:52 +05:30
parent ff4223904d
commit bc10a17534
2 changed files with 6 additions and 3 deletions

View File

@ -11,9 +11,10 @@ possible.
and after the change. Examples of benchmarks can be found in `benchmarks/python/`. and after the change. Examples of benchmarks can be found in `benchmarks/python/`.
4. If you've changed APIs, update the documentation. 4. If you've changed APIs, update the documentation.
5. Every PR should have passing tests and at least one review. 5. Every PR should have passing tests and at least one review.
6. For code formatting install `pre-commit` using something like `pip install pre-commit` and run `pre-commit install`. 6. For code formatting install `pre-commit`, `black` and `clang-format` using something like `pip install pre-commit black clang-format` and run `pre-commit install`.
This should install hooks for running `black` and `clang-format` to ensure This should install hooks for running `black` and `clang-format` to ensure
consistent style for C++ and python code. consistent style for C++ and python code.
For convenience, you can set up the repository-specific Python virtualenv inside the `venv` directory at the root of the repository - it is ignored by git.
You can also run the formatters manually as follows: You can also run the formatters manually as follows:

View File

@ -89,8 +89,10 @@ void automatic_differentiation() {
// dfdx is 2 * x // dfdx is 2 * x
// Get the second derivative by composing grad with grad // Get the second derivative by composing grad with grad
auto df2dx2 = grad(grad(fn))(x); auto d2fdx2 = grad(grad(fn))(x);
// df2dx2 is 2 // d2fdx2 is 2
std::cout << d2fdx2 << std::endl;
assert(d2fdx2.item<float>() - 2.0 <= std::numeric_limits<float>::epsilon());
} }
int main() { int main() {