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 math as tl_math
import numpy as np
import torch.nn as nn
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_lt_mul_pow_reciprocal_sin_where_zeros_like_0(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp1 = 0.25
    tmp2 = tmp0 * tmp1
    tmp3 = 1.0
    tmp4 = tmp2 < tmp3
    tmp5 = tl.full([1], 1, tl.int32)
    tmp6 = tmp5 / tmp2
    tmp7 = tmp6 * tmp3
    tmp8 = tmp2 * tmp2
    tmp9 = tmp8 * tmp8
    tmp10 = tmp9 * tmp2
    tmp11 = -28.0
    tmp12 = tmp10 * tmp11
    tmp13 = tmp7 + tmp12
    tmp14 = tmp8 * tmp2
    tmp15 = tmp14 * tmp14
    tmp16 = 48.0
    tmp17 = tmp15 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = tmp15 * tmp2
    tmp20 = -21.0
    tmp21 = tmp19 * tmp20
    tmp22 = tmp18 + tmp21
    tmp23 = 0.0
    tmp24 = tl.where(tmp4, tmp22, tmp23)
    tmp26 = tmp25 * tmp2
    tmp27 = tl_math.sin(tmp26)
    tmp28 = tmp24 * tmp27
    tl.store(out_ptr0 + x2, tmp28, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_lt_mul_pow_reciprocal_sin_where_zeros_like_0[grid
            (1024)](primals_1, primals_2, buf0, 1024, XBLOCK=128, num_warps
            =4, num_stages=1)
    return buf0, primals_1, primals_2


class Envelope(nn.Module):

    def __init__(self, exponent):
        super(Envelope, self).__init__()
        self.exponent = exponent
        self.p = exponent + 1
        self.a = -(self.p + 1) * (self.p + 2) / 2
        self.b = self.p * (self.p + 2)
        self.c = -self.p * (self.p + 1) / 2

    def forward(self, inputs):
        env_val = 1 / inputs + self.a * inputs ** (self.p - 1
            ) + self.b * inputs ** self.p + self.c * inputs ** (self.p + 1)
        return torch.where(inputs < 1, env_val, torch.zeros_like(inputs))


class BesselBasisLayerNew(nn.Module):

    def __init__(self, num_radial, cutoff, envelope_exponent=5):
        super(BesselBasisLayerNew, self).__init__()
        self.num_radial = num_radial
        self.cutoff = cutoff
        self.envelope = Envelope(envelope_exponent)
        freq_init = np.pi * torch.arange(1, num_radial + 1)
        self.frequencies = nn.Parameter(freq_init)

    def forward(self, input_0):
        primals_2 = self.frequencies
        primals_1 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 0.014976