Skip to content

Some experiments about structuring the code better#134

Open
unhyperbolic wants to merge 2 commits into
masterfrom
matthias-experiments
Open

Some experiments about structuring the code better#134
unhyperbolic wants to merge 2 commits into
masterfrom
matthias-experiments

Conversation

@unhyperbolic
Copy link
Copy Markdown
Member

I found it hard with all the monkey patching to actually find where a method is implemented. This is an attempt to fix it.

Let me know what you think.

@unhyperbolic
Copy link
Copy Markdown
Member Author

This still causes some test failures and I have some naming questions.

The idea is that the user-facing classes Triangulation[HP] and Manifold[HP] subclass from 1. a class defined in python that brings in all the python methods and 2. a cython class bringing in the cython wrapped methods.

  1. Is called Triangulation/ManifoldMixIn. I am somewhat happy with the name, but am open to suggestions. I wonder whether something like Triangulation/ManifoldPyBase are better in that they reflect the intention that this is where you add the python methods shared between Triangulation[HP] and Manifold[HP].
  2. Is called Triangulation and Manifold in the cython module. I find it actually somewhat confusing that they have the same name as the user-facing classes. Using the fully qualified name such as extensions.SnapPy.Triangulation makes it a bit better. But I wonder whether they should just be called _Triangulation and _Manifold in cython or Triangulation/ManifoldCyBase to reflect the intention better.

On a related note: tests in extensions.SnapPy test against the cython base class and not the user-facing class. I would prefer to test against the user-facing class. This affects things like Manifold.is_isometric_to which we expect to work when mixing Manifold and ManifoldHP.

My first though was that after renaming, say, Triangulation in extensions.SnapPy, we replace extensions.SnapPy._triangulation_class = Triangulation by extensions.SnapPy.Triangulation = Triangulation. Then setting extensions.SnapPyHP.Triangulation = TriangulationHP would allow both the cython code to call Triangulation(...) to generate the respective python class and would work in the tests. But it feels wrong to me.

So I think we still stick with extensions.SnapPy._triangulation_class but when testing extensions.SnapPy set the globals to use the python super classes Triangulation[HP] and Manifold[HP].

Let me know whether you agree with my thoughts and which of the above naming choices you prefer.

@culler
Copy link
Copy Markdown
Member

culler commented May 6, 2026 via email

@unhyperbolic
Copy link
Copy Markdown
Member Author

My initial reaction is that it would be better to have python classes named TriangulationBase and ManifoldBase and Cython classes named ManifoldKernel and TriangulationKernel.

I like the proposal. KernelTriangulation somehow sounds better but is inconsistent with Base being a suffix...

@culler
Copy link
Copy Markdown
Member

culler commented May 6, 2026 via email

@NathanDunfield
Copy link
Copy Markdown
Member

In general, I think "ManifoldBase" and "KernelManifold" and similar are better names than "ManifoldMixIn" or "_Manifold". Personally, I'm fine with using "ManifoldBase" and "KernelManifold" despite the asymmetry in where the modifier is. If we want to be consistent, I'd lean towards "BaseManifold/KernelManifold" over "ManifoldBase/ManifoldKernel".

@NathanDunfield
Copy link
Copy Markdown
Member

On a related note: tests in extensions.SnapPy test against the cython base class and not the user-facing class. I would prefer to test against the user-facing class. This affects things like Manifold.is_isometric_to which we expect to work when mixing Manifold and ManifoldHP.

I agree it is better to test against the user-facing class. However, rather than what you propose, is it possible to do that by just running the doctests on the final Manifold and ManifoldHP classes rather than the Cython base classes?

…(HP) from common classes that import the python methods in place.
…ion/Manifold

Triangulation/ManifoldMixIn -> BaseTriangulation/Manifold.
@unhyperbolic unhyperbolic force-pushed the matthias-experiments branch from 86c65df to 63703c8 Compare May 7, 2026 16:54
@unhyperbolic
Copy link
Copy Markdown
Member Author

I went ahead and checked-in the new python base classes.

Having gone through the exercise of renaming extensions.SnapPy.Triangulation/Manifold to KernelTriangulation/Manifold, I am a bit hesitant about this rename:

  1. extensions.SnapPy.Triangulation/Manifold is more than just purely wrapping the kernel. It adds a lot of its own logic and uses different names (e.g., canonize instead of proto_canonize, symmetry_group instead of compute_symmetry_group).
  2. I find some of the results such as "cdef c_Triangulation t\ncdef KernelTriangulation tri" confusing.

@NathanDunfield
Copy link
Copy Markdown
Member

Hmm, perhaps CythonManifold/CythonTriangulation is a better choice then?

@unhyperbolic
Copy link
Copy Markdown
Member Author

unhyperbolic commented May 7, 2026

Hmm, perhaps CythonManifold/CythonTriangulation is a better choice then?

My first though was along those lines: Triangulation/ManifoldCyBase. But CythonTriangulation/Manifold has a nicer ring to it. CCuspNeighborhood -> CyCuspNeighborhood along the same lines then, I guess.

@culler
Copy link
Copy Markdown
Member

culler commented May 8, 2026

I don't see why it is a problem that a KernelManifold does more that just wrap kernel methods.

What is confusing about the two cdef lines? The use of the c_ prefix was to indicate that t is a C struct, which it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants