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
import numpy as np
import torch as t
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_sum_0(in_ptr0, 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 = tl.load(in_ptr0 + 5 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (4 + 5 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp8 = tmp6 + tmp7
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_poi_fused_add_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    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 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tl.store(out_ptr0 + x2, tmp6, xmask)


@triton.jit
def triton_poi_fused_add_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    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 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tl.store(out_ptr0 + x2, tmp6, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1, arg4_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (5, 4), (1, 5))
    assert_size_stride(arg2_1, (5, 4), (1, 5))
    assert_size_stride(arg3_1, (5, 4), (1, 5))
    assert_size_stride(arg4_1, (5, 4), (1, 5))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 4, 1), (4, 1, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_sum_0[grid(4)](arg2_1, buf0, 4, XBLOCK=4,
            num_warps=1, num_stages=1)
        del arg2_1
        buf1 = empty_strided_cuda((1, 4, 1), (4, 1, 4), torch.float32)
        triton_poi_fused_sum_0[grid(4)](arg1_1, buf1, 4, XBLOCK=4,
            num_warps=1, num_stages=1)
        del arg1_1
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_1[grid(16)](arg0_1, buf0, buf1, buf2, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf3 = buf1
        del buf1
        triton_poi_fused_sum_0[grid(4)](arg4_1, buf3, 4, XBLOCK=4,
            num_warps=1, num_stages=1)
        del arg4_1
        buf4 = buf0
        del buf0
        triton_poi_fused_sum_0[grid(4)](arg3_1, buf4, 4, XBLOCK=4,
            num_warps=1, num_stages=1)
        del arg3_1
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_2[grid(16)](arg0_1, buf3, buf4, buf5, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del arg0_1
        del buf3
        del buf4
    return buf2, buf5


class SeasonalityBasisNew(t.nn.Module):
    """
    Harmonic functions to model seasonality.
    """

    def __init__(self, harmonics: 'int', backcast_size: 'int',
        forecast_size: 'int'):
        super().__init__()
        self.frequency = np.append(np.zeros(1, dtype=np.float32), np.arange
            (harmonics, harmonics / 2 * forecast_size, dtype=np.float32) /
            harmonics)[None, :]
        backcast_grid = -2 * np.pi * (np.arange(backcast_size, dtype=np.
            float32)[:, None] / forecast_size) * self.frequency
        forecast_grid = 2 * np.pi * (np.arange(forecast_size, dtype=np.
            float32)[:, None] / forecast_size) * self.frequency
        self.backcast_cos_template = t.nn.Parameter(t.tensor(np.transpose(
            np.cos(backcast_grid)), dtype=t.float32), requires_grad=False)
        self.backcast_sin_template = t.nn.Parameter(t.tensor(np.transpose(
            np.sin(backcast_grid)), dtype=t.float32), requires_grad=False)
        self.forecast_cos_template = t.nn.Parameter(t.tensor(np.transpose(
            np.cos(forecast_grid)), dtype=t.float32), requires_grad=False)
        self.forecast_sin_template = t.nn.Parameter(t.tensor(np.transpose(
            np.sin(forecast_grid)), dtype=t.float32), requires_grad=False)

    def forward(self, input_0):
        arg1_1 = self.backcast_cos_template
        arg2_1 = self.backcast_sin_template
        arg3_1 = self.forecast_cos_template
        arg4_1 = self.forecast_sin_template
        arg0_1 = input_0
        output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1])
        return output[0], output[1]


Measured latency_ms: 0.075874