Metadata-Version: 2.2
Name: funi
Version: 0.2.0
Summary: Find unique float arrays.
Author-Email: Jaewook Lee <jaewooklee042@gmail.com>
License: MIT License
         
         Copyright (c) 2023 tataratat
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
         
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Natural Language :: English
Classifier: Topic :: Scientific/Engineering
Project-URL: Homepage, https://github.com/tataratat/funi
Requires-Python: >=3.10
Requires-Dist: numpy
Description-Content-Type: text/markdown

# funi
Find UNIque float array rows.
[numpy.unique](https://numpy.org/doc/stable/reference/generated/numpy.unique.html) with `axis=0`, but for float arrays and with a tolerance.

Rows are sorted by their projection onto a fixed generic unit direction, then swept: each row claims every
not-yet-claimed row within `tolerance` (euclidean distance). The sweep window is exact, i.e. no duplicate is
missed. It is fast whenever few rows project to nearly the same key, which a generic direction ensures even
for grids; it only degrades if many distinct rows lie within `tolerance` of one hyperplane orthogonal to it.

## Install
```bash
pip install funi
```

## Quick Start
```python
import funi
import numpy as np

arr = np.random.random((10000, 3))
arr = np.vstack((arr, arr, arr))
np.random.shuffle(arr)

unique_data, unique_ids, inverse = funi.unique_rows(arr, tolerance=1e-11)

assert np.allclose(unique_data, arr[unique_ids])  # unique rows of the original array
assert np.allclose(arr, unique_data[inverse])     # map back to the original array
assert np.all(np.diff(unique_ids) > 0)            # first occurrences, in order of appearance
```


`unique_ids` are the first occurrence of each group; unique rows keep their order of appearance (`[1 2 3 3 5 2 4]` -> `[1 2 3 5 4]`).
