{"id":43079644,"url":"https://github.com/zfergus/finite-diff","last_synced_at":"2026-01-31T14:33:42.277Z","repository":{"id":41346194,"uuid":"224032305","full_name":"zfergus/finite-diff","owner":"zfergus","description":"A simple finite-difference library using Eigen.","archived":false,"fork":false,"pushed_at":"2025-06-14T17:43:40.000Z","size":50,"stargazers_count":33,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-14T18:33:22.911Z","etag":null,"topics":["finite-differences","numerical-methods"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zfergus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-11-25T20:07:35.000Z","updated_at":"2025-06-14T17:36:08.000Z","dependencies_parsed_at":"2025-06-14T18:23:41.197Z","dependency_job_id":null,"html_url":"https://github.com/zfergus/finite-diff","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zfergus/finite-diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfergus%2Ffinite-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfergus%2Ffinite-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfergus%2Ffinite-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfergus%2Ffinite-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfergus","download_url":"https://codeload.github.com/zfergus/finite-diff/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfergus%2Ffinite-diff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28945719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T14:26:55.697Z","status":"ssl_error","status_checked_at":"2026-01-31T14:26:52.545Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finite-differences","numerical-methods"],"created_at":"2026-01-31T14:33:42.180Z","updated_at":"2026-01-31T14:33:42.263Z","avatar_url":"https://github.com/zfergus.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Finite Differences\n\n[![Build Status](https://github.com/zfergus/finite-diff/actions/workflows/continuous.yml/badge.svg)](https://github.com/zfergus/finite-diff/actions/workflows/continuous.yml)\n[![License](https://img.shields.io/github/license/zfergus/finite-diff.svg?color=blue)](https://opensource.org/licenses/MIT)\n\n**A simple finite-difference library using Eigen.**\n\n## Usage\n\n### Add it to CMake\n\nThe easiest way to add the library to an existing CMake project is to download it through CMake.\nCMake provides functionality for doing this called [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) (requires CMake ≥ 3.14).\nWe use this same process to download all external dependencies.\nFor example,\n\n```CMake\ninclude(FetchContent)\nFetchContent_Declare(\n    finite-diff\n    GIT_REPOSITORY https://github.com/zfergus/finite-diff.git\n    GIT_TAG ${FINITE_DIFF_GIT_TAG}\n    GIT_SHALLOW TRUE\n)\nFetchContent_MakeAvailable(finite-diff)\n```\n\nwhere `FINITE_DIFF_GIT_TAG` is set to the version you want to use. This will download and add the library to CMake. The library can then be linked against using\n\n```CMake\ntarget_link_libraries(${TARGET_NAME} PUBLIC finitediff::finitediff)\n```\n\nwhere `TARGET_NAME` is the name of your library/executable.\n\n### API\n\nAll functiononality can be included with `#include \u003cfinitediff.hpp\u003e`.\n\nThe library provides three main functions `finite_gradient`, `finite_jacobian`, and `finite_hessian`.\n\n#### `finite_gradient`:\n\n```c++\nvoid finite_gradient(\n    const Eigen::Ref\u003cconst Eigen::VectorXd\u003e\u0026 x,\n    const std::function\u003cdouble(const Eigen::VectorXd\u0026)\u003e\u0026 f,\n    Eigen::VectorXd\u0026 grad,\n    const AccuracyOrder accuracy = SECOND,\n    const double eps = 1.0e-8);\n```\n\nThe `finite_gradient` function computes the [gradient](https://en.wikipedia.org/wiki/Gradient) (first derivative) `grad` of a function `f: ℝⁿ ↦ ℝ` at a point `x`. This will result in a vector of size `n`.\n\n#### `finite_jacobian`:\n\n```c++\nvoid finite_jacobian(\n    const Eigen::Ref\u003cconst Eigen::VectorXd\u003e\u0026 x,\n    const std::function\u003cEigen::MatrixXd(const Eigen::VectorXd\u0026)\u003e\u0026 f,\n    Eigen::MatrixXd\u0026 jac,\n    const AccuracyOrder accuracy = SECOND,\n    const double eps = 1.0e-8);\n```\n\nThe `finite_jacobian` function computes the [Jacobian](https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant) (first derivative) `jac` of a function `f: ℝⁿ ↦ ℝᵐ` at a point `x`. This will result in a matrix of size `m × n`.\n\n\n#### `finite_hessian`:\n\n```c++\nvoid finite_hessian(\n    const Eigen::Ref\u003cconst Eigen::VectorXd\u003e\u0026 x,\n    const std::function\u003cdouble(const Eigen::VectorXd\u0026)\u003e\u0026 f,\n    Eigen::MatrixXd\u0026 hess,\n    const AccuracyOrder accuracy = SECOND,\n    const double eps = 1.0e-5);\n```\n\nThe `finite_hessian` function computes the [Hessian](https://en.wikipedia.org/wiki/Hessian_matrix) (second derivative) `hess` of a function `f: ℝⁿ ↦ ℝ` at a point `x`. This will result in a matrix of size `n × n`.\n\n#### `AccuracyOrder`:\n\nEach finite difference function takes as input the accuracy order for the method. Possible options are:\n```c++\nenum AccuracyOrder {\n    SECOND, // Second order accuracy.\n    FOURTH, // Fourth order accuracy.\n    SIXTH,  // Sixth order accuracy.\n    EIGHTH  // Eighth order accuracy.\n};\n```\n\n#### `eps`:\n\nThe parameter `eps` is the finite difference step size. Smaller values result in a more accurate approximation, but too small of a value can result in a large numerical error because the difference will be divided by a small number.\n\n## Dependencies\n\n**All dependencies are downloaded through CMake** depending on the build options.\nThe following libraries are used in this project:\n\n* [Eigen](https://eigen.tuxfamily.org/): linear algebra\n* [spdlog](https://github.com/gabime/spdlog): logging information\n\n### Optional\n\n* [Catch2](https://github.com/catchorg/Catch2.git): testing (see [Unit Tests](#unit_tests))\n\n## \u003ca name=\"unit_tests\"\u003e\u003c/a\u003eUnit Tests\n\nWe provide unit tests for ensuring the correctness of our functions.\nTo enable the unit tests, use the flag `-DFINITE_DIFF_BUILD_UNIT_TESTS=ON` with CMake.\n\n## Contributing\n\nThis project is open to contributors! Contributions can come in the form of feature requests, bug fixes, documentation, tutorials and the like. We highly recommend filing an Issue first before submitting a Pull Request.\n\nSimply fork this repository and make a Pull Request! We'd appreciate:\n\n* Implementation of new features\n* Bug Reports\n* Documentation\n* Testing\n\n## License\n\nMIT License © 2019, Zachary Ferguson (See [`LICENSE.txt`](https://github.com/zfergus/finite-diff/blob/main/LICENSE) for details).\n\n### Acknowledgements\n\nBased on the functions in [CppNumericalSolvers](https://github.com/PatWie/CppNumericalSolvers/blob/v2/include/cppoptlib/utils/derivatives.h)\nby Patrick Wieschollek and rewritten to use Eigen.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfergus%2Ffinite-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfergus%2Ffinite-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfergus%2Ffinite-diff/lists"}