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.triton_helpers import libdevice, math as tl_math
import numpy as np
from typing import Tuple
from typing import cast
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_linspace_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 2.0
    tmp3 = tmp1 < tmp2
    tl.store(out_ptr0 + x0, tmp3, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x2 = xindex // 8
    x1 = xindex // 2 % 4
    x3 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x2, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = x1
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 2.0
    tmp9 = tmp7 < tmp8
    tmp10 = 0.6666666666666666
    tmp11 = tmp7 * tmp10
    tmp12 = -1.0
    tmp13 = tmp11 + tmp12
    tmp14 = 3 + -1 * x1
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp15 * tmp10
    tmp17 = 1.0
    tmp18 = tmp17 - tmp16
    tmp19 = tl.where(tmp9, tmp13, tmp18)
    tmp20 = 3.141592653589793
    tmp21 = tmp19 * tmp20
    tmp22 = 1e-08
    tmp23 = tmp21 + tmp22
    tmp24 = tmp5 * tmp23
    tmp25 = tl_math.cos(tmp24)
    tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype)
    tmp27 = tl.where(tmp4, tmp25, tmp26)
    tmp28 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp31 = tl.load(in_ptr0 + x2, tmp28 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp32 = tmp31 * tmp23
    tmp33 = tl_math.sin(tmp32)
    tmp34 = -tmp33
    tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype)
    tmp36 = tl.where(tmp28, tmp34, tmp35)
    tmp37 = tl.where(tmp4, tmp27, tmp36)
    tl.store(out_ptr0 + x3, tmp37, xmask)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x2 = xindex // 8
    x1 = xindex // 2 % 4
    x3 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x2, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = x1
    tmp7 = tmp6.to(tl.float32)
    tmp8 = 2.0
    tmp9 = tmp7 < tmp8
    tmp10 = 0.6666666666666666
    tmp11 = tmp7 * tmp10
    tmp12 = -1.0
    tmp13 = tmp11 + tmp12
    tmp14 = 3 + -1 * x1
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp15 * tmp10
    tmp17 = 1.0
    tmp18 = tmp17 - tmp16
    tmp19 = tl.where(tmp9, tmp13, tmp18)
    tmp20 = 3.141592653589793
    tmp21 = tmp19 * tmp20
    tmp22 = 1e-08
    tmp23 = tmp21 + tmp22
    tmp24 = tmp5 * tmp23
    tmp25 = tl.load(in_ptr1 + x2, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp26 = tmp25 + tmp22
    tmp27 = tmp24 / tmp26
    tmp28 = 0.0
    tmp29 = tmp27 == tmp28
    tmp30 = tl_math.sin(tmp27)
    tmp31 = tmp30 / tmp27
    tmp32 = tl.where(tmp29, tmp17, tmp31)
    tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
    tmp34 = tl.where(tmp4, tmp32, tmp33)
    tmp35 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp38 = tl.full(tmp28.shape, 0.0, tmp28.dtype)
    tmp39 = tl.where(tmp35, tmp28, tmp38)
    tmp40 = tl.where(tmp4, tmp34, tmp39)
    tl.store(out_ptr0 + x3, tmp40, xmask)


@triton.jit
def triton_poi_fused_cat_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp9 = 0.0
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp6, tmp9, tmp10)
    tmp12 = tl.where(tmp4, tmp5, tmp11)
    tl.store(out_ptr0 + x2, tmp12, xmask)


@triton.jit
def triton_poi_fused_mul_stack_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x2 = xindex // 8
    x4 = xindex // 2
    x5 = xindex
    tmp46 = tl.load(in_ptr1 + 2 * x4, xmask, eviction_policy='evict_last')
    tmp48 = tl.load(in_ptr1 + (1 + 2 * x4), xmask, eviction_policy='evict_last'
        )
    tmp53 = tl.load(in_ptr0 + 2 * x2, xmask, eviction_policy='evict_last')
    tmp56 = tl.load(in_ptr0 + (1 + 2 * x2), xmask, eviction_policy='evict_last'
        )
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + 2 * x2, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + (1 + 2 * x4), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tl.load(in_ptr1 + 2 * x4, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp8 = libdevice.atan2(tmp6, tmp7)
    tmp9 = tmp5 * tmp8
    tmp10 = tl.load(in_ptr0 + (1 + 2 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = 0.5
    tmp12 = tmp10 * tmp11
    tmp13 = tmp7 * tmp7
    tmp14 = tmp6 * tmp6
    tmp15 = tmp13 + tmp14
    tmp16 = libdevice.sqrt(tmp15)
    tmp17 = tmp16 * tmp16
    tmp18 = tl_math.log(tmp17)
    tmp19 = tmp12 * tmp18
    tmp20 = tmp9 + tmp19
    tmp21 = tl_math.cos(tmp20)
    tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
    tmp23 = tl.where(tmp4, tmp21, tmp22)
    tmp24 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp27 = tl.load(in_ptr0 + 2 * x2, tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp28 = tl.load(in_ptr1 + (1 + 2 * x4), tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp29 = tl.load(in_ptr1 + 2 * x4, tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp30 = libdevice.atan2(tmp28, tmp29)
    tmp31 = tmp27 * tmp30
    tmp32 = tl.load(in_ptr0 + (1 + 2 * x2), tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp33 = tmp32 * tmp11
    tmp34 = tmp29 * tmp29
    tmp35 = tmp28 * tmp28
    tmp36 = tmp34 + tmp35
    tmp37 = libdevice.sqrt(tmp36)
    tmp38 = tmp37 * tmp37
    tmp39 = tl_math.log(tmp38)
    tmp40 = tmp33 * tmp39
    tmp41 = tmp31 + tmp40
    tmp42 = tl_math.sin(tmp41)
    tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype)
    tmp44 = tl.where(tmp24, tmp42, tmp43)
    tmp45 = tl.where(tmp4, tmp23, tmp44)
    tmp47 = tmp46 * tmp46
    tmp49 = tmp48 * tmp48
    tmp50 = tmp47 + tmp49
    tmp51 = libdevice.sqrt(tmp50)
    tmp52 = tmp51 * tmp51
    tmp54 = tmp53 * tmp11
    tmp55 = libdevice.pow(tmp52, tmp54)
    tmp57 = -tmp56
    tmp58 = libdevice.atan2(tmp48, tmp46)
    tmp59 = tmp57 * tmp58
    tmp60 = tl_math.exp(tmp59)
    tmp61 = tmp55 * tmp60
    tmp62 = tmp61 * tmp45
    tl.store(out_ptr0 + x5, tmp45, xmask)
    tl.store(out_ptr1 + x5, tmp62, xmask)


@triton.jit
def triton_poi_fused_cat_mul_sqrt_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x4 = xindex
    x3 = xindex // 8
    tmp27 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last')
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + 2 * x1, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + 2 * x1, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tmp5 * tmp6
    tmp8 = tl.load(in_ptr0 + (1 + 2 * x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp9 = tl.load(in_ptr1 + (1 + 2 * x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp10 = tmp8 * tmp9
    tmp11 = tmp7 - tmp10
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp17 = tl.load(in_ptr0 + 2 * x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp18 = tl.load(in_ptr1 + (1 + 2 * x1), tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = tmp17 * tmp18
    tmp20 = tl.load(in_ptr0 + (1 + 2 * x1), tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tl.load(in_ptr1 + 2 * x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp22 = tmp20 * tmp21
    tmp23 = tmp19 + tmp22
    tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
    tmp25 = tl.where(tmp14, tmp23, tmp24)
    tmp26 = tl.where(tmp4, tmp13, tmp25)
    tmp28 = libdevice.sqrt(tmp27)
    tmp29 = tmp28 * tmp26
    tl.store(out_ptr0 + x4, tmp26, xmask)
    tl.store(out_ptr1 + x4, tmp29, xmask)


@triton.jit
def triton_poi_fused_mm_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_mm_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_stack_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x3 = xindex // 2
    x4 = xindex % 8
    x5 = xindex
    tmp11 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp9 = tl.load(in_ptr1 + x3, tmp6 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tmp12 = tmp10 + tmp11
    tl.store(out_ptr0 + x5, tmp12, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 2), (2, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4,), (1,), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_linspace_0[grid(4)](buf0, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        triton_poi_fused_cat_1[grid(32)](primals_4, buf1, 32, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        triton_poi_fused_cat_2[grid(32)](primals_3, primals_2, buf2, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((4, 1, 2), (2, 2, 1), torch.float32)
        triton_poi_fused_cat_3[grid(8)](primals_2, buf3, 8, XBLOCK=8,
            num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        triton_poi_fused_mul_stack_4[grid(32)](buf3, buf2, buf4, buf5, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
        triton_poi_fused_cat_mul_sqrt_5[grid(32)](buf5, buf1, primals_3,
            buf6, buf7, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del buf5
        buf8 = empty_strided_cuda((4, 4), (1, 4), torch.float32)
        triton_poi_fused_mm_6[grid(16)](buf7, buf8, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
            buf8, out=buf9)
        buf10 = buf8
        del buf8
        triton_poi_fused_mm_7[grid(16)](buf7, buf10, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
            buf10, out=buf11)
        del buf10
        buf12 = empty_strided_cuda((4, 4, 4, 4, 2), (128, 32, 8, 2, 1),
            torch.float32)
        triton_poi_fused_add_stack_8[grid(512)](buf9, buf11, primals_5,
            buf12, 512, XBLOCK=256, num_warps=4, num_stages=1)
        del buf11
        del buf9
        del primals_5
    return (buf12, buf7, primals_2, primals_3, primals_4, buf0, buf1, buf2,
        buf3, buf4, buf6, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0))


def scale(old_value, old_min, old_max, new_min, new_max):
    old_range = old_max - old_min
    new_range = new_max - new_min
    new_value = (old_value - old_min) * new_range / old_range + new_min
    return new_value


class LinearFBSPNew(torch.nn.Module):

    def __init__(self, out_features: 'int', bias: 'bool'=True, normalized:
        'bool'=False):
        super(LinearFBSPNew, self).__init__()
        self.out_features = out_features
        self.normalized = normalized
        self.eps = 1e-08
        default_dtype = torch.get_default_dtype()
        self.register_parameter('m', torch.nn.Parameter(torch.zeros(self.
            out_features, dtype=default_dtype)))
        self.register_parameter('fb', torch.nn.Parameter(torch.ones(self.
            out_features, dtype=default_dtype)))
        self.register_parameter('fc', torch.nn.Parameter(torch.arange(self.
            out_features, dtype=default_dtype)))
        self.register_parameter('bias', torch.nn.Parameter(torch.normal(0.0,
            0.5, (self.out_features, 2), dtype=default_dtype) if bias else
            cast(torch.nn.Parameter, None)))
        self.m.register_hook(lambda grad: grad / (torch.norm(grad, p=float(
            'inf')) + self.eps))
        self.fb.register_hook(lambda grad: grad / (torch.norm(grad, p=float
            ('inf')) + self.eps))
        self.fc.register_hook(lambda grad: grad / (torch.norm(grad, p=float
            ('inf')) + self.eps))

    @staticmethod
    def power(x1: 'torch.Tensor', x2: 'torch.Tensor') ->torch.Tensor:
        magnitudes = (x1[..., 0] ** 2 + x1[..., 1] ** 2) ** 0.5
        phases = x1[..., 1].atan2(x1[..., 0])
        power_real = x2[..., 0]
        power_imag = x2[..., 1]
        mag_out = (magnitudes ** 2) ** (0.5 * power_real) * torch.exp(-
            power_imag * phases)
        return mag_out.unsqueeze(-1) * torch.stack(((power_real * phases + 
            0.5 * power_imag * (magnitudes ** 2).log()).cos(), (power_real *
            phases + 0.5 * power_imag * (magnitudes ** 2).log()).sin()), dim=-1
            )

    @staticmethod
    def sinc(x: 'torch.Tensor') ->torch.Tensor:
        return torch.where(cast(torch.Tensor, x == 0), torch.ones_like(x), 
            torch.sin(x) / x)

    def _materialize_weights(self, x: 'torch.Tensor') ->Tuple[torch.Tensor,
        bool]:
        x_is_complex = x.shape[-1] == 2
        in_features = x.shape[-1 - int(x_is_complex)]
        t = np.pi * torch.linspace(-1.0, 1.0, in_features, dtype=x.dtype,
            device=x.device).reshape(1, -1, 1) + self.eps
        m = self.m.reshape(-1, 1, 1)
        fb = self.fb.reshape(-1, 1, 1)
        fc = self.fc.reshape(-1, 1, 1)
        kernel = torch.cat((torch.cos(fc * t), -torch.sin(fc * t)), dim=-1)
        scale = fb.sqrt()
        win = self.sinc(fb * t / (m + self.eps))
        win = self.power(torch.cat((win, torch.zeros_like(win)), dim=-1),
            torch.cat((m, torch.zeros_like(m)), dim=-1))
        weights = scale * torch.cat((win[..., :1] * kernel[..., :1] - win[
            ..., 1:] * kernel[..., 1:], win[..., :1] * kernel[..., 1:] + 
            win[..., 1:] * kernel[..., :1]), dim=-1)
        if self.normalized:
            weights = weights / in_features ** 0.5
        return weights, x_is_complex

    def extra_repr(self) ->str:
        return 'out_features={}, bias={}, normalized={}'.format(self.
            out_features, self.bias is not None and self.bias.numel() == 
            self.out_features * 2, self.normalized)

    def forward(self, input_0):
        primals_2 = self.m
        primals_3 = self.fb
        primals_4 = self.fc
        primals_5 = self.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0], output[1]


Measured latency_ms: 0.140999