diff --git a/geomfum/_registry.py b/geomfum/_registry.py index f9d8ae0..676ec71 100644 --- a/geomfum/_registry.py +++ b/geomfum/_registry.py @@ -1,5 +1,7 @@ import abc import inspect +import re +import sys from geomfum._utils import has_package @@ -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__]) diff --git a/geomfum/laplacian/_laplacian.py b/geomfum/laplacian.py similarity index 83% rename from geomfum/laplacian/_laplacian.py rename to geomfum/laplacian.py index 767e747..6a05bf8 100644 --- a/geomfum/laplacian/_laplacian.py +++ b/geomfum/laplacian.py @@ -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.""" diff --git a/geomfum/laplacian/__init__.py b/geomfum/laplacian/__init__.py deleted file mode 100644 index d313864..0000000 --- a/geomfum/laplacian/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -"""Laplacian-related algorithms.""" - -import geomfum.wrap as _wrap # for register - -from ._base import BaseLaplacianFinder -from ._laplacian import LaplacianFinder, LaplacianSpectrumFinder diff --git a/geomfum/laplacian/_base.py b/geomfum/laplacian/_base.py deleted file mode 100644 index da2da2c..0000000 --- a/geomfum/laplacian/_base.py +++ /dev/null @@ -1,22 +0,0 @@ -import abc - - -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. - """ diff --git a/geomfum/wrap/geopext.py b/geomfum/wrap/geopext.py index 24ade4c..e34e4c9 100644 --- a/geomfum/wrap/geopext.py +++ b/geomfum/wrap/geopext.py @@ -4,7 +4,7 @@ import numpy as np import scipy -from geomfum.laplacian._base import BaseLaplacianFinder +from geomfum.laplacian import BaseLaplacianFinder class GeopextMeshLaplacianFinder(BaseLaplacianFinder): diff --git a/geomfum/wrap/igl.py b/geomfum/wrap/igl.py index 46fd5e3..dad7fd9 100644 --- a/geomfum/wrap/igl.py +++ b/geomfum/wrap/igl.py @@ -2,7 +2,7 @@ import igl -from geomfum.laplacian._base import BaseLaplacianFinder +from geomfum.laplacian import BaseLaplacianFinder class IglMeshLaplacianFinder(BaseLaplacianFinder): diff --git a/geomfum/wrap/pyfm.py b/geomfum/wrap/pyfm.py index b3cf7f0..540a898 100644 --- a/geomfum/wrap/pyfm.py +++ b/geomfum/wrap/pyfm.py @@ -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 diff --git a/geomfum/wrap/robust.py b/geomfum/wrap/robust.py index 22b6e03..ba3569b 100644 --- a/geomfum/wrap/robust.py +++ b/geomfum/wrap/robust.py @@ -2,7 +2,7 @@ import robust_laplacian -from geomfum.laplacian._base import BaseLaplacianFinder +from geomfum.laplacian import BaseLaplacianFinder class RobustMeshLaplacianFinder(BaseLaplacianFinder):