|
| 1 | +"""Euclidean manifolds.""" |
| 2 | + |
| 3 | +__all__ = ("Euclidean", "EuclideanAtlas") |
| 4 | + |
| 5 | +from dataclasses import dataclass |
| 6 | + |
| 7 | +from typing import Any, final |
| 8 | + |
| 9 | +import coordinax.charts as cxc |
| 10 | +import coordinax.metrics as cxm |
| 11 | +from .base import AbstractManifold, Atlas |
| 12 | + |
| 13 | + |
| 14 | +@dataclass(frozen=True, slots=True) |
| 15 | +class EuclideanAtlas(Atlas): |
| 16 | + """Atlas for Euclidean manifolds.""" |
| 17 | + |
| 18 | + dim: int |
| 19 | + """Dimension of the Euclidean manifold.""" |
| 20 | + |
| 21 | + def default_chart(self) -> cxc.AbstractChart[Any, Any]: |
| 22 | + # TODO: make this autodetect |
| 23 | + chart: cxc.AbstractChart[Any, Any] |
| 24 | + match self.dim: |
| 25 | + case 0: |
| 26 | + chart = cxc.cart0d |
| 27 | + case 1: |
| 28 | + chart = cxc.cart1d |
| 29 | + case 2: |
| 30 | + chart = cxc.cart2d |
| 31 | + case 3: |
| 32 | + chart = cxc.cart3d |
| 33 | + case 6: |
| 34 | + chart = cxc.poincarepolar6d |
| 35 | + case _: |
| 36 | + msg = f"Euclidean({self.dim}) is unsupported for now." |
| 37 | + raise ValueError(msg) |
| 38 | + return chart |
| 39 | + |
| 40 | + # def supports(self, chart: cxc.AbstractChart[Any, Any]) -> bool: |
| 41 | + # return any(c == chart for c in self._charts) |
| 42 | + |
| 43 | + |
| 44 | +@final |
| 45 | +@dataclass(frozen=True, slots=True) |
| 46 | +class Euclidean(AbstractManifold): |
| 47 | + """Euclidean manifold with identity metric.""" |
| 48 | + |
| 49 | + dim: int |
| 50 | + """Intrinsic dimension of the manifold.""" |
| 51 | + |
| 52 | + def __init__(self, dim: int, /) -> None: |
| 53 | + object.__setattr__(self, "dim", dim) |
| 54 | + object.__setattr__(self, "metric", cxm.EuclideanMetric(dim)) |
| 55 | + object.__setattr__(self, "atlas", EuclideanAtlas(self.dim)) |
0 commit comments