import torch
import torch.nn as nn
import torch.utils.data


class AE_4D(nn.Module):

    def __init__(self, n_features=4):
        super(AE_4D, self).__init__()
        self.en1 = nn.Linear(n_features, 200)
        self.en2 = nn.Linear(200, 100)
        self.en3 = nn.Linear(100, 50)
        self.en4 = nn.Linear(50, 3)
        self.de1 = nn.Linear(3, 50)
        self.de2 = nn.Linear(50, 100)
        self.de3 = nn.Linear(100, 200)
        self.de4 = nn.Linear(200, n_features)
        self.relu = True
        if self.relu:
            self.leakyRelu = nn.LeakyReLU()
        else:
            self.tanh = nn.Tanh()

    def encode(self, x):
        if self.relu:
            return self.en4(self.leakyRelu(self.en3(self.leakyRelu(self.en2
                (self.leakyRelu(self.en1(x)))))))
        else:
            return self.en4(self.tanh(self.en3(self.tanh(self.en2(self.tanh
                (self.en1(x)))))))

    def decode(self, x):
        if self.relu:
            return self.de4(self.leakyRelu(self.de3(self.leakyRelu(self.de2
                (self.leakyRelu(self.de1(self.leakyRelu(x))))))))
        else:
            return self.de4(self.tanh(self.de3(self.tanh(self.de2(self.tanh
                (self.de1(self.tanh(x))))))))

    def forward(self, x):
        z = self.encode(x)
        return self.decode(z)

    def describe(self):
        return '4-200-200-20-3-20-200-200-4'


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


def get_init_inputs():
    return [[], {}]

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
import torch.nn as nn
import torch.utils.data
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 12800
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 200
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 6400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 100
    x2 = xindex // 1600
    x4 = xindex % 1600
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + (x4 + 1664 * x2), tmp4, xmask)
    tl.store(out_ptr1 + x3, tmp7, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 3200
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 50
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 3
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, 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) = args
    args.clear()
    assert_size_stride(primals_1, (200, 4), (4, 1))
    assert_size_stride(primals_2, (200,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (100, 200), (200, 1))
    assert_size_stride(primals_5, (100,), (1,))
    assert_size_stride(primals_6, (50, 100), (100, 1))
    assert_size_stride(primals_7, (50,), (1,))
    assert_size_stride(primals_8, (3, 50), (50, 1))
    assert_size_stride(primals_9, (3,), (1,))
    assert_size_stride(primals_10, (50, 3), (3, 1))
    assert_size_stride(primals_11, (50,), (1,))
    assert_size_stride(primals_12, (100, 50), (50, 1))
    assert_size_stride(primals_13, (100,), (1,))
    assert_size_stride(primals_14, (200, 100), (100, 1))
    assert_size_stride(primals_15, (200,), (1,))
    assert_size_stride(primals_16, (4, 200), (200, 1))
    assert_size_stride(primals_17, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 200), (200, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
            reinterpret_tensor(primals_1, (4, 200), (1, 4), 0), out=buf0)
        del primals_1
        buf1 = empty_strided_cuda((4, 4, 4, 200), (3200, 800, 200, 1),
            torch.bool)
        buf2 = empty_strided_cuda((4, 4, 4, 200), (3200, 800, 200, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_leaky_relu_0[grid(12800)](buf0, primals_2, buf1,
            buf2, 12800, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_2
        buf3 = empty_strided_cuda((64, 100), (100, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf2, (64, 200), (200, 1), 0),
            reinterpret_tensor(primals_4, (200, 100), (1, 200), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 4, 4, 100), (1664, 400, 100, 1),
            torch.bool)
        buf5 = empty_strided_cuda((4, 4, 4, 100), (1600, 400, 100, 1),
            torch.float32)
        triton_poi_fused_leaky_relu_1[grid(6400)](buf3, primals_5, buf4,
            buf5, 6400, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_5
        buf6 = empty_strided_cuda((64, 50), (50, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf5, (64, 100), (100, 1), 0),
            reinterpret_tensor(primals_6, (100, 50), (1, 100), 0), out=buf6)
        buf7 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.bool)
        buf8 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.
            float32)
        triton_poi_fused_leaky_relu_2[grid(3200)](buf6, primals_7, buf7,
            buf8, 3200, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_7
        buf9 = empty_strided_cuda((64, 3), (3, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf8, (64, 50), (50, 1), 0),
            reinterpret_tensor(primals_8, (50, 3), (1, 50), 0), out=buf9)
        buf10 = empty_strided_cuda((4, 4, 4, 3), (48, 12, 3, 1), torch.bool)
        buf11 = empty_strided_cuda((4, 4, 4, 3), (48, 12, 3, 1), torch.float32)
        triton_poi_fused_leaky_relu_3[grid(192)](buf9, primals_9, buf10,
            buf11, 192, XBLOCK=128, num_warps=4, num_stages=1)
        del buf9
        del primals_9
        buf12 = buf6
        del buf6
        extern_kernels.mm(reinterpret_tensor(buf11, (64, 3), (3, 1), 0),
            reinterpret_tensor(primals_10, (3, 50), (1, 3), 0), out=buf12)
        buf13 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.bool
            )
        buf14 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.
            float32)
        triton_poi_fused_leaky_relu_2[grid(3200)](buf12, primals_11, buf13,
            buf14, 3200, XBLOCK=256, num_warps=4, num_stages=1)
        del buf12
        del primals_11
        buf15 = buf3
        del buf3
        extern_kernels.mm(reinterpret_tensor(buf14, (64, 50), (50, 1), 0),
            reinterpret_tensor(primals_12, (50, 100), (1, 50), 0), out=buf15)
        buf16 = empty_strided_cuda((4, 4, 4, 100), (1664, 400, 100, 1),
            torch.bool)
        buf17 = empty_strided_cuda((4, 4, 4, 100), (1600, 400, 100, 1),
            torch.float32)
        triton_poi_fused_leaky_relu_1[grid(6400)](buf15, primals_13, buf16,
            buf17, 6400, XBLOCK=256, num_warps=4, num_stages=1)
        del buf15
        del primals_13
        buf18 = buf0
        del buf0
        extern_kernels.mm(reinterpret_tensor(buf17, (64, 100), (100, 1), 0),
            reinterpret_tensor(primals_14, (100, 200), (1, 100), 0), out=buf18)
        buf19 = empty_strided_cuda((4, 4, 4, 200), (3200, 800, 200, 1),
            torch.bool)
        buf20 = empty_strided_cuda((4, 4, 4, 200), (3200, 800, 200, 1),
            torch.float32)
        triton_poi_fused_leaky_relu_0[grid(12800)](buf18, primals_15, buf19,
            buf20, 12800, XBLOCK=128, num_warps=4, num_stages=1)
        del buf18
        del primals_15
        buf21 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_17, reinterpret_tensor(buf20, (64, 200
            ), (200, 1), 0), reinterpret_tensor(primals_16, (200, 4), (1, 
            200), 0), alpha=1, beta=1, out=buf21)
        del primals_17
    return (reinterpret_tensor(buf21, (4, 4, 4, 4), (64, 16, 4, 1), 0),
        reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1,
        reinterpret_tensor(buf2, (64, 200), (200, 1), 0), buf4,
        reinterpret_tensor(buf5, (64, 100), (100, 1), 0), buf7,
        reinterpret_tensor(buf8, (64, 50), (50, 1), 0), buf10,
        reinterpret_tensor(buf11, (64, 3), (3, 1), 0), buf13,
        reinterpret_tensor(buf14, (64, 50), (50, 1), 0), buf16,
        reinterpret_tensor(buf17, (64, 100), (100, 1), 0), buf19,
        reinterpret_tensor(buf20, (64, 200), (200, 1), 0), primals_16,
        primals_14, primals_12, primals_10, primals_8, primals_6, primals_4)


class AE_4DNew(nn.Module):

    def __init__(self, n_features=4):
        super(AE_4DNew, self).__init__()
        self.en1 = nn.Linear(n_features, 200)
        self.en2 = nn.Linear(200, 100)
        self.en3 = nn.Linear(100, 50)
        self.en4 = nn.Linear(50, 3)
        self.de1 = nn.Linear(3, 50)
        self.de2 = nn.Linear(50, 100)
        self.de3 = nn.Linear(100, 200)
        self.de4 = nn.Linear(200, n_features)
        self.relu = True
        if self.relu:
            self.leakyRelu = nn.LeakyReLU()
        else:
            self.tanh = nn.Tanh()

    def encode(self, x):
        if self.relu:
            return self.en4(self.leakyRelu(self.en3(self.leakyRelu(self.en2
                (self.leakyRelu(self.en1(x)))))))
        else:
            return self.en4(self.tanh(self.en3(self.tanh(self.en2(self.tanh
                (self.en1(x)))))))

    def decode(self, x):
        if self.relu:
            return self.de4(self.leakyRelu(self.de3(self.leakyRelu(self.de2
                (self.leakyRelu(self.de1(self.leakyRelu(x))))))))
        else:
            return self.de4(self.tanh(self.de3(self.tanh(self.de2(self.tanh
                (self.de1(self.tanh(x))))))))

    def describe(self):
        return '4-200-200-20-3-20-200-200-4'

    def forward(self, input_0):
        primals_1 = self.en1.weight
        primals_2 = self.en1.bias
        primals_4 = self.en2.weight
        primals_5 = self.en2.bias
        primals_6 = self.en3.weight
        primals_7 = self.en3.bias
        primals_8 = self.en4.weight
        primals_9 = self.en4.bias
        primals_10 = self.de1.weight
        primals_11 = self.de1.bias
        primals_12 = self.de2.weight
        primals_13 = self.de2.bias
        primals_14 = self.de3.weight
        primals_15 = self.de3.bias
        primals_16 = self.de4.weight
        primals_17 = self.de4.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])
        return output[0]
