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
import torch.nn.functional
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__to_copy_linalg_vector_norm_lt_sub_0(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (3 + 4 * 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 = 150.0
    tmp21 = tmp19 < tmp20
    tmp22 = tmp21.to(tl.float64)
    tl.store(out_ptr0 + x0, tmp22, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float64)
        get_raw_stream(0)
        triton_poi_fused__to_copy_linalg_vector_norm_lt_sub_0[grid(64)](arg0_1,
            arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
    return buf0,


class BaseMetric(nn.Module):

    def forward(self, y_pr, points_gt, gt_mask=None):
        """
        Base forward method for metric evaluation
        Args:
            y_pr: 3D prediction of joints, tensor of shape (BATCH_SIZExN_JOINTSx3)
            points_gt: 3D gt of joints, tensor of shape (BATCH_SIZExN_JOINTSx3)
            gt_mask: boolean mask, tensor of shape (BATCH_SIZExN_JOINTS). 
            Applied to results, if provided

        Returns:
            Metric as single value, if reduction is given, or as a tensor of values
        """
        pass


class PCKNew(BaseMetric):
    """
    Percentage of correct keypoints according to a thresold value. Usually
    default threshold is 150mm
    """

    def __init__(self, reduction=None, threshold=150, **kwargs):
        super().__init__(**kwargs)
        self.thr = threshold
        self.reduction = reduction

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0]


Measured latency_ms: 0.015029