Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions autoarray/structures/triangles/array.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import Tuple

from autoarray import Grid2D
from jax import numpy as np
from jax.tree_util import register_pytree_node_class
from jax import jit
import numpy as np


@register_pytree_node_class
class ArrayTriangles:
def __init__(
self,
Expand All @@ -28,16 +25,13 @@ def __init__(
self.vertices = vertices

@property
@jit
def triangles(self):
return self.vertices[self.indices]

@property
@jit
def means(self):
return np.mean(self.triangles, axis=1)

@jit
def containing_indices(self, point: Tuple[float, float]) -> np.ndarray:
"""
Find the triangles that contain a given point.
Expand Down Expand Up @@ -67,9 +61,8 @@ def containing_indices(self, point: Tuple[float, float]) -> np.ndarray:

inside = (0 <= a) & (a <= 1) & (0 <= b) & (b <= 1) & (0 <= c) & (c <= 1)

return np.where(inside, size=5, fill_value=-1)[0]
return np.where(inside)[0]

@jit
def for_indexes(self, indexes: np.ndarray) -> "ArrayTriangles":
"""
Create a new ArrayTriangles containing indices and vertices corresponding to the given indexes
Expand All @@ -95,7 +88,6 @@ def for_indexes(self, indexes: np.ndarray) -> "ArrayTriangles":

return ArrayTriangles(indices=new_indices, vertices=unique_vertices)

@jit
def up_sample(self) -> "ArrayTriangles":
"""
Up-sample the triangles by adding a new vertex at the midpoint of each edge.
Expand Down Expand Up @@ -128,7 +120,6 @@ def up_sample(self) -> "ArrayTriangles":
vertices=unique_vertices,
)

@jit
def neighborhood(self) -> "ArrayTriangles":
"""
Create a new set of triangles that are the neighborhood of the current triangles.
Expand Down Expand Up @@ -166,7 +157,6 @@ def neighborhood(self) -> "ArrayTriangles":
vertices=unique_vertices,
)

@jit
def with_vertices(self, vertices: np.ndarray) -> "ArrayTriangles":
"""
Create a new set of triangles with the vertices replaced.
Expand All @@ -186,7 +176,6 @@ def with_vertices(self, vertices: np.ndarray) -> "ArrayTriangles":
)

@classmethod
@jit
def for_grid(cls, grid: Grid2D) -> "ArrayTriangles":
"""
Create a grid of equilateral triangles from a regular grid.
Expand Down Expand Up @@ -278,19 +267,3 @@ def add_vertex(v):

def __iter__(self):
return iter(self.triangles)

def tree_flatten(self):
"""
Flatten this model as a PyTree.
"""
return (self.indices, self.vertices), ()

@classmethod
def tree_unflatten(cls, aux_data, children):
"""
Unflatten a PyTree into a model.
"""
return cls(
indices=children[0],
vertices=children[1],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[1.0, 0.0],
]
),
np.array([0, -1, -1, -1, -1]),
np.array([0]),
),
(
(0.6, 0.6),
Expand All @@ -27,7 +27,7 @@
[1.0, 1.0],
]
),
np.array([1, -1, -1, -1, -1]),
np.array([1]),
),
(
(0.5, 0.5),
Expand All @@ -39,7 +39,7 @@
[1.0, 1.0],
]
),
np.array([0, 1, -1, -1, -1]),
np.array([0, 1]),
),
],
)
Expand Down
21 changes: 0 additions & 21 deletions test_autoarray/structures/triangles/test_jax.py

This file was deleted.