# -*- coding: utf-8 -*-

from torch import isnan,tensor
from torch import nn, Tensor
from abc import abstractmethod
import logging

logger = logging.getLogger(__name__)


class BaseTNorm(nn.Module):
    def __init__(self) -> None:
        super().__init__()

    @abstractmethod
    def __call__(self,
              a: Tensor,
              b: Tensor) -> Tensor:
        raise NotImplementedError

    def conorm(self,
               a: Tensor,
               b: Tensor) -> Tensor:
        return 1.0 - self(1.0 - a, 1.0 - b)

    def adjust_nan_param(self):
        for key, value in self.__dict__.items():
            if type(value) == nn.Parameter:
                if isnan(value):
                    print("The Value of the paramter became NAN")
                    value.data = tensor(0.1, device = value.device)
