Skip to content

Commit

Permalink
Merge pull request #10 from luisfpereira/registry
Browse files Browse the repository at this point in the history
Add macro to create register functions and move laplacian to single file
  • Loading branch information
luisfpereira authored Dec 17, 2024
2 parents 3674a45 + 46625c1 commit f354edb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 50 deletions.
39 changes: 21 additions & 18 deletions geomfum/_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import abc
import inspect
import re
import sys

from geomfum._utils import has_package

Expand Down Expand Up @@ -219,46 +221,47 @@ class LaplacianFinderRegistry(MeshWhichRegistry):
MAP = {}


register_laplacian_finder = LaplacianFinderRegistry.register


class HeatKernelSignatureRegistry(WhichRegistry):
MAP = {}


register_heat_kernel_signature = HeatKernelSignatureRegistry.register


class WaveKernelSignatureRegistry(WhichRegistry):
MAP = {}


register_wave_kernel_signature = WaveKernelSignatureRegistry.register


class FaceValuedGradientRegistry(WhichRegistry):
MAP = {}


register_face_valued_gradient = FaceValuedGradientRegistry.register


class FaceDivergenceOperatorRegistry(WhichRegistry):
MAP = {}


register_face_divergence_operator = FaceDivergenceOperatorRegistry.register
class FaceOrientationOperatorRegistry(WhichRegistry):
MAP = {}


class FaceOrientationOperatorRegistry(WhichRegistry):
class HierarchicalMeshRegistry(WhichRegistry):
MAP = {}


register_face_orientation_operator = FaceOrientationOperatorRegistry.register
def _create_register_funcs(module):
# create `register_` functions automatically
for name, method in inspect.getmembers(module):
if not (
hasattr(method, "__bases__")
and abc.ABC not in method.__bases__
and name.endswith("Registry")
):
continue

# upper case split
name_ls = ["register"] + [
word.lower() for word in re.findall("[A-Z][^A-Z]*", name)[:-1]
]
new_name = "_".join(name_ls)

class HierarchicalMeshRegistry(WhichRegistry):
MAP = {}
setattr(module, new_name, method.register)


register_hierarchical_mesh = HierarchicalMeshRegistry.register
_create_register_funcs(sys.modules[__name__])
26 changes: 26 additions & 0 deletions geomfum/laplacian/_laplacian.py → geomfum/laplacian.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
"""Laplacian-related algorithms."""

import abc

import geomfum.wrap as _wrap # noqa (for register)
from geomfum._registry import LaplacianFinderRegistry, MeshWhichRegistryMixins
from geomfum.basis import LaplaceEigenBasis
from geomfum.numerics.eig import ScipyEigsh


class BaseLaplacianFinder(abc.ABC):
"""Algorithm to find the Laplacian."""

@abc.abstractmethod
def __call__(self, shape):
"""Apply algorithm.
Parameters
----------
shape : Shape
Shape.
Returns
-------
stiffness_matrix : array-like, shape=[n_vertices, n_vertices]
Stiffness matrix.
mass_matrix : array-like, shape=[n_vertices, n_vertices]
Mass matrix.
"""


class LaplacianFinder(MeshWhichRegistryMixins):
"""Algorithm to find the Laplacian."""

Expand Down
6 changes: 0 additions & 6 deletions geomfum/laplacian/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions geomfum/laplacian/_base.py

This file was deleted.

2 changes: 1 addition & 1 deletion geomfum/wrap/geopext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import scipy

from geomfum.laplacian._base import BaseLaplacianFinder
from geomfum.laplacian import BaseLaplacianFinder


class GeopextMeshLaplacianFinder(BaseLaplacianFinder):
Expand Down
2 changes: 1 addition & 1 deletion geomfum/wrap/igl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import igl

from geomfum.laplacian._base import BaseLaplacianFinder
from geomfum.laplacian import BaseLaplacianFinder


class IglMeshLaplacianFinder(BaseLaplacianFinder):
Expand Down
2 changes: 1 addition & 1 deletion geomfum/wrap/pyfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import scipy

from geomfum.descriptor._base import SpectralDescriptor
from geomfum.laplacian._base import BaseLaplacianFinder
from geomfum.laplacian import BaseLaplacianFinder
from geomfum.operator import FunctionalOperator, VectorFieldOperator


Expand Down
2 changes: 1 addition & 1 deletion geomfum/wrap/robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import robust_laplacian

from geomfum.laplacian._base import BaseLaplacianFinder
from geomfum.laplacian import BaseLaplacianFinder


class RobustMeshLaplacianFinder(BaseLaplacianFinder):
Expand Down

0 comments on commit f354edb

Please sign in to comment.