import torch
import torch.nn as nn

# --- 基准测试配置 ---
BATCH_SIZE = 4096
HIDDEN_DIM = 4096
SHAPE = (BATCH_SIZE, HIDDEN_DIM)

ALPHA_VAL = 0.5

class PAA(nn.Module):
    '''
    K. V. N. Babu and D. R. Edla, “New algebraic activation function for multi-layered feed forward neural networks,” IETE J. Res., vol. 63, no. 1, pp. 71–79, Jan. 2017.
    Formula: f(x) = x * (1 + a*|x|) / (1 + |x| * (1 + a*|x|))
    '''
    def __init__(self, alpha=0.5):
        super(PAA, self).__init__()
        self.alpha = alpha

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        abs_x = torch.abs(x)
        term = 1.0 + self.alpha * abs_x
        numerator = x * term
        denominator = 1.0 + abs_x * term
        return numerator / (denominator + 1e-8)

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

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

def get_init_inputs():
    return [ALPHA_VAL]