import torch
import torch.nn as nn


def chebyshev(L, X, k=3):
    if k == 1:
        return torch.sparse.mm(L, X)
    dp = [X, torch.sparse.mm(L, X)]
    for i in range(2, k):
        nxt = 2 * torch.sparse.mm(L, dp[i - 1])
        dp.append(torch.sparse.FloatTensor.add(nxt, -dp[i - 2]))
    return torch.cat(dp, dim=1)


class SCNLayer(nn.Module):

    def __init__(self, feature_size, output_size, enable_bias=True, k=1):
        super().__init__()
        self.k = k
        self.conv = nn.Linear(k * feature_size, output_size, bias=enable_bias)

    def forward(self, L, x):
        X = chebyshev(L, x, self.k)
        return self.conv(X)


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


def get_init_inputs():
    return [[], {'feature_size': 4, 'output_size': 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_zeros_0(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 = 0.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf1 = torch.ops.aten._sparse_addmm.default(reinterpret_tensor(buf0,
            (4, 4), (1, 4), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4
            ), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), beta=0)
        del primals_1
        del primals_2
        buf2 = buf1
        del buf1
        buf3 = buf0
        del buf0
        extern_kernels.addmm(primals_4, reinterpret_tensor(buf2, (4, 4), (1,
            4), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), alpha
            =1, beta=1, out=buf3)
        del primals_3
        del primals_4
    return buf3, reinterpret_tensor(buf2, (4, 4), (1, 4), 0)


def chebyshev(L, X, k=3):
    if k == 1:
        return torch.sparse.mm(L, X)
    dp = [X, torch.sparse.mm(L, X)]
    for i in range(2, k):
        nxt = 2 * torch.sparse.mm(L, dp[i - 1])
        dp.append(torch.sparse.FloatTensor.add(nxt, -dp[i - 2]))
    return torch.cat(dp, dim=1)


class SCNLayerNew(nn.Module):

    def __init__(self, feature_size, output_size, enable_bias=True, k=1):
        super().__init__()
        self.k = k
        self.conv = nn.Linear(k * feature_size, output_size, bias=enable_bias)

    def forward(self, input_0, input_1):
        primals_1 = self.conv.weight
        primals_4 = self.conv.bias
        primals_2 = input_0
        primals_3 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0]
