Find us on…

GitHub

ForDiff

GitHub Version Documentation Setup Fortran Conda CI/CD License

ForDiff: A Fortran library for numerical differentiation

fpm dependency

To use ForDiff as a dependency in your fpm project, include the following line in your fpm.toml file:

[dependencies]
fordiff = {git="https://github.com/gha3mi/fordiff.git"}

Usage

use fordiff
dfdx = derivative(f, x, h, method)

Run Demos

example/demo1.f90 demonstrates how to compute the derivative of a scalar-valued function w.r.t to a scalar variable using complex-step and finite-difference methods.

fpm run --example demo1

example/demo2.f90 demonstrates how to compute the derivative of a scalar-valued function w.r.t to a vector variable using complex-step and finite-difference methods.

fpm run --example demo2

example/demo3.f90 demonstrates how to compute the derivative of a vector-valued function w.r.t to a vector variable using complex-step and finite-difference methods.

fpm run --example demo3

Run Tests

The tests directory contains test programs to verify the functionality of the fordiff module. To run the tests using fpm, you can use:

fpm test

TODO

  • [x] Complex-step: f(x) f is a scalar-valued function and x is a scalar variable
  • [x] Complex-step: f(x) f is a scalar-valued function and x is a vector variable
  • [x] Complex-step: f(x) f is a vector-valued function and x is a vector variable
  • [x] Finite Difference: f(x) f is a scalar-valued function and x is a scalar variable
  • [x] Finite Difference: f(x) f is a scalar-valued function and x is a vector variable
  • [x] Finite Difference: f(x) f is a vector-valued function and x is a vector variable
  • [ ] Automatic Differentiation

CI Status

Compiler macos ubuntu windows
flang-new - fpm ✅ fpm ✅
gfortran fpm ✅ fpm ✅ fpm ✅
ifx - fpm ✅ fpm ✅
lfortran fpm ❌ fpm ❌ fpm ❌
nvfortran - fpm ✅ -

API documentation

The most up-to-date API documentation for the main branch is available here. To generate the API documentation for ForDiff using ford run the following command:

ford README.md

Contributing

Contributions to fordiff are welcome! If you find any issues or would like to suggest improvements, please open an issue or submit a pull request.

Developer Info

Seyed Ali Ghasemi