# AOT ID: ['0_inference']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_7/inductor_cache/63/c636kmgmo34vlk5u2vfnvkukvng7zzniiqxd6lmll4llqk3nm56k.py
# Topologically Sorted Source Nodes: [max_1, min_1, max_2, min_2, ones, Area_o, Area_t, add_6, add_4, sub_4, Inter_w, add_5, sub_6, Inter_t, Inter, lt, zeros, Inter_1, Union, IoU, sub_13, sub_11, pow_1, sub_12, pow_2, dis, C_width, C_height, C, pow_3, R_DIoU, loss, lt_1, zeros_1, loss_1, sum_1], Original ATen: [aten.max, aten.min, aten.ones_like, aten.mul, aten.add, aten.sub, aten.lt, aten.zeros_like, aten.where, aten.div, aten.pow, aten.sum]
# Source node to ATen node mapping:
#   Area_o => mul
#   Area_t => mul_1
#   C => mul_3
#   C_height => sub_10
#   C_width => sub_9
#   Inter => mul_2
#   Inter_1 => where
#   Inter_t => sub_7
#   Inter_w => sub_5
#   IoU => div_8
#   R_DIoU => div_9
#   Union => sub_8
#   add_4 => add_4
#   add_5 => add_5
#   add_6 => add_6
#   dis => add_7
#   loss => add_8
#   loss_1 => where_1
#   lt => lt
#   lt_1 => lt_1
#   max_1 => max_1
#   max_2 => max_2
#   min_1 => min_1
#   min_2 => min_2
#   ones => full_default_1
#   pow_1 => pow_1
#   pow_2 => pow_2
#   pow_3 => pow_3
#   sub_11 => sub_11
#   sub_12 => sub_12
#   sub_13 => sub_13
#   sub_4 => sub_4
#   sub_6 => sub_6
#   sum_1 => sum_1
#   zeros => full_default
#   zeros_1 => full_default_2
# Graph fragment:
#   %max_1 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%view, 1), kwargs = {})
#   %min_1 : [num_users=1] = call_function[target=torch.ops.aten.min.dim](args = (%view_1, 1), kwargs = {})
#   %max_2 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%view_2, 1), kwargs = {})
#   %min_2 : [num_users=1] = call_function[target=torch.ops.aten.min.dim](args = (%view_3, 1), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4], 1), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select, %select_2), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_1, %select_3), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%select, %select_1), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%getitem, %getitem_2), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_4, %sub_4), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%select_2, %select_3), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%getitem_4, %getitem_6), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_5, %sub_6), kwargs = {})
#   %mul_2 : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, %sub_7), kwargs = {})
#   %lt : [num_users=1] = call_function[target=torch.ops.aten.lt.Scalar](args = (%mul_2, 0), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%lt, %full_default, %mul_2), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_6, %where), kwargs = {})
#   %div_8 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%where, %sub_8), kwargs = {})
#   %sub_13 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%full_default_1, %div_8), kwargs = {})
#   %sub_11 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%select_20, %select_22), kwargs = {})
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_11, 2), kwargs = {})
#   %sub_12 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%select_21, %select_23), kwargs = {})
#   %pow_2 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_12, 2), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%pow_1, %pow_2), kwargs = {})
#   %sub_9 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%getitem, %getitem_2), kwargs = {})
#   %sub_10 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%getitem_4, %getitem_6), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_9, %sub_10), kwargs = {})
#   %pow_3 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%mul_3, 2), kwargs = {})
#   %div_9 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_7, %pow_3), kwargs = {})
#   %add_8 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_13, %div_9), kwargs = {})
#   %lt_1 : [num_users=1] = call_function[target=torch.ops.aten.lt.Scalar](args = (%add_8, 0), kwargs = {})
#   %full_default_2 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([4, 4, 4], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where_1 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%lt_1, %full_default_2, %add_8), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%where_1,), kwargs = {})
triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0 = async_compile.triton('triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[1, 64],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {3: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 4), equal_to_1=(3,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 24, 'num_reduction': 1, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@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):
    xnumel = 1
    rnumel = 64
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = (rindex // 4) % 4
    r0 = rindex % 4
    r2 = (rindex // 16)
    r4 = rindex
    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
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    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
    tmp13 = tl.full([1, 1], 8, tl.int64)
    tmp14 = tmp0 < tmp13
    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
    tmp23 = tmp22 >= tmp1
    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
    tmp32 = tmp22 < tmp13
    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)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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)
        # Topologically Sorted Source Nodes: [max_1, min_1, max_2, min_2, ones, Area_o, Area_t, add_6, add_4, sub_4, Inter_w, add_5, sub_6, Inter_t, Inter, lt, zeros, Inter_1, Union, IoU, sub_13, sub_11, pow_1, sub_12, pow_2, dis, C_width, C_height, C, pow_3, R_DIoU, loss, lt_1, zeros_1, loss_1, sum_1], Original ATen: [aten.max, aten.min, aten.ones_like, aten.mul, aten.add, aten.sub, aten.lt, aten.zeros_like, aten.where, aten.div, aten.pow, aten.sum]
        stream0 = get_raw_stream(0)
        triton_per_fused_add_div_lt_max_min_mul_ones_like_pow_sub_sum_where_zeros_like_0.run(arg0_1, arg1_1, buf6, 1, 64, grid=grid(1), stream=stream0)
        del arg0_1
        del arg1_1
    return (buf6, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    arg1_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1, arg1_1])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch


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_loss(torch.nn.Module):

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

    def forward(self, outputs, targets):
        Inter, Union, x_max, x_min, y_max, y_min = Interction_Union(outputs,
            targets)
        IoU = torch.div(Inter, Union)
        C_width = x_max.sub(x_min)
        C_height = y_max.sub(y_min)
        C = torch.mul(C_width, C_height)
        x_o, y_o, x_t, y_t = Center_points(outputs, targets)
        dis = torch.add(torch.pow(x_o.sub(x_t), 2), torch.pow(y_o.sub(y_t), 2))
        R_DIoU = torch.div(dis, torch.pow(C, 2))
        ones = torch.ones_like(IoU)
        loss = torch.add(ones.sub(IoU), R_DIoU)
        zeros = torch.zeros_like(loss)
        loss = torch.where(loss < 0, zeros, loss)
        return torch.sum(loss)


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


def get_init_inputs():
    return [[], {}]

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]
