import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch import nn
from torch.nn.parameter import Parameter
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_add_clamp_exp_ge_lt_masked_fill_mul_neg_pow_relu_sub_0(
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1,
    out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp9 = tl.load(in_ptr2 + 0)
    tmp10 = tl.broadcast_to(tmp9, [XBLOCK])
    tmp15 = tl.load(in_ptr3 + 0)
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
    tmp31 = tl.load(in_ptr4 + 0)
    tmp32 = tl.broadcast_to(tmp31, [XBLOCK])
    tmp3 = 0.1
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 3.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp0 < tmp6
    tmp8 = tmp0 >= tmp6
    tmp11 = 1.01
    tmp12 = triton_helpers.maximum(tmp10, tmp11)
    tmp13 = 6.0
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tmp17 = 0.5
    tmp18 = triton_helpers.maximum(tmp16, tmp17)
    tmp19 = 2.0
    tmp20 = triton_helpers.minimum(tmp18, tmp19)
    tmp21 = -tmp20
    tmp22 = tmp0 - tmp6
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 * tmp23
    tmp25 = tl_math.exp(tmp24)
    tmp26 = tmp14 * tmp25
    tmp27 = 0.0
    tmp28 = tl.where(tmp8, tmp27, tmp26)
    tmp29 = 1.0
    tmp30 = tmp14 - tmp29
    tmp33 = triton_helpers.maximum(tmp32, tmp17)
    tmp34 = triton_helpers.minimum(tmp33, tmp19)
    tmp35 = -tmp34
    tmp36 = tmp35 * tmp23
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp30 * tmp37
    tmp39 = tmp38 + tmp29
    tmp40 = tl.where(tmp7, tmp27, tmp39)
    tmp41 = tmp28 + tmp40
    tmp42 = tl.full([1], 0, tl.int32)
    tmp43 = triton_helpers.maximum(tmp42, tmp0)
    tmp44 = 0.8
    tmp45 = libdevice.pow(tmp43, tmp44)
    tl.store(out_ptr0 + x0, tmp7, xmask)
    tl.store(out_ptr1 + x0, tmp8, xmask)
    tl.store(out_ptr2 + x0, tmp41, xmask)
    tl.store(out_ptr3 + x0, tmp45, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (), ())
    assert_size_stride(primals_4, (), ())
    assert_size_stride(primals_5, (), ())
    assert_size_stride(primals_6, (), ())
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(2, 
            2), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 2, 2), (16, 4, 2, 1))
        buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
        buf2 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
        buf3 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_clamp_exp_ge_lt_masked_fill_mul_neg_pow_relu_sub_0[
            grid(64)](buf0, primals_4, primals_3, primals_5, primals_6,
            buf1, buf2, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
    return (buf3, buf4, primals_1, primals_2, primals_3, primals_4,
        primals_5, primals_6, buf0, buf1, buf2)


def weights_init():
    """
    Gaussian init.

    """

    def init_fun(m):
        classname = m.__class__.__name__
        if (classname.find('Conv') == 0 or classname.find('Linear') == 0
            ) and hasattr(m, 'weight'):
            nn.init.normal_(m.weight, 0.0, 0.02)
            if hasattr(m, 'bias') and m.bias is not None:
                nn.init.constant_(m.bias, 0.0)
    return init_fun


class GaussActivation(nn.Module):

    def __init__(self, a, mu, sigma1, sigma2):
        super(GaussActivation, self).__init__()
        self.a = Parameter(torch.tensor(a, dtype=torch.float32))
        self.mu = Parameter(torch.tensor(mu, dtype=torch.float32))
        self.sigma1 = Parameter(torch.tensor(sigma1, dtype=torch.float32))
        self.sigma2 = Parameter(torch.tensor(sigma2, dtype=torch.float32))

    def forward(self, inputFeatures):
        a = torch.clamp(self.a.data, 1.01, 6.0)
        mu = torch.clamp(self.mu.data, 0.1, 3.0)
        sigma1 = torch.clamp(self.sigma1.data, 0.5, 2.0)
        sigma2 = torch.clamp(self.sigma2.data, 0.5, 2.0)
        lowerThanMu = inputFeatures < mu
        largerThanMu = inputFeatures >= mu
        leftValuesActiv = a * torch.exp(-sigma1 * (inputFeatures - mu) ** 2)
        leftValuesActiv.masked_fill_(largerThanMu, 0.0)
        rightValueActiv = 1 + (a - 1) * torch.exp(-sigma2 * (inputFeatures -
            mu) ** 2)
        rightValueActiv.masked_fill_(lowerThanMu, 0.0)
        output = leftValuesActiv + rightValueActiv
        return output


class MaskUpdate(nn.Module):

    def __init__(self, alpha):
        super(MaskUpdate, self).__init__()
        self.updateFunc = nn.ReLU(True)
        self.alpha = alpha

    def forward(self, inputMaskMap):
        return torch.pow(self.updateFunc(inputMaskMap), self.alpha)


class ReverseMaskConvNew(nn.Module):

    def __init__(self, inputChannels, outputChannels):
        super(ReverseMaskConvNew, self).__init__()
        self.reverseMaskConv = nn.Conv2d(inputChannels, outputChannels,
            kernel_size=4, stride=2, padding=1, dilation=1, groups=1, bias=
            False)
        self.reverseMaskConv.apply(weights_init())
        self.activationFuncG_A = GaussActivation(1.1, 1.0, 0.5, 0.5)
        self.updateMask = MaskUpdate(0.8)

    def forward(self, input_0):
        primals_1 = self.reverseMaskConv.weight
        primals_3 = self.activationFuncG_A.a
        primals_4 = self.activationFuncG_A.mu
        primals_5 = self.activationFuncG_A.sigma1
        primals_6 = self.activationFuncG_A.sigma2
        primals_2 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6])
        return output[0], output[1]


Measured latency_ms: 0.017355