import torch
import torch.nn as nn


class ncm_output(nn.Module):

    def __init__(self, indim, outdim):
        super(ncm_output, self).__init__()
        self.linear = nn.Linear(indim, outdim)

    def forward(self, x):
        return -1 * torch.norm(x.reshape(x.shape[0], 1, -1) - self.linear.
            weight.transpose(0, 1).reshape(1, -1, x.shape[1]), dim=2).pow(2
            ) - self.linear.bias


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


def get_init_inputs():
    return [[], {'indim': 4, 'outdim': 4}]

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
from torch._inductor.runtime.triton_helpers import libdevice
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


@triton.jit
def triton_poi_fused_linalg_vector_norm_mul_pow_sub_0(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 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp6 = tmp4 - tmp5
    tmp7 = tmp6 * tmp6
    tmp8 = tmp3 + tmp7
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp8 + tmp12
    tmp16 = tmp14 - tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = libdevice.sqrt(tmp18)
    tmp20 = tmp19 * tmp19
    tmp21 = -1.0
    tmp22 = tmp20 * tmp21
    tmp24 = tmp22 - tmp23
    tl.store(out_ptr0 + x2, tmp24, 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,), (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_linalg_vector_norm_mul_pow_sub_0[grid(16)](primals_1,
            primals_2, primals_3, buf0, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        del primals_3
    return buf0, primals_1, primals_2


class ncm_outputNew(nn.Module):

    def __init__(self, indim, outdim):
        super(ncm_outputNew, self).__init__()
        self.linear = nn.Linear(indim, outdim)

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