{"id":20040817,"url":"https://github.com/vadimkantorov/pydlpack","last_synced_at":"2025-10-12T11:38:17.829Z","repository":{"id":146466563,"uuid":"282960784","full_name":"vadimkantorov/pydlpack","owner":"vadimkantorov","description":"Create a DLPack tensor in plain C library, wrap DLPack structures in Python, import DLpack tensor into NumPy /  PyTorch","archived":false,"fork":false,"pushed_at":"2021-10-20T20:56:17.000Z","size":39,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T19:47:30.486Z","etag":null,"topics":["ctypes","dlpack","numpy","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vadimkantorov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-07-27T16:56:49.000Z","updated_at":"2022-03-05T07:51:05.000Z","dependencies_parsed_at":"2023-08-15T02:17:01.763Z","dependency_job_id":null,"html_url":"https://github.com/vadimkantorov/pydlpack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fpydlpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fpydlpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fpydlpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fpydlpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vadimkantorov","download_url":"https://codeload.github.com/vadimkantorov/pydlpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252466742,"owners_count":21752424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ctypes","dlpack","numpy","python","pytorch"],"created_at":"2024-11-13T10:44:03.759Z","updated_at":"2025-10-12T11:38:17.755Z","avatar_url":"https://github.com/vadimkantorov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is an example of:\n1. Create and allocate a [DLPack](https://github.com/dmlc/dlpack/) tensor in a plain C library. Memory is supposed to also be freed in C with a custom deallocator.\n2. Wrap DLPack structures in Python with `ctypes`. [dlpack.py](./dlpack.py) should in theory be reusable as is outside this example project. Hopefully, in future there [will be](https://github.com/dmlc/dlpack/issues/51#issuecomment-672757632) official `ctypes` DLPack bindings\n3. (experimentally) Consume the DLPack tensor in NumPy. Hopefully, in future there [will be](https://github.com/dmlc/dlpack/issues/55) an official method for this. The main difficulty is absence of memory leaks and segfaults related to freeing the memory.\n4. Demonstrate of importing DLPack tensor into [PyTorch](https://pytorch.org/docs/stable/dlpack.html?highlight=from_dlpack#torch.utils.dlpack.from_dlpack)\n\n**IMPORTANT** Currently the sort-of-supported semantics of consuming DLPack tensors is move semantics. So consume the DLPack tensor only once. Also please monitor memory, I do not guarantee absence of leaks.\n\nA more complete example of reading an audio file with ffmpeg library in C and consuming it via DLPack is available at https://github.com/vadimkantorov/readaudio\n\nDLPack header is taken from https://github.com/dmlc/dlpack/blob/3efc489b55385936531a06ff83425b719387ec63/include/dlpack/dlpack.h\n\n### License for my code: dlpack.c and dlpack.py\nMIT\n\n### Usage\n```shell\n# dump golden.bin with some test data\nmake dlpack\n./dlpack golden.bin\n\n# dump numpy.bin and torch.bin\nmake libdlpack.so\npython3 dlpack.py numpy.bin\npython3 dlpack.py torch.bin\n\n# check that both ways of importing DLPack tensors work\ndiff golden.bin numpy.bin\ndiff golden.bin torch.bin\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadimkantorov%2Fpydlpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvadimkantorov%2Fpydlpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadimkantorov%2Fpydlpack/lists"}