import torch
import torch.utils.data
import torch.nn as nn
import torch.nn.functional as F


class SDNE_layer(nn.Module):

    def __init__(self, num_node, hidden_size1, hidden_size2, droput, alpha,
        beta, nu1, nu2):
        super(SDNE_layer, self).__init__()
        self.num_node = num_node
        self.hidden_size1 = hidden_size1
        self.hidden_size2 = hidden_size2
        self.droput = droput
        self.alpha = alpha
        self.beta = beta
        self.nu1 = nu1
        self.nu2 = nu2
        self.encode0 = nn.Linear(self.num_node, self.hidden_size1)
        self.encode1 = nn.Linear(self.hidden_size1, self.hidden_size2)
        self.decode0 = nn.Linear(self.hidden_size2, self.hidden_size1)
        self.decode1 = nn.Linear(self.hidden_size1, self.num_node)

    def forward(self, adj_mat, l_mat):
        t0 = F.leaky_relu(self.encode0(adj_mat))
        t0 = F.leaky_relu(self.encode1(t0))
        self.embedding = t0
        t0 = F.leaky_relu(self.decode0(t0))
        t0 = F.leaky_relu(self.decode1(t0))
        L_1st = 2 * torch.trace(torch.mm(torch.mm(torch.t(self.embedding),
            l_mat), self.embedding))
        L_2nd = torch.sum((adj_mat - t0) * adj_mat * self.beta * ((adj_mat -
            t0) * adj_mat * self.beta))
        L_reg = 0
        for param in self.parameters():
            L_reg += self.nu1 * torch.sum(torch.abs(param)
                ) + self.nu2 * torch.sum(param * param)
        return self.alpha * L_1st, L_2nd, self.alpha * L_1st + L_2nd, L_reg

    def get_emb(self, adj):
        t0 = self.encode0(adj)
        t0 = self.encode1(t0)
        return t0


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


def get_init_inputs():
    return [[], {'num_node': 4, 'hidden_size1': 4, 'hidden_size2': 4,
        'droput': 4, 'alpha': 4, 'beta': 4, 'nu1': 4, 'nu2': 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
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.utils.data
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_per_fused_leaky_relu_mul_sub_sum_1(in_ptr0, in_ptr1, out_ptr0,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp2 = 0.0
    tmp3 = tmp1 > tmp2
    tmp4 = 0.01
    tmp5 = tmp1 * tmp4
    tmp6 = tl.where(tmp3, tmp1, tmp5)
    tmp7 = tmp0 - tmp6
    tmp8 = tmp7 * tmp0
    tmp9 = 4.0
    tmp10 = tmp8 * tmp9
    tmp11 = tmp10 * tmp10
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp14 = tl.sum(tmp12, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp14, None)


@triton.jit
def triton_per_fused_add_mul_trace_2(in_ptr0, in_ptr1, out_ptr1, out_ptr2,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + 5 * r0, None, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + 0)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, 1])
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.sum(tmp1, 1)[:, None]
    tmp4 = 2.0
    tmp5 = tmp3 * tmp4
    tmp6 = 4.0
    tmp7 = tmp5 * tmp6
    tmp10 = tmp7 + tmp9
    tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp7, None)
    tl.store(out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp10, None)


@triton.jit
def triton_per_fused_abs_mul_sum_3(in_ptr0, out_ptr0, out_ptr1, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl_math.abs(tmp0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp4 = tl.sum(tmp2, 1)[:, None]
    tmp5 = tmp0 * tmp0
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp8 = tl.sum(tmp6, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp4, None)
    tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None)


@triton.jit
def triton_per_fused_abs_add_mul_sum_4(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9,
    in_ptr10, in_ptr11, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp9 = tl.load(in_ptr1 + r0, None)
    tmp18 = tl.load(in_ptr2 + r0, None)
    tmp27 = tl.load(in_ptr3 + r0, None)
    tmp42 = tl.load(in_ptr4 + 0)
    tmp43 = tl.broadcast_to(tmp42, [XBLOCK, 1])
    tmp45 = tl.load(in_ptr5 + 0)
    tmp46 = tl.broadcast_to(tmp45, [XBLOCK, 1])
    tmp54 = tl.load(in_ptr6 + 0)
    tmp55 = tl.broadcast_to(tmp54, [XBLOCK, 1])
    tmp57 = tl.load(in_ptr7 + 0)
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK, 1])
    tmp66 = tl.load(in_ptr8 + 0)
    tmp67 = tl.broadcast_to(tmp66, [XBLOCK, 1])
    tmp69 = tl.load(in_ptr9 + 0)
    tmp70 = tl.broadcast_to(tmp69, [XBLOCK, 1])
    tmp78 = tl.load(in_ptr10 + 0)
    tmp79 = tl.broadcast_to(tmp78, [XBLOCK, 1])
    tmp81 = tl.load(in_ptr11 + 0)
    tmp82 = tl.broadcast_to(tmp81, [XBLOCK, 1])
    tmp1 = tl_math.abs(tmp0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp4 = tl.sum(tmp2, 1)[:, None]
    tmp5 = tmp0 * tmp0
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp8 = tl.sum(tmp6, 1)[:, None]
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
    tmp13 = tl.sum(tmp11, 1)[:, None]
    tmp14 = tmp9 * tmp9
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tmp19 = tl_math.abs(tmp18)
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK])
    tmp22 = tl.sum(tmp20, 1)[:, None]
    tmp23 = tmp18 * tmp18
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
    tmp26 = tl.sum(tmp24, 1)[:, None]
    tmp28 = tl_math.abs(tmp27)
    tmp29 = tl.broadcast_to(tmp28, [XBLOCK, RBLOCK])
    tmp31 = tl.sum(tmp29, 1)[:, None]
    tmp32 = tmp27 * tmp27
    tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK])
    tmp35 = tl.sum(tmp33, 1)[:, None]
    tmp36 = 4.0
    tmp37 = tmp4 * tmp36
    tmp38 = tmp8 * tmp36
    tmp39 = tmp37 + tmp38
    tmp40 = 0.0
    tmp41 = tmp39 + tmp40
    tmp44 = tmp43 * tmp36
    tmp47 = tmp46 * tmp36
    tmp48 = tmp44 + tmp47
    tmp49 = tmp41 + tmp48
    tmp50 = tmp22 * tmp36
    tmp51 = tmp26 * tmp36
    tmp52 = tmp50 + tmp51
    tmp53 = tmp49 + tmp52
    tmp56 = tmp55 * tmp36
    tmp59 = tmp58 * tmp36
    tmp60 = tmp56 + tmp59
    tmp61 = tmp53 + tmp60
    tmp62 = tmp31 * tmp36
    tmp63 = tmp35 * tmp36
    tmp64 = tmp62 + tmp63
    tmp65 = tmp61 + tmp64
    tmp68 = tmp67 * tmp36
    tmp71 = tmp70 * tmp36
    tmp72 = tmp68 + tmp71
    tmp73 = tmp65 + tmp72
    tmp74 = tmp13 * tmp36
    tmp75 = tmp17 * tmp36
    tmp76 = tmp74 + tmp75
    tmp77 = tmp73 + tmp76
    tmp80 = tmp79 * tmp36
    tmp83 = tmp82 * tmp36
    tmp84 = tmp80 + tmp83
    tmp85 = tmp77 + tmp84
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp85, None)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10) = 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, 4), (4, 1))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (4, 4), (4, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4, 4), (4, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (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_3, reinterpret_tensor(primals_1, (4, 4),
            (1, 4), 0), out=buf0)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_leaky_relu_0[grid(16)](buf0, primals_2, buf1, buf2,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf3 = buf0
        del buf0
        extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4
            ), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_0[grid(16)](buf3, primals_5, buf4, buf5,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf6 = buf3
        del buf3
        extern_kernels.mm(buf5, reinterpret_tensor(primals_6, (4, 4), (1, 4
            ), 0), out=buf6)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_0[grid(16)](buf6, primals_7, buf7, buf8,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf9 = buf6
        del buf6
        extern_kernels.addmm(primals_9, buf8, reinterpret_tensor(primals_8,
            (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf9)
        buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf5, (4, 4), (1, 4), 0),
            primals_10, out=buf10)
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf10, buf5, out=buf11)
        buf13 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_leaky_relu_mul_sub_sum_1[grid(1)](primals_3, buf9,
            buf13, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        buf31 = empty_strided_cuda((), (), torch.float32)
        buf32 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_add_mul_trace_2[grid(1)](buf11, buf13, buf31,
            buf32, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
        del buf11
        buf16 = empty_strided_cuda((), (), torch.float32)
        buf17 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mul_sum_3[grid(1)](primals_2, buf16, buf17, 1,
            4, XBLOCK=1, num_warps=2, num_stages=1)
        buf20 = empty_strided_cuda((), (), torch.float32)
        buf21 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mul_sum_3[grid(1)](primals_5, buf20, buf21, 1,
            4, XBLOCK=1, num_warps=2, num_stages=1)
        buf25 = empty_strided_cuda((), (), torch.float32)
        buf26 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mul_sum_3[grid(1)](primals_7, buf25, buf26, 1,
            4, XBLOCK=1, num_warps=2, num_stages=1)
        buf29 = empty_strided_cuda((), (), torch.float32)
        buf30 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mul_sum_3[grid(1)](primals_9, buf29, buf30, 1,
            4, XBLOCK=1, num_warps=2, num_stages=1)
        buf14 = empty_strided_cuda((), (), torch.float32)
        buf24 = buf14
        del buf14
        buf33 = buf24
        del buf24
        triton_per_fused_abs_add_mul_sum_4[grid(1)](buf33, primals_1,
            primals_8, primals_4, primals_6, buf16, buf17, buf20, buf21,
            buf25, buf26, buf29, buf30, 1, 16, XBLOCK=1, num_warps=2,
            num_stages=1)
        del buf16
        del buf17
        del buf20
        del buf21
        del buf25
        del buf26
        del buf29
        del buf30
    return (buf31, buf13, buf32, buf33, buf5, primals_1, primals_2,
        primals_3, primals_4, primals_5, primals_6, primals_7, primals_8,
        primals_9, primals_10, buf1, buf2, buf4, buf5, buf7, buf8, buf9,
        reinterpret_tensor(buf10, (4, 4), (1, 4), 0))


class SDNE_layerNew(nn.Module):

    def __init__(self, num_node, hidden_size1, hidden_size2, droput, alpha,
        beta, nu1, nu2):
        super(SDNE_layerNew, self).__init__()
        self.num_node = num_node
        self.hidden_size1 = hidden_size1
        self.hidden_size2 = hidden_size2
        self.droput = droput
        self.alpha = alpha
        self.beta = beta
        self.nu1 = nu1
        self.nu2 = nu2
        self.encode0 = nn.Linear(self.num_node, self.hidden_size1)
        self.encode1 = nn.Linear(self.hidden_size1, self.hidden_size2)
        self.decode0 = nn.Linear(self.hidden_size2, self.hidden_size1)
        self.decode1 = nn.Linear(self.hidden_size1, self.num_node)

    def get_emb(self, adj):
        t0 = self.encode0(adj)
        t0 = self.encode1(t0)
        return t0

    def forward(self, input_0, input_1):
        primals_1 = self.encode0.weight
        primals_2 = self.encode0.bias
        primals_3 = self.encode1.weight
        primals_5 = self.encode1.bias
        primals_4 = self.decode0.weight
        primals_7 = self.decode0.bias
        primals_6 = self.decode1.weight
        primals_9 = self.decode1.bias
        primals_8 = input_0
        primals_10 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
        return output[0], output[1], output[2], output[3]
