import torch
import torch.nn as nn


class my_Hingeloss(nn.Module):

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

    def forward(self, output, target):
        pos = torch.sum(output * target, 2)
        neg = torch.max((1 - target) * output, 2)
        loss = neg[0] - pos + 1
        loss[loss < 0] = 0
        loss = torch.mean(loss)
        return 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
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_index_put_lift_fresh_max_mean_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 % 4
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), None)
    tmp3 = tl.load(in_ptr1 + (r0 + 16 * r1), None)
    tmp5 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), None)
    tmp7 = tl.load(in_ptr1 + (4 + r0 + 16 * r1), None)
    tmp10 = tl.load(in_ptr0 + (8 + r0 + 16 * r1), None)
    tmp12 = tl.load(in_ptr1 + (8 + r0 + 16 * r1), None)
    tmp15 = tl.load(in_ptr0 + (12 + r0 + 16 * r1), None)
    tmp17 = tl.load(in_ptr1 + (12 + r0 + 16 * r1), None)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tmp2 * tmp3
    tmp6 = tmp1 - tmp5
    tmp8 = tmp6 * tmp7
    tmp9 = triton_helpers.maximum(tmp4, tmp8)
    tmp11 = tmp1 - tmp10
    tmp13 = tmp11 * tmp12
    tmp14 = triton_helpers.maximum(tmp9, tmp13)
    tmp16 = tmp1 - tmp15
    tmp18 = tmp16 * tmp17
    tmp19 = triton_helpers.maximum(tmp14, tmp18)
    tmp20 = tmp3 * tmp0
    tmp21 = tmp7 * tmp5
    tmp22 = tmp20 + tmp21
    tmp23 = tmp12 * tmp10
    tmp24 = tmp22 + tmp23
    tmp25 = tmp17 * tmp15
    tmp26 = tmp24 + tmp25
    tmp27 = tmp19 - tmp26
    tmp28 = tmp27 + tmp1
    tmp29 = 0.0
    tmp30 = tmp28 < tmp29
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK])
    tmp34 = tl.sum(tmp32, 1)[:, None]
    tmp35 = 64.0
    tmp36 = tmp34 / tmp35
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp36, 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)
        buf2 = empty_strided_cuda((), (), torch.float32)
        buf3 = buf2
        del buf2
        get_raw_stream(0)
        triton_per_fused_add_index_put_lift_fresh_max_mean_mul_rsub_sub_sum_0[
            grid(1)](buf3, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf3,


class my_HingelossNew(nn.Module):

    def __init__(self):
        super(my_HingelossNew, self).__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]
