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 import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn
import torch.optim
import torch.utils.data
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__euclidean_dist_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 384
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = -2.0
    tmp7 = tmp5 * tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tmp11 = tl.full([1], 5, tl.int64)
    tmp12 = tmp0 < tmp11
    tmp13 = tmp10 & tmp12
    tmp14 = tl.load(in_ptr0 + 4 * x1, tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tmp14 * tmp14
    tmp16 = tl.load(in_ptr0 + (1 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp19 = tl.load(in_ptr0 + (2 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp22 = tl.load(in_ptr0 + (3 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
    tmp26 = tl.where(tmp13, tmp24, tmp25)
    tmp27 = tmp0 >= tmp11
    tl.full([1], 6, tl.int64)
    tmp30 = 1.0
    tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
    tmp32 = tl.where(tmp27, tmp30, tmp31)
    tmp33 = tl.where(tmp13, tmp26, tmp32)
    tmp34 = tl.where(tmp4, tmp9, tmp33)
    tl.store(out_ptr0 + x2, tmp34, xmask)


@triton.jit
def triton_poi_fused__euclidean_dist_1(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 24
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 5, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = 1.0
    tmp11 = tl.full(tmp10.shape, 0.0, tmp10.dtype)
    tmp12 = tl.where(tmp9, tmp10, tmp11)
    tmp13 = tmp0 >= tmp7
    tl.full([1], 6, tl.int64)
    tmp16 = tl.load(in_ptr0 + 4 * x1, tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp17 = tmp16 * tmp16
    tmp18 = tl.load(in_ptr0 + (1 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = tmp18 * tmp18
    tmp20 = tmp17 + tmp19
    tmp21 = tl.load(in_ptr0 + (2 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp22 = tmp21 * tmp21
    tmp23 = tmp20 + tmp22
    tmp24 = tl.load(in_ptr0 + (3 + 4 * x1), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp25 = tmp24 * tmp24
    tmp26 = tmp23 + tmp25
    tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
    tmp28 = tl.where(tmp13, tmp26, tmp27)
    tmp29 = tl.where(tmp9, tmp12, tmp28)
    tmp30 = tl.where(tmp4, tmp5, tmp29)
    tl.store(out_ptr0 + x2, tmp30, xmask)


@triton.jit
def triton_poi_fused__euclidean_dist_pow_2(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 0.0
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp3 = libdevice.sqrt(tmp2)
    tmp4 = tmp3 * tmp3
    tl.store(out_ptr0 + x0, tmp4, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 6), (6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__euclidean_dist_0[grid(384)](primals_1, buf0, 384,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
        triton_poi_fused__euclidean_dist_1[grid(24)](primals_2, buf1, 24,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(buf1, (6, 4), (1, 6), 0),
            out=buf2)
        del buf0
        del buf1
        buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused__euclidean_dist_pow_2[grid(256)](buf2, buf3, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
    return buf3, primals_2, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
        ), buf2


class PrototypeNew(torch.nn.Module):
    """"""

    def __init__(self, prototype_num, latent_size) ->None:
        super(PrototypeNew, self).__init__()
        self.latent_size = latent_size
        self.prototype_num = prototype_num
        self.prototypes = torch.nn.Parameter(data=torch.rand(self.
            prototype_num, self.latent_size), requires_grad=True)

    def __calc_dist_2(self, x, y):
        """"""
        dis_2 = torch.cdist(x, y, p=2) ** 2
        return dis_2

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


Measured latency_ms: 0.046469