# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/08_dims.ipynb.

# %% auto 0
__all__ = ['DimsMeta', 'Dims']

# %% ../nbs/08_dims.ipynb 4
from typing import Any, Tuple, Union

# %% ../nbs/08_dims.ipynb 5
from .pttype import PTMeta, PTType
from .shape import Shape, ShapeMeta

# %% ../nbs/08_dims.ipynb 7
class DimsMeta(PTMeta):
    """
    Metaclass for Dims. It contains logic for instance checking.
    """

    __args__: Union[Tuple[Shape], int]
    _parameterized: bool

    def __getitem__(cls, item):
        
        if not isinstance(item, (tuple, Shape, ShapeMeta, int)):
            raise TypeError("Dims expects an int, tuple or Shape argument.")
        return super().__getitem__(item)

    def __str__(cls):
        dims = cls.__args__[0]
        return f"Dims[{dims}]"

    # def __instancecheck__(cls, instance):
    #     dims = cls.__args__[0]

    #     # Check dimensions
    #     if dims is not Any and not dims.match(instance.shape):
    #         return False

    #     return True

# %% ../nbs/08_dims.ipynb 8
class Dims(PTType, metaclass=DimsMeta):
    """
    Represents the number of dimensions in a tensor.
    """
    __args__ = (Any, )
    
    # def __instancecheck__(cls, instance):
    #     dims = cls.__args__[0]

    #     # Check dimensions
    #     if dims is not Any and instance.dim() != dims:
    #         return False

    #     return True
