import torch
import torch.nn as nn

BATCH_SIZE = 4096
HIDDEN_DIM = 4096
SHAPE = (BATCH_SIZE, HIDDEN_DIM)

ALPHA_VALUE = 1.0

class STL(nn.Module):
    """
    Signed and Truncated Logarithm (STL) Activation.
    "STL: A Signed and Truncated Logarithm Activation Function for Neural Networks" (arXiv, 2023)
    Formula:
      f(x) = alpha * x                      if |x| <= 1
      f(x) = alpha * sign(x) * (ln(|x|) + 1) if |x| > 1
    """
    def __init__(self, alpha=1.0):
        super(STL, self).__init__()
        self.alpha = alpha

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        abs_x = torch.abs(x)
        
        linear_part = self.alpha * x
        log_part = self.alpha * torch.sign(x) * (torch.log(abs_x) + 1.0)
        
        return torch.where(abs_x <= 1.0, linear_part, log_part)

class Model(nn.Module):
    def __init__(self, alpha=1.0):
        super(Model, self).__init__()
        self.act = STL(alpha=alpha)
    
    def forward(self, x):
        return self.act(x)

def get_inputs():
    input_tensor = torch.randn(SHAPE, dtype=torch.float32) * 2.0
    return [input_tensor.contiguous()]

def get_init_inputs():
    return [ALPHA_VALUE]