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 import triton_helpers
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0(
    in_ptr0, in_ptr1, out_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    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)
    r1 = rindex // 4 % 4
    r0 = rindex % 4
    r2 = rindex // 16
    r3 = rindex % 16
    tmp98 = tl.load(in_ptr0 + (32 + r3 + 64 * r2), None)
    tmp99 = tl.load(in_ptr1 + (32 + r3 + 64 * r2), None)
    tmp103 = tl.load(in_ptr0 + (48 + r3 + 64 * r2), None)
    tmp104 = tl.load(in_ptr1 + (48 + r3 + 64 * r2), None)
    tmp119 = tl.load(in_ptr0 + (r3 + 64 * r2), None)
    tmp120 = tl.load(in_ptr1 + (r3 + 64 * r2), None)
    tmp123 = tl.load(in_ptr0 + (16 + r3 + 64 * r2), None)
    tmp124 = tl.load(in_ptr1 + (16 + r3 + 64 * r2), None)
    tmp0 = r1
    tl.full([1, 1], 0, tl.int64)
    tmp3 = tl.full([1, 1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + tl.broadcast_to(r0 + 4 * r1 + 64 * r2, [XBLOCK,
        RBLOCK]), tmp4, other=0.0)
    tmp6 = tl.load(in_ptr0 + tl.broadcast_to(32 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp4, other=0.0)
    tmp7 = 0.5
    tmp8 = tmp6 * tmp7
    tmp9 = tmp5 + tmp8
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp4, tmp9, tmp10)
    tmp12 = tmp0 >= tmp3
    tl.full([1, 1], 8, tl.int64)
    tmp15 = tl.load(in_ptr1 + tl.broadcast_to(r0 + 4 * (-4 + r1) + 64 * r2,
        [XBLOCK, RBLOCK]), tmp12, other=0.0)
    tmp16 = tl.load(in_ptr1 + tl.broadcast_to(32 + r0 + 4 * (-4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp12, other=0.0)
    tmp17 = tmp16 * tmp7
    tmp18 = tmp15 + tmp17
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp12, tmp18, tmp19)
    tmp21 = tl.where(tmp4, tmp11, tmp20)
    tmp22 = 4 + r1
    tmp24 = tmp22 < tmp3
    tmp25 = tl.load(in_ptr0 + tl.broadcast_to(r0 + 4 * (4 + r1) + 64 * r2,
        [XBLOCK, RBLOCK]), tmp24, other=0.0)
    tmp26 = tl.load(in_ptr0 + tl.broadcast_to(32 + r0 + 4 * (4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp24, other=0.0)
    tmp27 = tmp26 * tmp7
    tmp28 = tmp25 + tmp27
    tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype)
    tmp30 = tl.where(tmp24, tmp28, tmp29)
    tmp31 = tmp22 >= tmp3
    tmp33 = tl.load(in_ptr1 + tl.broadcast_to(r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp31, other=0.0)
    tmp34 = tl.load(in_ptr1 + tl.broadcast_to(32 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp31, other=0.0)
    tmp35 = tmp34 * tmp7
    tmp36 = tmp33 + tmp35
    tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype)
    tmp38 = tl.where(tmp31, tmp36, tmp37)
    tmp39 = tl.where(tmp24, tmp30, tmp38)
    tmp40 = triton_helpers.maximum(tmp21, tmp39)
    tmp41 = tmp5 - tmp8
    tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype)
    tmp43 = tl.where(tmp4, tmp41, tmp42)
    tmp44 = tmp15 - tmp17
    tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype)
    tmp46 = tl.where(tmp12, tmp44, tmp45)
    tmp47 = tl.where(tmp4, tmp43, tmp46)
    tmp48 = tmp25 - tmp27
    tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype)
    tmp50 = tl.where(tmp24, tmp48, tmp49)
    tmp51 = tmp33 - tmp35
    tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype)
    tmp53 = tl.where(tmp31, tmp51, tmp52)
    tmp54 = tl.where(tmp24, tmp50, tmp53)
    tmp55 = triton_helpers.minimum(tmp47, tmp54)
    tmp56 = tl.load(in_ptr0 + tl.broadcast_to(16 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp4, other=0.0)
    tmp57 = tl.load(in_ptr0 + tl.broadcast_to(48 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp4, other=0.0)
    tmp58 = tmp57 * tmp7
    tmp59 = tmp56 + tmp58
    tmp60 = tl.full(tmp59.shape, 0.0, tmp59.dtype)
    tmp61 = tl.where(tmp4, tmp59, tmp60)
    tmp62 = tl.load(in_ptr1 + tl.broadcast_to(16 + r0 + 4 * (-4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp12, other=0.0)
    tmp63 = tl.load(in_ptr1 + tl.broadcast_to(48 + r0 + 4 * (-4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp12, other=0.0)
    tmp64 = tmp63 * tmp7
    tmp65 = tmp62 + tmp64
    tmp66 = tl.full(tmp65.shape, 0.0, tmp65.dtype)
    tmp67 = tl.where(tmp12, tmp65, tmp66)
    tmp68 = tl.where(tmp4, tmp61, tmp67)
    tmp69 = tl.load(in_ptr0 + tl.broadcast_to(16 + r0 + 4 * (4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp24, other=0.0)
    tmp70 = tl.load(in_ptr0 + tl.broadcast_to(48 + r0 + 4 * (4 + r1) + 64 *
        r2, [XBLOCK, RBLOCK]), tmp24, other=0.0)
    tmp71 = tmp70 * tmp7
    tmp72 = tmp69 + tmp71
    tmp73 = tl.full(tmp72.shape, 0.0, tmp72.dtype)
    tmp74 = tl.where(tmp24, tmp72, tmp73)
    tmp75 = tl.load(in_ptr1 + tl.broadcast_to(16 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp31, other=0.0)
    tmp76 = tl.load(in_ptr1 + tl.broadcast_to(48 + r0 + 4 * r1 + 64 * r2, [
        XBLOCK, RBLOCK]), tmp31, other=0.0)
    tmp77 = tmp76 * tmp7
    tmp78 = tmp75 + tmp77
    tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype)
    tmp80 = tl.where(tmp31, tmp78, tmp79)
    tmp81 = tl.where(tmp24, tmp74, tmp80)
    tmp82 = triton_helpers.maximum(tmp68, tmp81)
    tmp83 = tmp56 - tmp58
    tmp84 = tl.full(tmp83.shape, 0.0, tmp83.dtype)
    tmp85 = tl.where(tmp4, tmp83, tmp84)
    tmp86 = tmp62 - tmp64
    tmp87 = tl.full(tmp86.shape, 0.0, tmp86.dtype)
    tmp88 = tl.where(tmp12, tmp86, tmp87)
    tmp89 = tl.where(tmp4, tmp85, tmp88)
    tmp90 = tmp69 - tmp71
    tmp91 = tl.full(tmp90.shape, 0.0, tmp90.dtype)
    tmp92 = tl.where(tmp24, tmp90, tmp91)
    tmp93 = tmp75 - tmp77
    tmp94 = tl.full(tmp93.shape, 0.0, tmp93.dtype)
    tmp95 = tl.where(tmp31, tmp93, tmp94)
    tmp96 = tl.where(tmp24, tmp92, tmp95)
    tmp97 = triton_helpers.minimum(tmp89, tmp96)
    tmp100 = tmp98 + tmp99
    tmp101 = tmp40 - tmp55
    tmp102 = tmp100 - tmp101
    tmp105 = tmp103 + tmp104
    tmp106 = tmp82 - tmp97
    tmp107 = tmp105 - tmp106
    tmp108 = tmp102 * tmp107
    tmp109 = 0.0
    tmp110 = tmp108 < tmp109
    tmp111 = tl.where(tmp110, tmp109, tmp108)
    tmp112 = tmp98 * tmp103
    tmp113 = tmp99 * tmp104
    tmp114 = tmp112 + tmp113
    tmp115 = tmp114 - tmp111
    tmp116 = tmp111 / tmp115
    tmp117 = 1.0
    tmp118 = tmp117 - tmp116
    tmp121 = tmp119 - tmp120
    tmp122 = tmp121 * tmp121
    tmp125 = tmp123 - tmp124
    tmp126 = tmp125 * tmp125
    tmp127 = tmp122 + tmp126
    tmp128 = tmp101 * tmp106
    tmp129 = tmp128 * tmp128
    tmp130 = tmp127 / tmp129
    tmp131 = tmp118 + tmp130
    tmp132 = tmp131 < tmp109
    tmp133 = tl.where(tmp132, tmp109, tmp131)
    tmp134 = tl.broadcast_to(tmp133, [XBLOCK, RBLOCK])
    tmp136 = tl.sum(tmp134, 1)[:, None]
    tl.store(out_ptr4 + tl.full([XBLOCK, 1], 0, tl.int32), tmp136, None)


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)
        buf6 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0[
            grid(1)](arg0_1, arg1_1, buf6, 1, 64, XBLOCK=1, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf6,


def Interction_Union(outputs, targets):
    width_o = outputs[:, 2]
    width_t = targets[:, 2]
    height_o = outputs[:, 3]
    height_t = targets[:, 3]
    x_max = torch.max(torch.stack((outputs[:, 0] + outputs[:, 2] / 2, 
        targets[:, 0] + targets[:, 2] / 2), 1), 1)[0]
    x_min = torch.min(torch.stack((outputs[:, 0] - outputs[:, 2] / 2, 
        targets[:, 0] - targets[:, 2] / 2), 1), 1)[0]
    y_max = torch.max(torch.stack((outputs[:, 1] + outputs[:, 3] / 2, 
        targets[:, 1] + targets[:, 3] / 2), 1), 1)[0]
    y_min = torch.min(torch.stack((outputs[:, 1] - outputs[:, 3] / 2, 
        targets[:, 1] - targets[:, 3] / 2), 1), 1)[0]
    Area_o = torch.mul(width_o, height_o)
    Area_t = torch.mul(width_t, height_t)
    Inter_w = torch.add(width_o, width_t).sub(x_max.sub(x_min))
    Inter_t = torch.add(height_o, height_t).sub(y_max.sub(y_min))
    Inter = torch.mul(Inter_w, Inter_t)
    zeros = torch.zeros_like(Inter)
    Inter = torch.where(Inter < 0, zeros, Inter)
    Union = torch.add(Area_o, Area_t).sub(Inter)
    return Inter, Union, x_max, x_min, y_max, y_min


def Center_points(outputs, targets):
    x_o = outputs[:, 0]
    y_o = outputs[:, 1]
    x_t = targets[:, 0]
    y_t = targets[:, 1]
    return x_o, y_o, x_t, y_t


class DIoU_lossNew(torch.nn.Module):

    def __init__(self):
        super().__init__()

    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.015403