from .tensor import Tensor


class Parameter(Tensor):
    """
    A Tensor subclass that represents a trainable parameter.
    Automatically sets requires_grad=True.
    """
    def __init__(self, data):
        # If data is already a Tensor, use it directly
        if isinstance(data, Tensor):
            # Copy the underlying C tensor object
            super().__init__(data.shape)
            self._tensor = data._tensor
        else:
            # Create new tensor from data
            super().__init__(data)
        
        # Always track gradients for parameters
        self.requires_grad = True
    
    def __repr__(self):
        return f"Parameter containing:\n{super().__repr__()}"
