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 typing import Union
from typing import Optional
from typing import Iterable
from torch import 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_mean_mul_rsub_sum_0(in_out_ptr0, in_ptr0,
    in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    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
    tmp0 = tl.load(in_ptr0 + 16 * r0, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 16 * r0, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (2 + 16 * r0), None, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + 16 * r0), None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr0 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp16 = tl.load(in_ptr1 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp18 = tl.load(in_ptr0 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr1 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr0 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_ptr1 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp26 = tl.load(in_ptr0 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr1 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp31 = tl.load(in_ptr0 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp32 = tl.load(in_ptr1 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp34 = tl.load(in_ptr0 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp35 = tl.load(in_ptr1 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp38 = tl.load(in_ptr0 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp39 = tl.load(in_ptr1 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp43 = tl.load(in_ptr1 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp47 = tl.load(in_ptr0 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp48 = tl.load(in_ptr1 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp51 = tl.load(in_ptr1 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp54 = tl.load(in_ptr0 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp55 = tl.load(in_ptr1 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp58 = tl.load(in_ptr0 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp59 = tl.load(in_ptr1 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tmp17 = tmp15 * tmp16
    tmp20 = tmp18 * tmp19
    tmp21 = tmp17 + tmp20
    tmp24 = tmp22 * tmp23
    tmp25 = tmp21 + tmp24
    tmp28 = tmp26 * tmp27
    tmp29 = tmp25 + tmp28
    tmp30 = tmp14 + tmp29
    tmp33 = tmp31 * tmp32
    tmp36 = tmp34 * tmp35
    tmp37 = tmp33 + tmp36
    tmp40 = tmp38 * tmp39
    tmp41 = tmp37 + tmp40
    tmp44 = tmp42 * tmp43
    tmp45 = tmp41 + tmp44
    tmp46 = tmp30 + tmp45
    tmp49 = tmp47 * tmp48
    tmp52 = tmp50 * tmp51
    tmp53 = tmp49 + tmp52
    tmp56 = tmp54 * tmp55
    tmp57 = tmp53 + tmp56
    tmp60 = tmp58 * tmp59
    tmp61 = tmp57 + tmp60
    tmp62 = tmp46 + tmp61
    tmp63 = 1.0
    tmp64 = tmp63 - tmp0
    tmp65 = tmp64 * tmp1
    tmp66 = tmp63 - tmp3
    tmp67 = tmp66 * tmp4
    tmp68 = tmp65 + tmp67
    tmp69 = tmp63 - tmp7
    tmp70 = tmp69 * tmp8
    tmp71 = tmp68 + tmp70
    tmp72 = tmp63 - tmp11
    tmp73 = tmp72 * tmp12
    tmp74 = tmp71 + tmp73
    tmp75 = tmp63 - tmp15
    tmp76 = tmp75 * tmp16
    tmp77 = tmp63 - tmp18
    tmp78 = tmp77 * tmp19
    tmp79 = tmp76 + tmp78
    tmp80 = tmp63 - tmp22
    tmp81 = tmp80 * tmp23
    tmp82 = tmp79 + tmp81
    tmp83 = tmp63 - tmp26
    tmp84 = tmp83 * tmp27
    tmp85 = tmp82 + tmp84
    tmp86 = tmp74 + tmp85
    tmp87 = tmp63 - tmp31
    tmp88 = tmp87 * tmp32
    tmp89 = tmp63 - tmp34
    tmp90 = tmp89 * tmp35
    tmp91 = tmp88 + tmp90
    tmp92 = tmp63 - tmp38
    tmp93 = tmp92 * tmp39
    tmp94 = tmp91 + tmp93
    tmp95 = tmp63 - tmp42
    tmp96 = tmp95 * tmp43
    tmp97 = tmp94 + tmp96
    tmp98 = tmp86 + tmp97
    tmp99 = tmp63 - tmp47
    tmp100 = tmp99 * tmp48
    tmp101 = tmp63 - tmp50
    tmp102 = tmp101 * tmp51
    tmp103 = tmp100 + tmp102
    tmp104 = tmp63 - tmp54
    tmp105 = tmp104 * tmp55
    tmp106 = tmp103 + tmp105
    tmp107 = tmp63 - tmp58
    tmp108 = tmp107 * tmp59
    tmp109 = tmp106 + tmp108
    tmp110 = tmp98 + tmp109
    tmp111 = tmp63 - tmp1
    tmp112 = tmp0 * tmp111
    tmp113 = tmp63 - tmp4
    tmp114 = tmp3 * tmp113
    tmp115 = tmp112 + tmp114
    tmp116 = tmp63 - tmp8
    tmp117 = tmp7 * tmp116
    tmp118 = tmp115 + tmp117
    tmp119 = tmp63 - tmp12
    tmp120 = tmp11 * tmp119
    tmp121 = tmp118 + tmp120
    tmp122 = tmp63 - tmp16
    tmp123 = tmp15 * tmp122
    tmp124 = tmp63 - tmp19
    tmp125 = tmp18 * tmp124
    tmp126 = tmp123 + tmp125
    tmp127 = tmp63 - tmp23
    tmp128 = tmp22 * tmp127
    tmp129 = tmp126 + tmp128
    tmp130 = tmp63 - tmp27
    tmp131 = tmp26 * tmp130
    tmp132 = tmp129 + tmp131
    tmp133 = tmp121 + tmp132
    tmp134 = tmp63 - tmp32
    tmp135 = tmp31 * tmp134
    tmp136 = tmp63 - tmp35
    tmp137 = tmp34 * tmp136
    tmp138 = tmp135 + tmp137
    tmp139 = tmp63 - tmp39
    tmp140 = tmp38 * tmp139
    tmp141 = tmp138 + tmp140
    tmp142 = tmp63 - tmp43
    tmp143 = tmp42 * tmp142
    tmp144 = tmp141 + tmp143
    tmp145 = tmp133 + tmp144
    tmp146 = tmp63 - tmp48
    tmp147 = tmp47 * tmp146
    tmp148 = tmp63 - tmp51
    tmp149 = tmp50 * tmp148
    tmp150 = tmp147 + tmp149
    tmp151 = tmp63 - tmp55
    tmp152 = tmp54 * tmp151
    tmp153 = tmp150 + tmp152
    tmp154 = tmp63 - tmp59
    tmp155 = tmp58 * tmp154
    tmp156 = tmp153 + tmp155
    tmp157 = tmp145 + tmp156
    tmp158 = 0.0
    tmp159 = tmp62 + tmp158
    tmp160 = 2.0
    tmp161 = tmp159 * tmp160
    tmp162 = tmp110 * tmp63
    tmp163 = tmp161 + tmp162
    tmp164 = tmp163 + tmp157
    tmp165 = 1e-06
    tmp166 = tmp164 + tmp165
    tmp167 = tmp161 / tmp166
    tmp168 = tmp63 - tmp167
    tmp169 = tl.broadcast_to(tmp168, [XBLOCK, RBLOCK])
    tmp171 = tl.sum(tmp169, 1)[:, None]
    tmp172 = 16.0
    tmp173 = tmp171 / tmp172
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp173, 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)
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf4 = buf3
        del buf3
        get_raw_stream(0)
        triton_per_fused_add_div_mean_mul_rsub_sum_0[grid(1)](buf4, arg1_1,
            arg0_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf4,


class FScoreLossNew(nn.modules.loss._WeightedLoss):
    """Uses the 1 - F-score as a loss.

    .. math::
        F = rac{ (1 + eta^2) TP }{ (1 + eta^2) TP + eta^2 FN + FP }

    Args:
        beta: The beta in the above formula.
        eps: Epsilon for numerical stability.
        tp_bias: This is added to the TP count. Should add a little stability for
            very small structures.
        make_onehot: Convert the target segmentation to onehot internally. Turn this
            off if the target is already onehot.
        make_onehot_newaxis: 'newaxis' argument for the onehot conversion.
        ignore_index: These classes will not contribute to the loss. Has no effect if
            reduction is "none".
        weight: Weights for the different classes. Has no effect if reduction is "none".
        reduction: "mean", "sum", or "none".

    """

    def __init__(self, beta: 'float'=1.0, eps: 'float'=1e-06, tp_bias:
        'Union[int, float]'=0, make_onehot: 'bool'=False,
        make_onehot_newaxis: 'bool'=False, ignore_index:
        'Optional[Union[int, Iterable[int]]]'=None, weight:
        'Optional[torch.Tensor]'=None, reduction='mean', **kwargs):
        super(FScoreLossNew, self).__init__(weight=weight, reduction=reduction)
        self.beta = beta
        self.eps = eps
        self.tp_bias = tp_bias
        self.make_onehot = make_onehot
        self.make_onehot_newaxis = make_onehot_newaxis
        self.ignore_index = ignore_index
        if isinstance(ignore_index, int):
            self.ignore_index = [ignore_index]

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