# 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_8/inductor_cache/6b/c6buzk73ml4cn4qgfofpvbpedkpojxukecnqivpettwovefmugdm.py
# Topologically Sorted Source Nodes: [mul, tp, numerator, sub_1, mul_2, fp, mul_3, add_1, sub, mul_1, fn, mul_4, add_2, denominator, tversky_label, tversky_sum, mul_5, tp_1, numerator_1, sub_3, mul_7, fp_1, mul_8, add_6, sub_2, mul_6, fn_1, mul_9, add_7, denominator_1, tversky_label_1, tversky_sum_1, mul_10, tp_2, numerator_2, sub_5, mul_12, fp_2, mul_13, add_10, sub_4, mul_11, fn_2, mul_14, add_11, denominator_2, tversky_label_2, tversky_sum_2, mul_15, tp_3, numerator_3, sub_7, mul_17, fp_3, mul_18, add_14, sub_6, mul_16, fn_3, mul_19, add_15, denominator_3, tversky_label_3, tversky_sum_3, neg, truediv_4], Original ATen: [aten.mul, aten.sum, aten.add, aten.rsub, aten.div, aten.neg]
# Source node to ATen node mapping:
#   add_1 => add_1
#   add_10 => add_11
#   add_11 => add_12
#   add_14 => add_16
#   add_15 => add_17
#   add_2 => add_2
#   add_6 => add_6
#   add_7 => add_7
#   denominator => add_3
#   denominator_1 => add_8
#   denominator_2 => add_13
#   denominator_3 => add_18
#   fn => sum_2
#   fn_1 => sum_5
#   fn_2 => sum_8
#   fn_3 => sum_11
#   fp => sum_3
#   fp_1 => sum_6
#   fp_2 => sum_9
#   fp_3 => sum_12
#   mul => mul
#   mul_1 => mul_1
#   mul_10 => mul_10
#   mul_11 => mul_11
#   mul_12 => mul_12
#   mul_13 => mul_13
#   mul_14 => mul_14
#   mul_15 => mul_15
#   mul_16 => mul_16
#   mul_17 => mul_17
#   mul_18 => mul_18
#   mul_19 => mul_19
#   mul_2 => mul_2
#   mul_3 => mul_3
#   mul_4 => mul_4
#   mul_5 => mul_5
#   mul_6 => mul_6
#   mul_7 => mul_7
#   mul_8 => mul_8
#   mul_9 => mul_9
#   neg => neg
#   numerator => add
#   numerator_1 => add_5
#   numerator_2 => add_10
#   numerator_3 => add_15
#   sub => sub
#   sub_1 => sub_1
#   sub_2 => sub_2
#   sub_3 => sub_3
#   sub_4 => sub_4
#   sub_5 => sub_5
#   sub_6 => sub_6
#   sub_7 => sub_7
#   tp => sum_1
#   tp_1 => sum_4
#   tp_2 => sum_7
#   tp_3 => sum_10
#   truediv_4 => div_4
#   tversky_label => div
#   tversky_label_1 => div_1
#   tversky_label_2 => div_2
#   tversky_label_3 => div_3
#   tversky_sum => add_4
#   tversky_sum_1 => add_9
#   tversky_sum_2 => add_14
#   tversky_sum_3 => add_19
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_1, %select), kwargs = {})
#   %sum_1 : [num_users=2] = call_function[target=torch.ops.aten.sum.default](args = (%mul,), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_1, 1.0), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_1), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_1, %select), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_2,), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_3, 0.7), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_1, %mul_3), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_1, %sub), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_1,), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_2, 0.3), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_1, %mul_4), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, 1.0), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add, %add_3), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, 0.0), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_3, %select_2), kwargs = {})
#   %sum_4 : [num_users=2] = call_function[target=torch.ops.aten.sum.default](args = (%mul_5,), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_4, 1.0), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_3), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_3, %select_2), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_7,), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, 0.7), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_4, %mul_8), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_2), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_3, %sub_2), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_6,), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_5, 0.3), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, %mul_9), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_7, 1.0), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_5, %add_8), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_4, %div_1), kwargs = {})
#   %mul_10 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_5, %select_4), kwargs = {})
#   %sum_7 : [num_users=2] = call_function[target=torch.ops.aten.sum.default](args = (%mul_10,), kwargs = {})
#   %add_10 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_7, 1.0), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_5), kwargs = {})
#   %mul_12 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, %select_4), kwargs = {})
#   %sum_9 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_12,), kwargs = {})
#   %mul_13 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_9, 0.7), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_7, %mul_13), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_4), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_5, %sub_4), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_11,), kwargs = {})
#   %mul_14 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_8, 0.3), kwargs = {})
#   %add_12 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_11, %mul_14), kwargs = {})
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_12, 1.0), kwargs = {})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_10, %add_13), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_9, %div_2), kwargs = {})
#   %mul_15 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_7, %select_6), kwargs = {})
#   %sum_10 : [num_users=2] = call_function[target=torch.ops.aten.sum.default](args = (%mul_15,), kwargs = {})
#   %add_15 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_10, 1.0), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_7), kwargs = {})
#   %mul_17 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_7, %select_6), kwargs = {})
#   %sum_12 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_17,), kwargs = {})
#   %mul_18 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_12, 0.7), kwargs = {})
#   %add_16 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_10, %mul_18), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %select_6), kwargs = {})
#   %mul_16 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_7, %sub_6), kwargs = {})
#   %sum_11 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%mul_16,), kwargs = {})
#   %mul_19 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_11, 0.3), kwargs = {})
#   %add_17 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_16, %mul_19), kwargs = {})
#   %add_18 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_17, 1.0), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_15, %add_18), kwargs = {})
#   %add_19 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_14, %div_3), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%add_19,), kwargs = {})
#   %div_4 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%neg, 4), kwargs = {})
triton_per_fused_add_div_mul_neg_rsub_sum_0 = async_compile.triton('triton_per_fused_add_div_mul_neg_rsub_sum_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_mul_neg_rsub_sum_0', 'mutated_arg_names': ['in_out_ptr1'], 'no_x_dim': False, 'num_load': 8, 'num_reduction': 12, '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_mul_neg_rsub_sum_0(in_out_ptr1, in_ptr0, in_ptr1, 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)
    r0 = rindex % 16
    r1 = (rindex // 16)
    tmp0 = tl.load(in_ptr0 + (r0 + (64*r1)), None)
    tmp1 = tl.load(in_ptr1 + (r0 + (64*r1)), None)
    tmp17 = tl.load(in_ptr0 + (16 + r0 + (64*r1)), None)
    tmp18 = tl.load(in_ptr1 + (16 + r0 + (64*r1)), None)
    tmp33 = tl.load(in_ptr0 + (48 + r0 + (64*r1)), None)
    tmp34 = tl.load(in_ptr1 + (48 + r0 + (64*r1)), None)
    tmp49 = tl.load(in_ptr0 + (32 + r0 + (64*r1)), None)
    tmp50 = tl.load(in_ptr1 + (32 + r0 + (64*r1)), None)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp6 = 1.0
    tmp7 = tmp6 - tmp0
    tmp8 = tmp7 * tmp1
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tmp12 = tmp6 - tmp1
    tmp13 = tmp0 * tmp12
    tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp16 = tl.sum(tmp14, 1)[:, None]
    tmp19 = tmp17 * tmp18
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK])
    tmp22 = tl.sum(tmp20, 1)[:, None]
    tmp23 = tmp6 - tmp17
    tmp24 = tmp23 * tmp18
    tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
    tmp27 = tl.sum(tmp25, 1)[:, None]
    tmp28 = tmp6 - tmp18
    tmp29 = tmp17 * tmp28
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK])
    tmp32 = tl.sum(tmp30, 1)[:, None]
    tmp35 = tmp33 * tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp39 = tmp6 - tmp33
    tmp40 = tmp39 * tmp34
    tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
    tmp43 = tl.sum(tmp41, 1)[:, None]
    tmp44 = tmp6 - tmp34
    tmp45 = tmp33 * tmp44
    tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK])
    tmp48 = tl.sum(tmp46, 1)[:, None]
    tmp51 = tmp49 * tmp50
    tmp52 = tl.broadcast_to(tmp51, [XBLOCK, RBLOCK])
    tmp54 = tl.sum(tmp52, 1)[:, None]
    tmp55 = tmp6 - tmp49
    tmp56 = tmp55 * tmp50
    tmp57 = tl.broadcast_to(tmp56, [XBLOCK, RBLOCK])
    tmp59 = tl.sum(tmp57, 1)[:, None]
    tmp60 = tmp6 - tmp50
    tmp61 = tmp49 * tmp60
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK])
    tmp64 = tl.sum(tmp62, 1)[:, None]
    tmp65 = tmp5 + tmp6
    tmp66 = 0.7
    tmp67 = tmp11 * tmp66
    tmp68 = tmp5 + tmp67
    tmp69 = 0.3
    tmp70 = tmp16 * tmp69
    tmp71 = tmp68 + tmp70
    tmp72 = tmp71 + tmp6
    tmp73 = tmp65 / tmp72
    tmp74 = 0.0
    tmp75 = tmp73 + tmp74
    tmp76 = tmp22 + tmp6
    tmp77 = tmp27 * tmp66
    tmp78 = tmp22 + tmp77
    tmp79 = tmp32 * tmp69
    tmp80 = tmp78 + tmp79
    tmp81 = tmp80 + tmp6
    tmp82 = tmp76 / tmp81
    tmp83 = tmp75 + tmp82
    tmp84 = tmp54 + tmp6
    tmp85 = tmp59 * tmp66
    tmp86 = tmp54 + tmp85
    tmp87 = tmp64 * tmp69
    tmp88 = tmp86 + tmp87
    tmp89 = tmp88 + tmp6
    tmp90 = tmp84 / tmp89
    tmp91 = tmp83 + tmp90
    tmp92 = tmp38 + tmp6
    tmp93 = tmp43 * tmp66
    tmp94 = tmp38 + tmp93
    tmp95 = tmp48 * tmp69
    tmp96 = tmp94 + tmp95
    tmp97 = tmp96 + tmp6
    tmp98 = tmp92 / tmp97
    tmp99 = tmp91 + tmp98
    tmp100 = -tmp99
    tmp101 = 0.25
    tmp102 = tmp100 * tmp101
    tl.debug_barrier()
    tl.store(in_out_ptr1 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp102, 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)
        buf10 = empty_strided_cuda((), (), torch.float32)
        buf13 = buf10; del buf10  # reuse
        # Topologically Sorted Source Nodes: [mul, tp, numerator, sub_1, mul_2, fp, mul_3, add_1, sub, mul_1, fn, mul_4, add_2, denominator, tversky_label, tversky_sum, mul_5, tp_1, numerator_1, sub_3, mul_7, fp_1, mul_8, add_6, sub_2, mul_6, fn_1, mul_9, add_7, denominator_1, tversky_label_1, tversky_sum_1, mul_10, tp_2, numerator_2, sub_5, mul_12, fp_2, mul_13, add_10, sub_4, mul_11, fn_2, mul_14, add_11, denominator_2, tversky_label_2, tversky_sum_2, mul_15, tp_3, numerator_3, sub_7, mul_17, fp_3, mul_18, add_14, sub_6, mul_16, fn_3, mul_19, add_15, denominator_3, tversky_label_3, tversky_sum_3, neg, truediv_4], Original ATen: [aten.mul, aten.sum, aten.add, aten.rsub, aten.div, aten.neg]
        stream0 = get_raw_stream(0)
        triton_per_fused_add_div_mul_neg_rsub_sum_0.run(buf13, arg1_1, arg0_1, 1, 64, grid=grid(1), stream=stream0)
        del arg0_1
        del arg1_1
    return (buf13, )


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
import torch.nn as nn


class TverskyLoss(nn.Module):
    """Tversky Loss.

    .. seealso::
        Salehi, Seyed Sadegh Mohseni, Deniz Erdogmus, and Ali Gholipour. "Tversky loss function for image segmentation
        using 3D fully convolutional deep networks." International Workshop on Machine Learning in Medical Imaging.
        Springer, Cham, 2017.

    Args:
        alpha (float): Weight of false positive voxels.
        beta  (float): Weight of false negative voxels.
        smooth (float): Epsilon to avoid division by zero, when both Numerator and Denominator of Tversky are zeros.

    Attributes:
        alpha (float): Weight of false positive voxels.
        beta  (float): Weight of false negative voxels.
        smooth (float): Epsilon to avoid division by zero, when both Numerator and Denominator of Tversky are zeros.

    Notes:
        - setting alpha=beta=0.5: Equivalent to DiceLoss.
        - default parameters were suggested by https://arxiv.org/pdf/1706.05721.pdf .
    """

    def __init__(self, alpha=0.7, beta=0.3, smooth=1.0):
        super(TverskyLoss, self).__init__()
        self.alpha = alpha
        self.beta = beta
        self.smooth = smooth

    def tversky_index(self, y_pred, y_true):
        """Compute Tversky index.

        Args:
            y_pred (torch Tensor): Prediction.
            y_true (torch Tensor): Target.

        Returns:
            float: Tversky index.
        """
        y_true = y_true.float()
        tp = torch.sum(y_true * y_pred)
        fn = torch.sum(y_true * (1 - y_pred))
        fp = torch.sum((1 - y_true) * y_pred)
        numerator = tp + self.smooth
        denominator = tp + self.alpha * fp + self.beta * fn + self.smooth
        tversky_label = numerator / denominator
        return tversky_label

    def forward(self, input, target):
        n_classes = input.shape[1]
        tversky_sum = 0.0
        for i_label in range(n_classes):
            y_pred, y_true = input[:, i_label], target[:, i_label]
            tversky_sum += self.tversky_index(y_pred, y_true)
        return -tversky_sum / n_classes


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
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_per_fused_add_div_mul_neg_rsub_sum_0(in_out_ptr1, in_ptr0,
    in_ptr1, 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)
    r0 = rindex % 16
    r1 = rindex // 16
    tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
    tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
    tmp17 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp18 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
    tmp33 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp34 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
    tmp49 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp50 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp6 = 1.0
    tmp7 = tmp6 - tmp0
    tmp8 = tmp7 * tmp1
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tmp12 = tmp6 - tmp1
    tmp13 = tmp0 * tmp12
    tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp16 = tl.sum(tmp14, 1)[:, None]
    tmp19 = tmp17 * tmp18
    tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK])
    tmp22 = tl.sum(tmp20, 1)[:, None]
    tmp23 = tmp6 - tmp17
    tmp24 = tmp23 * tmp18
    tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
    tmp27 = tl.sum(tmp25, 1)[:, None]
    tmp28 = tmp6 - tmp18
    tmp29 = tmp17 * tmp28
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK])
    tmp32 = tl.sum(tmp30, 1)[:, None]
    tmp35 = tmp33 * tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp39 = tmp6 - tmp33
    tmp40 = tmp39 * tmp34
    tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
    tmp43 = tl.sum(tmp41, 1)[:, None]
    tmp44 = tmp6 - tmp34
    tmp45 = tmp33 * tmp44
    tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK])
    tmp48 = tl.sum(tmp46, 1)[:, None]
    tmp51 = tmp49 * tmp50
    tmp52 = tl.broadcast_to(tmp51, [XBLOCK, RBLOCK])
    tmp54 = tl.sum(tmp52, 1)[:, None]
    tmp55 = tmp6 - tmp49
    tmp56 = tmp55 * tmp50
    tmp57 = tl.broadcast_to(tmp56, [XBLOCK, RBLOCK])
    tmp59 = tl.sum(tmp57, 1)[:, None]
    tmp60 = tmp6 - tmp50
    tmp61 = tmp49 * tmp60
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK])
    tmp64 = tl.sum(tmp62, 1)[:, None]
    tmp65 = tmp5 + tmp6
    tmp66 = 0.7
    tmp67 = tmp11 * tmp66
    tmp68 = tmp5 + tmp67
    tmp69 = 0.3
    tmp70 = tmp16 * tmp69
    tmp71 = tmp68 + tmp70
    tmp72 = tmp71 + tmp6
    tmp73 = tmp65 / tmp72
    tmp74 = 0.0
    tmp75 = tmp73 + tmp74
    tmp76 = tmp22 + tmp6
    tmp77 = tmp27 * tmp66
    tmp78 = tmp22 + tmp77
    tmp79 = tmp32 * tmp69
    tmp80 = tmp78 + tmp79
    tmp81 = tmp80 + tmp6
    tmp82 = tmp76 / tmp81
    tmp83 = tmp75 + tmp82
    tmp84 = tmp54 + tmp6
    tmp85 = tmp59 * tmp66
    tmp86 = tmp54 + tmp85
    tmp87 = tmp64 * tmp69
    tmp88 = tmp86 + tmp87
    tmp89 = tmp88 + tmp6
    tmp90 = tmp84 / tmp89
    tmp91 = tmp83 + tmp90
    tmp92 = tmp38 + tmp6
    tmp93 = tmp43 * tmp66
    tmp94 = tmp38 + tmp93
    tmp95 = tmp48 * tmp69
    tmp96 = tmp94 + tmp95
    tmp97 = tmp96 + tmp6
    tmp98 = tmp92 / tmp97
    tmp99 = tmp91 + tmp98
    tmp100 = -tmp99
    tmp101 = 0.25
    tmp102 = tmp100 * tmp101
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp102, 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)
        buf10 = empty_strided_cuda((), (), torch.float32)
        buf13 = buf10
        del buf10
        get_raw_stream(0)
        triton_per_fused_add_div_mul_neg_rsub_sum_0[grid(1)](buf13, arg1_1,
            arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf13,


class TverskyLossNew(nn.Module):
    """Tversky Loss.

    .. seealso::
        Salehi, Seyed Sadegh Mohseni, Deniz Erdogmus, and Ali Gholipour. "Tversky loss function for image segmentation
        using 3D fully convolutional deep networks." International Workshop on Machine Learning in Medical Imaging.
        Springer, Cham, 2017.

    Args:
        alpha (float): Weight of false positive voxels.
        beta  (float): Weight of false negative voxels.
        smooth (float): Epsilon to avoid division by zero, when both Numerator and Denominator of Tversky are zeros.

    Attributes:
        alpha (float): Weight of false positive voxels.
        beta  (float): Weight of false negative voxels.
        smooth (float): Epsilon to avoid division by zero, when both Numerator and Denominator of Tversky are zeros.

    Notes:
        - setting alpha=beta=0.5: Equivalent to DiceLoss.
        - default parameters were suggested by https://arxiv.org/pdf/1706.05721.pdf .
    """

    def __init__(self, alpha=0.7, beta=0.3, smooth=1.0):
        super(TverskyLossNew, self).__init__()
        self.alpha = alpha
        self.beta = beta
        self.smooth = smooth

    def tversky_index(self, y_pred, y_true):
        """Compute Tversky index.

        Args:
            y_pred (torch Tensor): Prediction.
            y_true (torch Tensor): Target.

        Returns:
            float: Tversky index.
        """
        y_true = y_true.float()
        tp = torch.sum(y_true * y_pred)
        fn = torch.sum(y_true * (1 - y_pred))
        fp = torch.sum((1 - y_true) * y_pred)
        numerator = tp + self.smooth
        denominator = tp + self.alpha * fp + self.beta * fn + self.smooth
        tversky_label = numerator / denominator
        return tversky_label

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