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
import torch.utils.data
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_rsub_sub_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
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp12 = tl.load(in_ptr0 + (64 + r0), None)
    tmp13 = tl.load(in_ptr1 + (64 + r0), None)
    tmp24 = tl.load(in_ptr0 + (192 + r0), None)
    tmp25 = tl.load(in_ptr1 + (192 + r0), None)
    tmp36 = tl.load(in_ptr0 + (128 + r0), None)
    tmp37 = tl.load(in_ptr1 + (128 + r0), None)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp6 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp8 = tl.sum(tmp6, 1)[:, None]
    tmp9 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tmp14 = tmp12 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tmp18 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
    tmp20 = tl.sum(tmp18, 1)[:, None]
    tmp21 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp23 = tl.sum(tmp21, 1)[:, None]
    tmp26 = tmp24 * tmp25
    tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK])
    tmp29 = tl.sum(tmp27, 1)[:, None]
    tmp30 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
    tmp32 = tl.sum(tmp30, 1)[:, None]
    tmp33 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp35 = tl.sum(tmp33, 1)[:, None]
    tmp38 = tmp36 * tmp37
    tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK])
    tmp41 = tl.sum(tmp39, 1)[:, None]
    tmp42 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
    tmp44 = tl.sum(tmp42, 1)[:, None]
    tmp45 = tl.broadcast_to(tmp37, [XBLOCK, RBLOCK])
    tmp47 = tl.sum(tmp45, 1)[:, None]
    tmp48 = 1.0
    tmp49 = tmp5 + tmp48
    tmp50 = tmp8 + tmp11
    tmp51 = tmp50 - tmp5
    tmp52 = tmp51 + tmp48
    tmp53 = tmp49 / tmp52
    tmp54 = tmp48 - tmp53
    tmp55 = 0.0
    tmp56 = tmp54 + tmp55
    tmp57 = tmp17 + tmp48
    tmp58 = tmp20 + tmp23
    tmp59 = tmp58 - tmp17
    tmp60 = tmp59 + tmp48
    tmp61 = tmp57 / tmp60
    tmp62 = tmp48 - tmp61
    tmp63 = tmp56 + tmp62
    tmp64 = tmp41 + tmp48
    tmp65 = tmp44 + tmp47
    tmp66 = tmp65 - tmp41
    tmp67 = tmp66 + tmp48
    tmp68 = tmp64 / tmp67
    tmp69 = tmp48 - tmp68
    tmp70 = tmp63 + tmp69
    tmp71 = tmp29 + tmp48
    tmp72 = tmp32 + tmp35
    tmp73 = tmp72 - tmp29
    tmp74 = tmp73 + tmp48
    tmp75 = tmp71 / tmp74
    tmp76 = tmp48 - tmp75
    tmp77 = tmp70 + tmp76
    tmp78 = 0.25
    tmp79 = tmp77 * tmp78
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp79, 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_rsub_sub_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 JaccardLossNew(nn.Module):
    """Jaccard loss.
    """

    def __init__(self, size_average=True, reduce=True, smooth=1.0):
        super(JaccardLossNew, self).__init__()
        self.smooth = smooth
        self.reduce = reduce

    def jaccard_loss(self, pred, target):
        loss = 0.0
        for index in range(pred.size()[0]):
            iflat = pred[index].view(-1)
            tflat = target[index].view(-1)
            intersection = (iflat * tflat).sum()
            loss += 1 - (intersection + self.smooth) / (iflat.sum() + tflat
                .sum() - intersection + self.smooth)
        return loss / float(pred.size()[0])

    def jaccard_loss_batch(self, pred, target):
        iflat = pred.view(-1)
        tflat = target.view(-1)
        intersection = (iflat * tflat).sum()
        loss = 1 - (intersection + self.smooth) / (iflat.sum() + tflat.sum(
            ) - intersection + self.smooth)
        return loss

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