import torch
import torch.nn as nn
import torch.nn.functional as F


class Upsample(nn.Module):
    """ nn.Upsample is deprecated """

    def __init__(self, scale_factor, mode='linear'):
        super(Upsample, self).__init__()
        self.scale_factor = scale_factor
        self.mode = mode

    def forward(self, x):
        x = F.interpolate(x, scale_factor=self.scale_factor, mode=self.mode)
        return x


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


def get_init_inputs():
    return [[], {'scale_factor': 1.0}]

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_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 1.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tl.load(in_ptr0 + (tmp9 + 4 * x1), xmask, eviction_policy=
        'evict_last')
    tmp11 = tl.full([1], 1, tl.int64)
    tmp12 = tmp9 + tmp11
    tmp13 = tl.full([1], 3, tl.int64)
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tmp15 = tl.load(in_ptr0 + (tmp14 + 4 * x1), xmask, eviction_policy=
        'evict_last')
    tmp16 = tmp15 - tmp10
    tmp17 = tmp9.to(tl.float32)
    tmp18 = tmp8 - tmp17
    tmp19 = triton_helpers.maximum(tmp18, tmp7)
    tmp20 = triton_helpers.minimum(tmp19, tmp4)
    tmp21 = tmp16 * tmp20
    tmp22 = tmp10 + tmp21
    tl.store(out_ptr0 + x2, tmp22, xmask)


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


class UpsampleNew(nn.Module):
    """ nn.Upsample is deprecated """

    def __init__(self, scale_factor, mode='linear'):
        super(UpsampleNew, self).__init__()
        self.scale_factor = scale_factor
        self.mode = mode

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