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_add_div_mul_0(in_out_ptr0, in_out_ptr1, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
    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_out_ptr0 + x0, xmask)
    tmp3 = tl.load(in_ptr0 + x0, xmask)
    tmp6 = tl.load(in_ptr1 + x0, xmask)
    tmp9 = tl.load(in_ptr2 + x0, xmask)
    tmp12 = tl.load(in_ptr3 + x0, xmask)
    tmp15 = tl.load(in_ptr4 + x0, xmask)
    tmp18 = tl.load(in_ptr5 + x0, xmask)
    tmp21 = tl.load(in_ptr6 + x0, xmask)
    tmp24 = tl.load(in_ptr7 + x0, xmask)
    tmp27 = tl.load(in_ptr8 + x0, xmask)
    tmp32 = tl.load(in_out_ptr1 + x0, xmask)
    tmp1 = 0.9
    tmp2 = tmp0 * tmp1
    tmp4 = tmp3 * tmp1
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp1
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp1
    tmp11 = tmp8 + tmp10
    tmp13 = tmp12 * tmp1
    tmp14 = tmp11 + tmp13
    tmp16 = tmp15 * tmp1
    tmp17 = tmp14 + tmp16
    tmp19 = tmp18 * tmp1
    tmp20 = tmp17 + tmp19
    tmp22 = tmp21 * tmp1
    tmp23 = tmp20 + tmp22
    tmp25 = tmp24 * tmp1
    tmp26 = tmp23 + tmp25
    tmp28 = tmp27 * tmp1
    tmp29 = tmp26 + tmp28
    tmp30 = 0.1
    tmp31 = tmp29 * tmp30
    tmp33 = tmp32 * tmp30
    tmp34 = tmp31 + tmp33
    tl.store(in_out_ptr1 + x0, tmp34, xmask)


def call(args):
    primals_1, primals_2, primals_3 = 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))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4),
            (1, 4), 0), out=buf0)
        del primals_2
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf0, out=buf1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf1, out=buf2)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf2, out=buf3)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf3, out=buf4)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf4, out=buf5)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf5, out=buf6)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf6, out=buf7)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf7, out=buf8)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf8, out=buf9)
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf9, out=buf11)
        buf10 = buf1
        del buf1
        buf12 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_add_div_mul_0[grid(16)](buf10, buf12, buf2, buf3,
            buf4, buf5, buf6, buf7, buf8, buf9, buf11, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf10
        del buf11
        del buf2
        del buf3
        del buf4
        del buf5
        del buf6
        del buf7
        del buf8
        del buf9
    return buf12, primals_1, reinterpret_tensor(primals_3, (4, 4), (1, 4), 0)


class SpectralEigenConv(nn.Module):

    def __init__(self, in_features, out_features, bias=False, K=10, alpha=
        0.1, **kwargs):
        super().__init__()
        assert K > 0
        self.K = K
        self.alpha = alpha
        self.in_features = in_features
        self.out_features = out_features
        self.w = nn.Linear(in_features, out_features, bias=bias)

    def forward(self, x, U, V=None):
        """
        x: node attribute matrix
        if `V=None`:
            U: (N, N) adjacency matrix
        else:
            U: (N, k) eigenvector matrix
            V: (k,) eigenvalue
        """
        x = self.w(x)
        if V is not None:
            V_pow = torch.ones_like(V)
            V_out = torch.zeros_like(V)
            for _ in range(self.K):
                V_pow *= V
                V_out += (1 - self.alpha) * V_pow
            V_out = V_out / self.K
            x_out = U * V_out @ (U.t() @ x) + self.alpha * x
        else:
            adj = U
            x_in = x
            x_out = torch.zeros_like(x)
            for _ in range(self.K):
                x = torch.spmm(adj, x)
                x_out += (1 - self.alpha) * x
            x_out /= self.K
            x_out += self.alpha * x_in
        return x_out

    def reset_parameters(self):
        self.w.reset_parameters()

    def __repr__(self):
        return (
            f'{self.__class__.__name__}({self.in_features}, {self.out_features}, K={self.K}, alpha={self.alpha})'
            )


class SSGCNew(nn.Module):

    def __init__(self, in_features, out_features, K=10, alpha=0.1, hids=[],
        acts=[], dropout=0.5, bias=False):
        super().__init__()
        lin = []
        lin.append(nn.Dropout(dropout))
        for hid, act in zip(hids, acts):
            lin.append(nn.Linear(in_features, hid, bias=bias))
            lin.append(activations.get(act))
            lin.append(nn.Dropout(dropout))
            in_features = hid
        lin = nn.Sequential(*lin)
        conv = SpectralEigenConv(in_features, out_features, bias=bias, K=K,
            alpha=alpha)
        self.lin = lin
        self.conv = conv

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


Measured latency_ms: 0.110208