import torch
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.triton_helpers import libdevice, math as tl_math
import numpy as np
import torch.nn as nn
from numbers import Number
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_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0(
    in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    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 + x0, xmask)
    tmp2 = libdevice.sqrt(tmp1)
    tmp3 = tmp0 / tmp2
    tmp4 = 0.0
    tmp5 = tmp3 - tmp4
    tmp6 = 1.0
    tmp7 = tmp5 * tmp6
    tmp8 = 1.414213562373095
    tmp9 = tmp7 / tmp8
    tmp10 = libdevice.erf(tmp9)
    tmp11 = tmp10 + tmp6
    tmp12 = 0.5
    tmp13 = tmp11 * tmp12
    tmp14 = tmp0 * tmp13
    tmp15 = tmp5 * tmp5
    tmp16 = -tmp15
    tmp17 = tmp16 * tmp12
    tmp18 = 0.9189385332046727
    tmp19 = tmp17 - tmp18
    tmp20 = tl_math.exp(tmp19)
    tmp21 = tmp2 * tmp20
    tmp22 = tmp14 + tmp21
    tmp23 = -tmp0
    tmp24 = tmp6 - tmp13
    tmp25 = tmp23 * tmp24
    tmp26 = tmp25 + tmp21
    tmp27 = 0.01
    tmp28 = tmp26 * tmp27
    tmp29 = tmp22 - tmp28
    tmp30 = tmp0 * tmp0
    tmp31 = tmp30 + tmp1
    tmp32 = tmp31 * tmp13
    tmp33 = tmp0 * tmp21
    tmp34 = tmp32 + tmp33
    tmp35 = tmp22 * tmp22
    tmp36 = tmp34 - tmp35
    tmp37 = tmp31 * tmp24
    tmp38 = tmp37 - tmp33
    tmp39 = tmp26 * tmp26
    tmp40 = tmp38 - tmp39
    tmp41 = -tmp22
    tmp42 = tmp41 * tmp26
    tmp43 = 0.0001
    tmp44 = tmp40 * tmp43
    tmp45 = tmp36 + tmp44
    tmp46 = 0.02
    tmp47 = tmp42 * tmp46
    tmp48 = tmp45 - tmp47
    tl.store(out_ptr0 + x0, tmp29, xmask)
    tl.store(in_out_ptr0 + x0, tmp48, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf4 = buf1
        del buf1
        get_raw_stream(0)
        triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0[grid
            (256)](buf4, arg1_1, arg0_1, buf0, 256, XBLOCK=256, num_warps=4,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf0, buf4


def normcdf(value, mu=0.0, stddev=1.0):
    sinv = 1.0 / stddev if isinstance(stddev, Number) else stddev.reciprocal()
    return 0.5 * (1.0 + torch.erf((value - mu) * sinv / np.sqrt(2.0)))


def _normal_log_pdf(value, mu, stddev):
    var = stddev ** 2
    log_scale = np.log(stddev) if isinstance(stddev, Number) else torch.log(
        stddev)
    return -(value - mu) ** 2 / (2.0 * var) - log_scale - np.log(np.sqrt(
        2.0 * np.pi))


def normpdf(value, mu=0.0, stddev=1.0):
    return torch.exp(_normal_log_pdf(value, mu, stddev))


class LeakyReLUNew(nn.Module):

    def __init__(self, negative_slope=0.01, keep_variance_fn=None):
        super(LeakyReLUNew, self).__init__()
        self._keep_variance_fn = keep_variance_fn
        self._negative_slope = negative_slope

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0], output[1]


Measured latency_ms: 0.030046