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.triton_helpers import math as tl_math
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_abs_add_linalg_vector_norm_mul_reciprocal_sub_0(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 16
    x4 = xindex % 16
    x0 = xindex % 4
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (x4 + 64 * x2), xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (16 + x4 + 64 * x2), xmask)
    tmp8 = tl.load(in_ptr0 + (32 + x4 + 64 * x2), xmask)
    tmp12 = tl.load(in_ptr0 + (48 + x4 + 64 * x2), xmask)
    tmp21 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp5 = tmp4 - tmp1
    tmp6 = tl_math.abs(tmp5)
    tmp7 = tmp3 + tmp6
    tmp9 = tmp8 - tmp1
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tmp7 + tmp10
    tmp13 = tmp12 - tmp1
    tmp14 = tl_math.abs(tmp13)
    tmp15 = tmp11 + tmp14
    tmp16 = 1.0
    tmp17 = tmp15 + tmp16
    tmp18 = tl.full([1], 1, tl.int32)
    tmp19 = tmp18 / tmp17
    tmp20 = tmp19 * tmp16
    tmp22 = tl_math.abs(tmp21)
    tmp23 = tmp22 - tmp15
    tmp24 = tl_math.abs(tmp23)
    tmp25 = tmp24 + tmp16
    tmp26 = tmp18 / tmp25
    tmp27 = tmp26 * tmp16
    tmp28 = tmp20 - tmp27
    tl.store(in_out_ptr0 + x5, tmp28, xmask)


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


class RationalHat_transformNew(nn.Module):
    """
    Coordinate function as defined in 

    /Hofer, C., Kwitt, R., and Niethammer, M.
    Learning representations of persistence barcodes.
    JMLR, 20(126):1–45, 2019b./

    """

    def __init__(self, output_dim, input_dim=1):
        """
        output dim is the number of lines in the Line point transformation
        """
        super().__init__()
        self.output_dim = output_dim
        self.c_param = torch.nn.Parameter(torch.randn(input_dim, output_dim
            ) * 0.1, requires_grad=True)
        self.r_param = torch.nn.Parameter(torch.randn(1, output_dim) * 0.1,
            requires_grad=True)

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


Measured latency_ms: 0.016346