https://github.com/gha3mi/fordiff
ForDiff - A Fortran library for numerical differentiation
https://github.com/gha3mi/fordiff
complex-step-differentiation derivative differentiation finite-difference fortran fortran-package-manager
Last synced: 3 months ago
JSON representation
ForDiff - A Fortran library for numerical differentiation
- Host: GitHub
- URL: https://github.com/gha3mi/fordiff
- Owner: gha3mi
- License: bsd-3-clause
- Created: 2023-07-02T19:32:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-09-11T22:00:39.000Z (9 months ago)
- Last Synced: 2025-09-11T23:08:26.381Z (9 months ago)
- Topics: complex-step-differentiation, derivative, differentiation, finite-difference, fortran, fortran-package-manager
- Language: Fortran
- Homepage: https://gha3mi.github.io/fordiff/
- Size: 1.44 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/gha3mi/fordiff)
[](https://github.com/gha3mi/fordiff/releases)
[](https://gha3mi.github.io/fordiff/)
[](https://github.com/gha3mi/fordiff/actions/workflows/CI-CD.yml)
[](https://github.com/gha3mi/fordiff/blob/main/LICENSE)
**ForDiff**: A Fortran library for numerical differentiation
- [fpm dependency](#fpm-dependency)
- [Usage](#usage)
- [Run Demos](#run-demos)
- [Run Tests](#run-tests)
- [TODO](#todo)
- [CI Status](#ci-status)
- [API documentation](#api-documentation)
- [Contributing](#contributing)
## fpm dependency
To use `ForDiff` as a dependency in your fpm project, include the following line in your `fpm.toml` file:
```toml
[dependencies]
fordiff = {git="https://github.com/gha3mi/fordiff.git"}
```
## Usage
```fortran
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.
```bash
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.
```bash
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.
```bash
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:
```bash
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](https://gha3mi.github.io/fordiff/).
To generate the API documentation for `ForDiff` using
[ford](https://github.com/Fortran-FOSS-Programmers/ford) run the following
command:
```shell
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.