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


@triton.jit
def triton_per_fused_mean_pow_sub_0(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel
    ):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = triton_helpers.promote_to_tensor(tl.sum(tmp1, 0))
    tmp4 = 256.0
    tmp5 = tmp3 / tmp4
    tmp6 = tmp0 - tmp5
    tmp7 = tmp6 * tmp6
    tmp8 = tl.broadcast_to(tmp7, [RBLOCK])
    tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0))
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None)
    tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp10, None)


@triton.jit
def triton_poi_fused_div_mean_mul_neg_pow_sqrt_squeeze_sub_1(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp6 = tl.load(in_ptr2 + x0, xmask)
    tmp7 = tl.load(in_ptr3 + 0)
    tmp8 = tl.broadcast_to(tmp7, [XBLOCK])
    tmp12 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp14 = tl.load(in_ptr2 + (64 + x0), xmask)
    tmp18 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp20 = tl.load(in_ptr2 + (128 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp26 = tl.load(in_ptr2 + (192 + x0), xmask)
    tmp33 = tl.load(in_ptr4 + 0)
    tmp34 = tl.broadcast_to(tmp33, [XBLOCK])
    tmp37 = tl.load(in_ptr5 + 0)
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK])
    tmp3 = 256.0
    tmp4 = tmp2 / tmp3
    tmp5 = tmp0 - tmp4
    tmp9 = tmp8 / tmp3
    tmp10 = tmp6 - tmp9
    tmp11 = tmp5 * tmp10
    tmp13 = tmp12 - tmp4
    tmp15 = tmp14 - tmp9
    tmp16 = tmp13 * tmp15
    tmp17 = tmp11 + tmp16
    tmp19 = tmp18 - tmp4
    tmp21 = tmp20 - tmp9
    tmp22 = tmp19 * tmp21
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 - tmp4
    tmp27 = tmp26 - tmp9
    tmp28 = tmp25 * tmp27
    tmp29 = tmp23 + tmp28
    tmp30 = 4.0
    tmp31 = tmp29 / tmp30
    tmp32 = -tmp31
    tmp35 = tmp34 / tmp3
    tmp36 = libdevice.sqrt(tmp35)
    tmp39 = tmp38 / tmp3
    tmp40 = libdevice.sqrt(tmp39)
    tmp41 = tmp36 * tmp40
    tmp42 = tmp32 / tmp41
    tl.store(in_out_ptr0 + x0, tmp42, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf3 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_per_fused_mean_pow_sub_0[grid(1)](arg0_1, buf0, buf3, 1, 256,
            num_warps=2, num_stages=1)
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf4 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_mean_pow_sub_0[grid(1)](arg1_1, buf1, buf4, 1, 256,
            num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf5 = buf2
        del buf2
        triton_poi_fused_div_mean_mul_neg_pow_sqrt_squeeze_sub_1[grid(64)](buf5
            , arg0_1, buf0, arg1_1, buf1, buf3, buf4, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        del buf0
        del buf1
        del buf3
        del buf4
    return buf5,


class PearsonCorrelationNew(nn.Module):
    """
    Module for measuring Pearson correlation.
    Given samples (x, y), the Pearson correlation coefficient is given by:
    .. math::
        r = rac{{}\\sum_{i=1}^{n} (x_i - \\overline{x})(y_i - \\overline{y})}
        {\\sqrt{\\sum_{i=1}^{n} (x_i - \\overline{x})^2(y_i - \\overline{y})^2}}
    """

    def __init__(self) ->None:
        super(PearsonCorrelationNew, self).__init__()

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


Measured latency_ms: 0.044875