{"id":15649774,"url":"https://github.com/rusty1s/pytorch_unique","last_synced_at":"2025-10-23T20:47:31.439Z","repository":{"id":57476588,"uuid":"116790196","full_name":"rusty1s/pytorch_unique","owner":"rusty1s","description":"PyTorch Extension Library of Optimized Unique Operation","archived":false,"fork":false,"pushed_at":"2019-03-01T06:14:53.000Z","size":48,"stargazers_count":37,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-29T21:22:30.317Z","etag":null,"topics":["python","pytorch","unique"],"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/rusty1s.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}},"created_at":"2018-01-09T08:48:06.000Z","updated_at":"2024-01-04T16:19:52.000Z","dependencies_parsed_at":"2022-09-12T15:22:44.522Z","dependency_job_id":null,"html_url":"https://github.com/rusty1s/pytorch_unique","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fpytorch_unique","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fpytorch_unique/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fpytorch_unique/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fpytorch_unique/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rusty1s","download_url":"https://codeload.github.com/rusty1s/pytorch_unique/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228348363,"owners_count":17905897,"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":["python","pytorch","unique"],"created_at":"2024-10-03T12:31:59.083Z","updated_at":"2025-10-23T20:47:31.341Z","avatar_url":"https://github.com/rusty1s.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[pypi-image]: https://badge.fury.io/py/torch-unique.svg\n[pypi-url]: https://pypi.python.org/pypi/torch-unique\n[build-image]: https://travis-ci.org/rusty1s/pytorch_unique.svg?branch=master\n[build-url]: https://travis-ci.org/rusty1s/pytorch_unique\n[coverage-image]: https://codecov.io/gh/rusty1s/pytorch_unique/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/github/rusty1s/pytorch_unique?branch=master\n\n# PyTorch Unique\n\n[![PyPI Version][pypi-image]][pypi-url]\n[![Build Status][build-image]][build-url]\n[![Code Coverage][coverage-image]][coverage-url]\n\n--------------------------------------------------------------------------------\n\n**PyTorch 0.4.1 now supports [`unique`](https://pytorch.org/docs/stable/torch.html#torch.unique) both for CPU and GPU.\nTherefore, this package is no longer needed and will not be updated.\nIn contrast to this package, PyTorch's version does not return an index array.\nHowever, you can easily generate it by using the following code:**\n\n```python\nimport torch\n\nunique, inverse = torch.unique(x, sorted=True, return_inverse=True)\nperm = torch.arange(inverse.size(0), dtype=inverse.dtype, device=inverse.device)\ninverse, perm = inverse.flip([0]), perm.flip([0])\nperm = inverse.new_empty(unique.size(0)).scatter_(0, inverse, perm)\n```\n\n--------------------------------------------------------------------------------\n\nThis package consists of a small extension library of a highly optimized `unique` operation for the use in [PyTorch](http://pytorch.org/), which is missing in the main package.\nThe operation works on varying data types and is implemented both for CPU and GPU.\n\n## Installation\n\nEnsure that PyTorch 0.4.0 is installed and verify that `cuda/bin` and `cuda/include` are in your `$PATH` and `$CPATH` respectively, *e.g.*:\n\n```\n$ python -c \"import torch; print(torch.__version__)\"\n\u003e\u003e\u003e 0.4.0\n\n$ echo $PATH\n\u003e\u003e\u003e /usr/local/cuda/bin:...\n\n$ echo $CPATH\n\u003e\u003e\u003e /usr/local/cuda/include:...\n```\n\nThen run:\n\n```\npip install torch-unique\n```\n\nIf you are running into any installation problems, please create an [issue](https://github.com/rusty1s/pytorch_unique/issues).\nBe sure to import `torch` first before using this package to resolve symbols the dynamic linker must see.\n\n## Usage\n\n```\ntorch_unique.unique(src) -\u003e (Tensor, LongTensor)\n```\n\nReturns the sorted unique scalar elements of the input tensor as an one-dimensional tensor.\n\nA tuple of `(unique_tensor, unique_indices)` is returned, where the `unique_indices` are the indices of the elements in the original input tensor. Note that `unique_indices` is not guaranteed to be stable on GPU.\n\n### Parameters\n\n* **src** *(Tensor)* - The input tensor.\n\n### Returns\n\n* **out** *(Tensor)* - The unique elements from `src` as an one-dimensional tensor.\n* **perm** *(LongTensor)* - The unique indices from `src` as an one-dimensional tensor.\n\n### Example\n\n```py\nimport torch\nfrom torch_unique import unique\n\nsrc = torch.tensor([100, 10, 100, 1, 1000, 1, 1000, 1])\nout, perm = unique(src)\n```\n\n```\nprint(out)\ntensor([    1,    10,   100,  1000])\nprint(perm)\ntensor([ 3,  1,  0,  4])\n```\n\n## Running tests\n\n```\npython setup.py test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusty1s%2Fpytorch_unique","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusty1s%2Fpytorch_unique","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusty1s%2Fpytorch_unique/lists"}