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 math as tl_math
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 % 8
    x1 = xindex // 8
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl_math.cos(tmp7)
    tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
    tmp10 = tl.where(tmp4, tmp8, tmp9)
    tmp11 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp14 = tl.load(in_ptr2 + (4 * x1 + (-4 + x0)), tmp11 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tl.load(in_ptr3 + (-4 + x0), tmp11 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tmp14 + tmp15
    tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype)
    tmp18 = tl.where(tmp11, tmp16, tmp17)
    tmp19 = tl.where(tmp4, tmp10, tmp18)
    tl.store(out_ptr0 + x2, tmp19, 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, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0),
            primals_1, out=buf0)
        del primals_1
        buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0),
            primals_3, out=buf1)
        del primals_3
        buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(512)](buf0, primals_2, buf1, primals_4,
            buf2, 512, XBLOCK=128, num_warps=4, num_stages=1)
        del buf1
        del primals_4
    return buf2, primals_2, buf0, reinterpret_tensor(primals_5, (4, 64), (1,
        4), 0)


def t2v(tau, f, weight_linear, bias_linear, weight_periodic, bias_periodic,
    arg=None):
    if arg:
        v1 = f(torch.matmul(tau, weight_linear) + bias_linear, arg)
    else:
        v1 = f(torch.matmul(tau, weight_linear) + bias_linear)
    v2 = torch.matmul(tau, weight_periodic) + bias_periodic
    return torch.cat([v1, v2], -1)


class CosineActivationNew(nn.Module):

    def __init__(self, in_features, output_features):
        super(CosineActivationNew, self).__init__()
        self.output_features = output_features
        self.weight_linear = nn.parameter.Parameter(torch.randn(in_features,
            output_features))
        self.bias_linear = nn.parameter.Parameter(torch.randn(output_features))
        self.weight_periodic = nn.parameter.Parameter(torch.randn(
            in_features, output_features))
        self.bias_periodic = nn.parameter.Parameter(torch.randn(
            output_features))
        self.f = torch.cos

    def forward(self, input_0):
        primals_1 = self.weight_linear
        primals_2 = self.bias_linear
        primals_3 = self.weight_periodic
        primals_4 = self.bias_periodic
        primals_5 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.031533