{"id":34039543,"url":"https://github.com/famura/ndc","last_synced_at":"2026-03-17T16:33:16.459Z","repository":{"id":42003239,"uuid":"480485345","full_name":"famura/ndc","owner":"famura","description":"Numerical differentiation leveraging convolutions based on PyTorch","archived":false,"fork":false,"pushed_at":"2022-04-19T09:29:00.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T14:01:56.888Z","etag":null,"topics":["convolution","finite-differences","numerical-differentiation","pytorch","signal-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","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/famura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-11T17:35:57.000Z","updated_at":"2023-10-25T08:36:07.000Z","dependencies_parsed_at":"2022-08-12T02:00:57.551Z","dependency_job_id":null,"html_url":"https://github.com/famura/ndc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/famura/ndc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/famura%2Fndc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/famura%2Fndc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/famura%2Fndc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/famura%2Fndc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/famura","download_url":"https://codeload.github.com/famura/ndc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/famura%2Fndc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30627176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T14:16:03.965Z","status":"ssl_error","status_checked_at":"2026-03-17T14:16:03.380Z","response_time":56,"last_error":"SSL_read: 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":["convolution","finite-differences","numerical-differentiation","pytorch","signal-processing"],"created_at":"2025-12-13T21:42:08.371Z","updated_at":"2026-03-17T16:33:16.443Z","avatar_url":"https://github.com/famura.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numerical Differentiation Leveraging Convolution (ndc)\n\n[![License](https://img.shields.io/badge/license-MIT-brightgreen)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/famura/ndc/branch/main/graph/badge.svg?token=ESUTNFwtYY)](https://codecov.io/gh/famura/ndc)\n[![isort](https://img.shields.io/badge/imports-isort-green)](https://pycqa.github.io/isort/)\n[![codestyle](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n**What for?**\n\nDifferentiate signals stored as PyTorch tensors, e.g. measurements obtained from a device or simulation, where automatic differentiation can not be applied.\n\n**Features**\n\n* Theoretically **any order, any stencils, and any step size** (see [this Wiki page](https://en.wikipedia.org/wiki/Finite_difference_coefficient) for information). Be aware that there are numerical limits when computing the filter kernel's coefficients, e.g. small step sized and high orders lead to numerical issues.\n* Works for **multidimensional signals**, assuming that all dimensions share the same step size.\n* Computations can be executed on **CUDA**. However, this has not been tested extensively.\n* Straightforward implementation which you can easily adapt to your needs.\n\n**How?**\n\nThe idea of this small repository is to use the duality between convolution, i.e., filtering, and [numerical differentiation](https://en.wikipedia.org/wiki/Numerical_differentiation) to leverage the existing functions for 1-dimensional convolution in order to compute the (time) derivatives.\n\n**Why PyTorch?**\n\nMore often then not I received (recorded) simulation data as PyTorch tensors rather than numpy arrays.\nThus, I think it is nice to have a function to differentiate measurement signals without switching the data type or computation device.\nMoreover, the `torch.conv1d` function fits perfectly for this purpose.\n\n\n## Citing\n\nIf you use code or ideas from this repository for your projects or research, please cite it.\n```\n@misc{Muratore_ncd,\n  author = {Fabio Muratore},\n  title = {ndc - Numerical differentiation leveraging convolutions},\n  year = {2022},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/famura/ndc}}\n}\n```\n\n## Installation\n\nTo install the core part of the package run\n```\npip install ndc\n```\n\nFor (local) development install the dependencies with\n```\npip install -e .[dev]\n```\n\n## Usage\n\nConsider a signal `x`, e.g. a measurement you obtained form a device. This package assumes that the signal to differentiate is of shape `(num_steps, dim_data)`\n\n```python\nimport torch\nimport ndc\n\n# Assuming you got x(t) from somewhere.\nassert isinstance(x, torch.Tensor)\nnum_steps, dim_data = x.shape \n\n# Specify the derivative. Here, the first order central derivative.\nstencils = [-1, 0, 1]\norder = 1\nstep_size = dt # should be known from your signal x(t), else use 1\npadding = True # if true, the initial and final values are repeated as often as necessary to match the  length of x \n\ndx_dt_num = ndc.differentiate_numerically(x, stencils, order, step_size, padding)\nassert dx_dt_num.device == x.device\nif padding:\n    assert dx_dt_num.shape == (num_steps, dim_data)\nelse:\n    assert dx_dt_num.shape == (num_steps - sum(s != 0 for s in stencils), dim_data)\n```\n\n\n## Contributions\n\nMaybe you want another padding mode, or you found a way to improve the CUDA support. Please feel free to leave a pull request or issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffamura%2Fndc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffamura%2Fndc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffamura%2Fndc/lists"}