import torch
import torch.nn as nn
from numpy import *


class Adversarial_Loss(nn.Module):

    def __init__(self, lambda_adv):
        super(Adversarial_Loss, self).__init__()
        self.lambda_adv = lambda_adv
        pass

    def forward(self, input_p, input_h):
        dis_p = input_p * torch.log(input_p)
        dis_h = torch.log(torch.ones_like(input_h) - input_h)
        adv_loss = dis_h + dis_p
        return torch.sum(self.lambda_adv * adv_loss)


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


def get_init_inputs():
    return [[], {'lambda_adv': 4}]

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
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
from numpy import *
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_log_mul_ones_like_sub_sum_0(in_ptr0, in_ptr1,
    out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp4 = tl.load(in_ptr1 + r0, None)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp3 = tl_math.log(tmp2)
    tmp5 = tl_math.log(tmp4)
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 + tmp6
    tmp8 = 4.0
    tmp9 = tmp7 * tmp8
    tmp10 = tl.broadcast_to(tmp9, [RBLOCK])
    tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0))
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp12, 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)
        buf0 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_log_mul_ones_like_sub_sum_0[grid(1)](arg1_1,
            arg0_1, buf0, 1, 256, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf0,


class Adversarial_LossNew(nn.Module):

    def __init__(self, lambda_adv):
        super(Adversarial_LossNew, self).__init__()
        self.lambda_adv = lambda_adv
        pass

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