Skip to content

Commit

Permalink
Merge pull request #1 from harrydobbs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
harrydobbs authored Feb 1, 2025
2 parents cdabdd9 + 7799937 commit 1a344cf
Show file tree
Hide file tree
Showing 25 changed files with 1,351 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/html
publish_dir: docs/build/html
14 changes: 7 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ jobs:
with:
fetch-depth: 0 # This fetches all history and tags
- run: git fetch --tags # This ensures all tags are fetched

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build setuptools setuptools_scm
- name: Check SCM Version
run: |
python -c "from setuptools_scm import get_version; print(f'Detected version: {get_version()}')"
- name: Build release distributions
run: python -m build

- name: Upload distributions
uses: actions/upload-artifact@v4
with:
Expand All @@ -53,6 +53,6 @@ jobs:
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@release/v1
53 changes: 53 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
- id: check-merge-conflict

- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: [--config=pyproject.toml]

- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [
'flake8-docstrings',
'flake8-bugbear',
'flake8-comprehensions',
]
args: [
"--max-line-length=88", # Match black's line length
"--extend-ignore=E203", # Black-compatible
]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [
'types-PyYAML',
'types-setuptools',
'torch',
'numpy',
]
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ pip install torch-ransac3d
- Lines
- Planes
- Spheres
- Circles
- Cylinders
- Cuboids
- Points
- Batch processing capability for improved efficiency
- Support for both PyTorch tensors and NumPy arrays as input
- Clean dataclass return types for all fitting functions

## Example Usage

Expand All @@ -50,18 +55,21 @@ from torch_ransac3d.line import line_fit

# Using PyTorch tensor
points_torch = torch.rand(1000, 3)
direction, point, inliers = line_fit(
result = line_fit(
pts=points_torch,
thresh=0.01,
max_iterations=1000,
iterations_per_batch=100,
epsilon=1e-8,
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
)
print(f"Direction: {result.direction}")
print(f"Point: {result.point}")
print(f"Number of inliers: {len(result.inliers)}")

# Using NumPy array
points_numpy = np.random.rand(1000, 3)
direction, point, inliers = line_fit(
result = line_fit(
pts=points_numpy,
thresh=0.01,
max_iterations=1000,
Expand All @@ -78,14 +86,16 @@ from torch_ransac3d.plane import plane_fit

# Works with both PyTorch tensors and NumPy arrays
points = torch.rand(1000, 3) # or np.random.rand(1000, 3)
equation, inliers = plane_fit(
result = plane_fit(
pts=points,
thresh=0.05,
max_iterations=1000,
iterations_per_batch=100,
epsilon=1e-8,
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
)
print(f"Plane equation: {result.equation}") # [a, b, c, d] for ax + by + cz + d = 0
print(f"Number of inliers: {len(result.inliers)}")
```

### Sphere Fitting
Expand All @@ -95,14 +105,17 @@ from torch_ransac3d.sphere import sphere_fit

# Works with both PyTorch tensors and NumPy arrays
points = torch.rand(1000, 3) # or np.random.rand(1000, 3)
center, radius, inliers = sphere_fit(
result = sphere_fit(
pts=points,
thresh=0.05,
max_iterations=1000,
iterations_per_batch=100,
epsilon=1e-8,
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
)
print(f"Center: {result.center}")
print(f"Radius: {result.radius}")
print(f"Number of inliers: {len(result.inliers)}")
```

## Parameters
Expand Down Expand Up @@ -142,5 +155,5 @@ This project is based on the work done at https://github.com/leomariga/pyRANSAC-

## Contact

**Maintainer:** Harry Dobbs
**Email:** harrydobbs87@gmail.com
**Maintainer:** Harry Dobbs
**Email:** harrydobbs87@gmail.com
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Indices and tables

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
* :ref:`search`
2 changes: 1 addition & 1 deletion docs/source/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ torch_ransac3d
.. automodule:: torch_ransac3d
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
26 changes: 22 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "torch_ransac3d"
version = "1.0.36"
version = "1.0.36"
authors = [
{name = "Harry Dobbs", email = "harrydobbs87@gmail.com"},
]
Expand All @@ -16,7 +16,7 @@ dependencies = [
'numpy',
'torch'
]
# ... rest of your project configuration ...


[tool.setuptools_scm]
write_to = "torch_ransac3d/_version.py"
Expand All @@ -37,5 +37,23 @@ Issues = "https://github.com/harrydobbs/torch_ransac3d/issues"
dev = [
"sphinx",
"sphinx-autodoc-typehints",
"sphinx-rtd-theme"
]
"sphinx-rtd-theme",
"pytest",
"pytest-cov",
"pytest-xdist",
"pytest-timeout"
]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
addopts = "-v --color=yes"

[tool.pycln]
all = true
expand_stars = true
verbose = true
exclude = """
__init__.py
|tests/.*
"""
Empty file added tests/*
Empty file.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest
import torch


@pytest.fixture
def device():
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
Loading

0 comments on commit 1a344cf

Please sign in to comment.