import torch
import torch.nn as nn
import torch.nn.functional as F


class CombFilter(nn.Module):

    def __init__(self, ninputs, fmaps, L):
        super().__init__()
        self.L = L
        self.filt = nn.Conv1d(ninputs, fmaps, 2, dilation=L, bias=False)
        r_init_weight = torch.ones(ninputs * fmaps, 2)
        r_init_weight[:, 0] = torch.rand(r_init_weight.size(0))
        self.filt.weight.data = r_init_weight.view(fmaps, ninputs, 2)

    def forward(self, x):
        x_p = F.pad(x, (self.L, 0))
        y = self.filt(x_p)
        return y


def get_inputs():
    return [torch.rand([4, 4])]


def get_init_inputs():
    return [[], {'ninputs': 4, 'fmaps': 4, 'L': 4}]

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
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_constant_pad_nd_0(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 % 8
    x1 = xindex // 8
    x2 = xindex
    tmp0 = -4 + x0
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.load(in_ptr0 + (-4 + x0 + 4 * x1), tmp2 & xmask, other=0.0)
    tl.store(out_ptr0 + x2, tmp3, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4, 2), (8, 2, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_constant_pad_nd_0[grid(32)](primals_1, buf0, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        del primals_1
        buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 8
            ), (0, 8, 1), 0), primals_2, stride=(1,), padding=(0,),
            dilation=(4,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf1, (1, 4, 4), (16, 4, 1))
    return reinterpret_tensor(buf1, (4, 4), (4, 1), 0
        ), primals_2, reinterpret_tensor(buf0, (1, 4, 8), (32, 8, 1), 0)


class CombFilterNew(nn.Module):

    def __init__(self, ninputs, fmaps, L):
        super().__init__()
        self.L = L
        self.filt = nn.Conv1d(ninputs, fmaps, 2, dilation=L, bias=False)
        r_init_weight = torch.ones(ninputs * fmaps, 2)
        r_init_weight[:, 0] = torch.rand(r_init_weight.size(0))
        self.filt.weight.data = r_init_weight.view(fmaps, ninputs, 2)

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