import torch
import torch.nn as nn


class IRevInjectivePad(nn.Module):
    """
    i-RevNet channel zero padding block.

    Parameters:
    ----------
    padding : int
        Size of the padding.
    """

    def __init__(self, padding):
        super(IRevInjectivePad, self).__init__()
        self.padding = padding
        self.pad = nn.ZeroPad2d(padding=(0, 0, 0, padding))

    def forward(self, x):
        x = x.permute(0, 2, 1, 3)
        x = self.pad(x)
        return x.permute(0, 2, 1, 3)

    def inverse(self, x):
        return x[:, :x.size(1) - self.padding, :, :]


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


def get_init_inputs():
    return [[], {'padding': 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
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 8
    x0 = xindex % 4
    x2 = xindex // 32 % 4
    x3 = xindex // 128
    x4 = xindex
    tmp0 = x1
    tmp1 = tl.full([1], 4, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp2 &
        xmask, other=0.0)
    tl.store(out_ptr0 + x4, tmp3, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 8, 4), (128, 32, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_constant_pad_nd_0[grid(512)](arg0_1, buf0, 512,
            XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
    return reinterpret_tensor(buf0, (4, 8, 4, 4), (128, 4, 32, 1), 0),


class IRevInjectivePadNew(nn.Module):
    """
    i-RevNet channel zero padding block.

    Parameters:
    ----------
    padding : int
        Size of the padding.
    """

    def __init__(self, padding):
        super(IRevInjectivePadNew, self).__init__()
        self.padding = padding
        self.pad = nn.ZeroPad2d(padding=(0, 0, 0, padding))

    def inverse(self, x):
        return x[:, :x.size(1) - self.padding, :, :]

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