Skip to content

Commit

Permalink
wip wip wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Dec 21, 2023
1 parent 100ae28 commit 763a98c
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 63 deletions.
14 changes: 1 addition & 13 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ serialize =
commit = True
message = chore(version): bump {current_version} to {new_version}

[bumpversion:file:pyproject.toml]
[bumpversion:file:Cargo.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:differt/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:differt-core/Cargo.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:differt-core/src/lib.rs]
search = const VERSION: &str = "{current_version}"
replace = const VERSION: &str = "{new_version}"
69 changes: 62 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ jobs:

- name: Install dependencies
run: |
pdm install -G test,github-action
pdm install --no-self
- name: Run Cargo test
run: |
cargo test --no-default-features --features test
benchmark:
python-benchmark:
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand All @@ -81,7 +81,7 @@ jobs:

- name: Install dependencies
run: |
pdm install -G test,github-action # TODO: build in release mode?
pdm install -G test,github-action
- name: Run Benchmarks on changes
run: pdm run pytest --benchmark-only --benchmark-save=changes
Expand All @@ -97,7 +97,62 @@ jobs:
- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
pdm run pytest --benchmark-only --benchmark-compare=changes >> $GITHUB_OUTPUT
pdm run pytest-benchmark compare before changes >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: compare

- name: Comment PR with benchmarks
uses: thollander/actions-comment-pull-request@v2
continue-on-error: true
with:
message: |
Python benchmark results:
${{ steps.compare.outputs.results }}
comment_tag: python-benchmarks

id: comment

- name: If PR comment failed, write to PR summary
if: steps.comment.outcome != 'success'
run: |
echo '### Python benchmark results' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
rust-benchmark:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: '3.11'
cache: true

- name: Install Rust
uses: dtolnay/rust-toolchain@nightly

- name: Install dependencies
run: |
pdm install --no-self
- name: Run Benchmarks on changes
run: cargo bench > changes

- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
clean: false

- name: Run Benchmarks before changes
run: cargo bench > before

- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
cargo benchcmp before changes >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: compare

Expand All @@ -106,14 +161,14 @@ jobs:
continue-on-error: true
with:
message: |
Benchmark results:
Rust benchmark results:
${{ steps.compare.outputs.results }}
comment_tag: benchmarks
comment_tag: rust-benchmarks

id: comment

- name: If PR comment failed, write to PR summary
if: steps.comment.outcome != 'success'
run: |
echo '### Benchmark results' >> $GITHUB_STEP_SUMMARY
echo '### Rust benchmark results' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.compare.outputs.results }}' >> $GITHUB_STEP_SUMMARY
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ edition = "2021"
name = "_core"
version = "0.0.5"

[profile.release]
lto = "fat"
codegen-units = 1
strip = true

[profile.bench]
debug = true
strip = false

[profile.release]
codegen-units = 1
lto = "fat"
strip = true
2 changes: 1 addition & 1 deletion benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use test::{black_box, Bencher};
use numpy::PyArray2;
use pyo3::{types::IntoPyDict, Python};

use differt_core::rt::utils as rt_utils;
use differt::rt::utils as rt_utils;

fn large_visibility_matrix<'py>(py: Python<'py>) -> &'py PyArray2<bool> {
let np = py.import("numpy").unwrap();
Expand Down
11 changes: 0 additions & 11 deletions docs/source/reference/differt-core.rst

This file was deleted.

4 changes: 1 addition & 3 deletions python/differt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .version import VERSION

__version__ = VERSION
__all__ = (
'VERSION',
)
__all__ = ("VERSION",)
26 changes: 5 additions & 21 deletions python/differt/geometry/triangle_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from pathlib import Path

import jax.numpy as jnp
import open3d as o3d
import plotly.graph_objects as go
from chex import dataclass
from jaxtyping import Array, Bool, Float, UInt

from .utils import pairwise_cross
from .. import _core

Check warning on line 11 in python/differt/geometry/triangle_mesh.py

View check run for this annotation

Codecov / codecov/patch

python/differt/geometry/triangle_mesh.py#L11

Added line #L11 was not covered by tests


def triangles_contain_vertices_assuming_inside_same_plane(
Expand Down Expand Up @@ -89,7 +88,7 @@ def paths_intersect_triangles(

@dataclass
class TriangleMesh:
mesh: o3d.geometry.TriangleMesh
mesh: _core.geometry.triangle_mesh.TriangleMesh

Check warning on line 91 in python/differt/geometry/triangle_mesh.py

View check run for this annotation

Codecov / codecov/patch

python/differt/geometry/triangle_mesh.py#L91

Added line #L91 was not covered by tests

@cached_property
def triangles(self) -> UInt[Array, "num_triangles 3"]:
Expand All @@ -107,30 +106,15 @@ def normals(self) -> Float[Array, "num_triangles 3"]:

@cached_property
def diffraction_edges(self) -> UInt[Array, "num_edges 3"]:
all_vertices = jnp.take(self.vertices, self.indices, axis=0)
normals = self.normals

print(normals)

cross = pairwise_cross(normals, normals)
n = jnp.linalg.norm(cross, axis=-1)
print(n)
print(n.shape)
print(cross)
print(cross.shape)

print(all_vertices)
return len(all_vertices)
return jnp.asarray(self.mesh.get_non_manifold_edges(False))
raise NotImplementedError

@classmethod
def load_geojson(cls, file: Path, default_height: float = 1.0) -> TriangleMesh:
pass
raise NotImplementedError

@classmethod
def load_obj(cls, file: Path) -> TriangleMesh:
mesh = o3d.io.read_triangle_mesh(str(file)).compute_triangle_normals()
return cls(mesh=mesh)
return cls(mesh=_core.geometry.triangle_mesh.TriangleMesh.load_obj(str(file)))

Check warning on line 117 in python/differt/geometry/triangle_mesh.py

View check run for this annotation

Codecov / codecov/patch

python/differt/geometry/triangle_mesh.py#L117

Added line #L117 was not covered by tests

def plot(self, *args, **kwargs):
x, y, z = self.vertices.T
Expand Down
3 changes: 2 additions & 1 deletion python/differt/rt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def generate_all_path_candidates(
``num_primitives * ((num_primitives - 1) ** (order - 1))``.
"""
return jnp.asarray(
_core.rt.utils.generate_all_path_candidates(num_primitives, order), dtype=jnp.uint32
_core.rt.utils.generate_all_path_candidates(num_primitives, order),
dtype=jnp.uint32,
)


Expand Down
2 changes: 1 addition & 1 deletion python/differt/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._core import __version__

__all__ = ('VERSION',)
__all__ = ("VERSION",)

VERSION = __version__

0 comments on commit 763a98c

Please sign in to comment.