import torch
import torch.utils
import torch.utils.data
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import init


class HamidaEtAl(nn.Module):
    """
    3-D Deep Learning Approach for Remote Sensing Image Classification
    Amina Ben Hamida, Alexandre Benoit, Patrick Lambert, Chokri Ben Amar
    IEEE TGRS, 2018
    https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8344565
    """

    @staticmethod
    def weight_init(m):
        if isinstance(m, nn.Linear) or isinstance(m, nn.Conv3d):
            init.kaiming_normal_(m.weight)
            init.zeros_(m.bias)

    def __init__(self, input_channels, n_classes, patch_size=5, dilation=1):
        super(HamidaEtAl, self).__init__()
        self.patch_size = patch_size
        self.input_channels = input_channels
        dilation = dilation, 1, 1
        if patch_size == 3:
            self.conv1 = nn.Conv3d(1, 20, (3, 3, 3), stride=(1, 1, 1),
                dilation=dilation, padding=(1, 0, 0))
        else:
            self.conv1 = nn.Conv3d(1, 20, (3, 3, 3), stride=(1, 1, 1),
                dilation=dilation, padding=(1, 0, 0))
        self.pool1 = nn.Conv3d(20, 2, (3, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv2 = nn.Conv3d(2, 35, (3, 3, 3), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool2 = nn.Conv3d(35, 2, (2, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv3 = nn.Conv3d(2, 35, (3, 1, 1), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool3 = nn.Conv3d(35, 2, (1, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv4 = nn.Conv3d(2, 35, (3, 1, 1), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool4 = nn.Conv3d(35, 4, (1, 1, 1), dilation=dilation, stride=
            (2, 2, 2), padding=(0, 0, 0))
        self.dropout = nn.Dropout(p=0.5)
        self.features_size = self._get_final_flattened_size()
        self.fc = nn.Linear(self.features_size, n_classes)
        self.apply(self.weight_init)

    def _get_final_flattened_size(self):
        with torch.no_grad():
            x = torch.zeros((1, 1, self.input_channels, self.patch_size,
                self.patch_size))
            x = self.pool1(self.conv1(x))
            x = self.pool2(self.conv2(x))
            x = self.pool3(self.conv3(x))
            x = self.pool4(self.conv4(x))
            _, t, c, w, h = x.size()
        return t * c * w * h

    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = self.pool1(x)
        x = F.relu(self.conv2(x))
        x = self.pool2(x)
        x = F.relu(self.conv3(x))
        x = self.pool3(x)
        x = F.relu(self.conv4(x))
        x = self.pool4(x)
        x = x.view(-1, self.features_size)
        x = self.dropout(x)
        x = self.fc(x)
        return x


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


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

import torch
from torch._inductor.select_algorithm import extern_kernels
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.utils
import torch.utils.data
import torch.nn as nn
from torch.nn import init
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_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 246016 % 20
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 984064
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 123008 % 2
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 115200 % 35
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 489600
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 61200 % 2
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 8568000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 61200 % 35
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 288000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 36000 % 2
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 5040000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 36000 % 35
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_7(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 72000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 4500 % 4
    x0 = xindex % 4500
    x4 = xindex // 4500
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x0 + 4512 * x4), tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_view_8(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 72000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (4512 * (x0 // 4500) + x0 % 4500), xmask)
    tl.store(out_ptr0 + x0, tmp0, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17,
        primals_18, primals_19) = args
    args.clear()
    assert_size_stride(primals_1, (20, 1, 3, 3, 3), (27, 27, 9, 3, 1))
    assert_size_stride(primals_2, (20,), (1,))
    assert_size_stride(primals_3, (4, 1, 64, 64, 64), (262144, 262144, 4096,
        64, 1))
    assert_size_stride(primals_4, (2, 20, 3, 1, 1), (60, 3, 1, 1, 1))
    assert_size_stride(primals_5, (2,), (1,))
    assert_size_stride(primals_6, (35, 2, 3, 3, 3), (54, 27, 9, 3, 1))
    assert_size_stride(primals_7, (35,), (1,))
    assert_size_stride(primals_8, (2, 35, 2, 1, 1), (70, 2, 1, 1, 1))
    assert_size_stride(primals_9, (2,), (1,))
    assert_size_stride(primals_10, (35, 2, 3, 1, 1), (6, 3, 1, 1, 1))
    assert_size_stride(primals_11, (35,), (1,))
    assert_size_stride(primals_12, (2, 35, 1, 1, 1), (35, 1, 1, 1, 1))
    assert_size_stride(primals_13, (2,), (1,))
    assert_size_stride(primals_14, (35, 2, 3, 1, 1), (6, 3, 1, 1, 1))
    assert_size_stride(primals_15, (35,), (1,))
    assert_size_stride(primals_16, (4, 35, 1, 1, 1), (35, 1, 1, 1, 1))
    assert_size_stride(primals_17, (4,), (1,))
    assert_size_stride(primals_18, (4, 4), (4, 1))
    assert_size_stride(primals_19, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1, 1), padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 20, 64, 62, 62), (4920320, 246016, 
            3844, 62, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(19681280)](buf1, primals_2,
            19681280, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_2
        buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 1, 1),
            padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 2, 32, 62, 62), (246016, 123008, 3844,
            62, 1))
        buf3 = buf2
        del buf2
        triton_poi_fused_convolution_1[grid(984064)](buf3, primals_5, 
            984064, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_5
        buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1, 1),
            padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 35, 32, 60, 60), (4032000, 115200, 
            3600, 60, 1))
        buf5 = buf4
        del buf4
        triton_poi_fused_convolution_relu_2[grid(16128000)](buf5, primals_7,
            16128000, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_7
        buf6 = extern_kernels.convolution(buf5, primals_8, stride=(2, 1, 1),
            padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 2, 17, 60, 60), (122400, 61200, 3600, 
            60, 1))
        buf7 = buf6
        del buf6
        triton_poi_fused_convolution_3[grid(489600)](buf7, primals_9, 
            489600, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_9
        buf8 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1, 1
            ), padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 35, 17, 60, 60), (2142000, 61200, 3600,
            60, 1))
        buf9 = buf8
        del buf8
        triton_poi_fused_convolution_relu_4[grid(8568000)](buf9, primals_11,
            8568000, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_11
        buf10 = extern_kernels.convolution(buf9, primals_12, stride=(2, 1, 
            1), padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 2, 10, 60, 60), (72000, 36000, 3600, 
            60, 1))
        buf11 = buf10
        del buf10
        triton_poi_fused_convolution_5[grid(288000)](buf11, primals_13, 
            288000, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_13
        buf12 = extern_kernels.convolution(buf11, primals_14, stride=(1, 1,
            1), padding=(1, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 35, 10, 60, 60), (1260000, 36000, 
            3600, 60, 1))
        buf13 = buf12
        del buf12
        triton_poi_fused_convolution_relu_6[grid(5040000)](buf13,
            primals_15, 5040000, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_15
        buf14 = extern_kernels.convolution(buf13, primals_16, stride=(2, 2,
            2), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 4, 5, 30, 30), (18000, 4500, 900, 30, 1))
        buf15 = empty_strided_cuda((4, 4, 5, 30, 30), (18048, 4512, 900, 30,
            1), torch.float32)
        triton_poi_fused_convolution_7[grid(72000)](buf14, primals_17,
            buf15, 72000, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_17
        buf16 = reinterpret_tensor(buf14, (18000, 4), (4, 1), 0)
        del buf14
        triton_poi_fused_convolution_view_8[grid(72000)](buf15, buf16, 
            72000, XBLOCK=1024, num_warps=4, num_stages=1)
        del buf15
        buf17 = empty_strided_cuda((18000, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_19, buf16, reinterpret_tensor(
            primals_18, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf17)
        del primals_19
    return (buf17, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, primals_12, primals_14, primals_16, buf1, buf3, buf5,
        buf7, buf9, buf11, buf13, buf16, primals_18)


class HamidaEtAlNew(nn.Module):
    """
    3-D Deep Learning Approach for Remote Sensing Image Classification
    Amina Ben Hamida, Alexandre Benoit, Patrick Lambert, Chokri Ben Amar
    IEEE TGRS, 2018
    https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8344565
    """

    @staticmethod
    def weight_init(m):
        if isinstance(m, nn.Linear) or isinstance(m, nn.Conv3d):
            init.kaiming_normal_(m.weight)
            init.zeros_(m.bias)

    def __init__(self, input_channels, n_classes, patch_size=5, dilation=1):
        super(HamidaEtAlNew, self).__init__()
        self.patch_size = patch_size
        self.input_channels = input_channels
        dilation = dilation, 1, 1
        if patch_size == 3:
            self.conv1 = nn.Conv3d(1, 20, (3, 3, 3), stride=(1, 1, 1),
                dilation=dilation, padding=(1, 0, 0))
        else:
            self.conv1 = nn.Conv3d(1, 20, (3, 3, 3), stride=(1, 1, 1),
                dilation=dilation, padding=(1, 0, 0))
        self.pool1 = nn.Conv3d(20, 2, (3, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv2 = nn.Conv3d(2, 35, (3, 3, 3), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool2 = nn.Conv3d(35, 2, (2, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv3 = nn.Conv3d(2, 35, (3, 1, 1), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool3 = nn.Conv3d(35, 2, (1, 1, 1), dilation=dilation, stride=
            (2, 1, 1), padding=(1, 0, 0))
        self.conv4 = nn.Conv3d(2, 35, (3, 1, 1), dilation=dilation, stride=
            (1, 1, 1), padding=(1, 0, 0))
        self.pool4 = nn.Conv3d(35, 4, (1, 1, 1), dilation=dilation, stride=
            (2, 2, 2), padding=(0, 0, 0))
        self.dropout = nn.Dropout(p=0.5)
        self.features_size = self._get_final_flattened_size()
        self.fc = nn.Linear(self.features_size, n_classes)
        self.apply(self.weight_init)

    def _get_final_flattened_size(self):
        with torch.no_grad():
            x = torch.zeros((1, 1, self.input_channels, self.patch_size,
                self.patch_size))
            x = self.pool1(self.conv1(x))
            x = self.pool2(self.conv2(x))
            x = self.pool3(self.conv3(x))
            x = self.pool4(self.conv4(x))
            _, t, c, w, h = x.size()
        return t * c * w * h

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = self.conv1.bias
        primals_4 = self.pool1.weight
        primals_5 = self.pool1.bias
        primals_6 = self.conv2.weight
        primals_7 = self.conv2.bias
        primals_8 = self.pool2.weight
        primals_9 = self.pool2.bias
        primals_10 = self.conv3.weight
        primals_11 = self.conv3.bias
        primals_12 = self.pool3.weight
        primals_13 = self.pool3.bias
        primals_14 = self.conv4.weight
        primals_15 = self.conv4.bias
        primals_16 = self.pool4.weight
        primals_17 = self.pool4.bias
        primals_18 = self.fc.weight
        primals_19 = self.fc.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19])
        return output[0]
