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 libdevice
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_clamp_min_div_linalg_vector_norm_mul_sum_0(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x3 = xindex // 64
    x0 = xindex % 4
    x6 = xindex
    x4 = xindex // 16
    tmp0 = tl.load(in_ptr0 + (4 * x1 + 16 * x3), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (1 + 4 * x1 + 16 * x3), xmask, eviction_policy
        ='evict_last')
    tmp5 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (2 + 4 * x1 + 16 * x3), xmask, eviction_policy
        ='evict_last')
    tmp10 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr0 + (3 + 4 * x1 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr2 + 4 * x4, xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr2 + (1 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp29 = tl.load(in_ptr2 + (2 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp33 = tl.load(in_ptr2 + (3 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 * tmp1
    tmp3 = tmp2 * tmp2
    tmp6 = tmp4 * tmp5
    tmp7 = tmp6 * tmp6
    tmp8 = tmp3 + tmp7
    tmp11 = tmp9 * tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp8 + tmp12
    tmp16 = tmp14 * tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = libdevice.sqrt(tmp18)
    tmp20 = 1e-08
    tmp21 = triton_helpers.maximum(tmp19, tmp20)
    tmp23 = tmp22 * tmp1
    tmp24 = tmp23 * tmp23
    tmp26 = tmp25 * tmp5
    tmp27 = tmp26 * tmp26
    tmp28 = tmp24 + tmp27
    tmp30 = tmp29 * tmp10
    tmp31 = tmp30 * tmp30
    tmp32 = tmp28 + tmp31
    tmp34 = tmp33 * tmp15
    tmp35 = tmp34 * tmp34
    tmp36 = tmp32 + tmp35
    tmp37 = libdevice.sqrt(tmp36)
    tmp38 = triton_helpers.maximum(tmp37, tmp20)
    tmp39 = tmp23 / tmp38
    tmp40 = tmp2 / tmp21
    tmp41 = tmp39 * tmp40
    tmp42 = tmp26 / tmp38
    tmp43 = tmp6 / tmp21
    tmp44 = tmp42 * tmp43
    tmp45 = tmp41 + tmp44
    tmp46 = tmp30 / tmp38
    tmp47 = tmp11 / tmp21
    tmp48 = tmp46 * tmp47
    tmp49 = tmp45 + tmp48
    tmp50 = tmp34 / tmp38
    tmp51 = tmp16 / tmp21
    tmp52 = tmp50 * tmp51
    tmp53 = tmp49 + tmp52
    tl.store(in_out_ptr0 + x6, tmp53, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (16 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr0 + (4 + 16 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tl.load(in_ptr0 + (8 + 16 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp10 = tl.load(in_ptr0 + (12 + 16 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp17 = tl.load(in_ptr0 + (16 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp18 = tl.load(in_ptr0 + (4 + 16 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp19 = tmp17 + tmp18
    tmp20 = tl.load(in_ptr0 + (8 + 16 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp21 = tmp19 + tmp20
    tmp22 = tl.load(in_ptr0 + (12 + 16 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp23 = tmp21 + tmp22
    tmp24 = 4.0
    tmp25 = tmp23 / tmp24
    tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype)
    tmp27 = tl.where(tmp14, tmp25, tmp26)
    tmp28 = tl.where(tmp4, tmp13, tmp27)
    tl.store(out_ptr0 + x2, tmp28, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 256),
            torch.float32)
        buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf0
        get_raw_stream(0)
        triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_sum_0[grid(256)](
            buf2, primals_2, primals_3, primals_1, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_1[grid(128)](buf2, buf3, 128, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf2
    return buf3, primals_1, primals_2, primals_3


def multi_perspective_expand_for_2D(in_tensor, decompose_params):
    """
    Return: [batch_size, decompse_dim, dim]
    """
    in_tensor = in_tensor.unsqueeze(1)
    decompose_params = decompose_params.unsqueeze(0)
    return torch.mul(in_tensor, decompose_params)


class MaxpoolMatchLayNew(nn.Module):

    def __init__(self, mp_dim, cont_dim):
        super().__init__()
        self.cont_dim = cont_dim
        self.mp_dim = mp_dim
        self.register_parameter('weight', nn.Parameter(torch.Tensor(mp_dim,
            cont_dim)))
        self.weight.data.uniform_(-1.0, 1.0)

    def forward(self, input_0, input_1):
        primals_3 = self.weight
        primals_1 = input_0
        primals_2 = input_1
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.028653