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 import nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_lift_fresh_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.full([1], 0, tl.int64)
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp0, None)


@triton.jit
def triton_poi_fused_lift_fresh_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.full([1], -1, tl.int64)
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp0, None)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 240
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 12 % 5
    x0 = xindex % 3
    x3 = xindex // 60
    x4 = xindex % 12
    x5 = xindex
    tmp0 = x2
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tl.load(in_ptr1 + (x4 + 48 * x3), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tmp5 - tmp6
    tmp8 = tl.sigmoid(tmp7)
    tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
    tmp10 = tl.where(tmp4, tmp8, tmp9)
    tmp11 = tmp0 >= tmp3
    tmp12 = tl.full([1], 4, tl.int64)
    tmp13 = tmp0 < tmp12
    tmp14 = tmp11 & tmp13
    tmp15 = tl.load(in_ptr0 + x0, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tl.load(in_ptr1 + (12 + x4 + 12 * (-1 + x2) + 48 * x3), tmp14 &
        xmask, other=0.0)
    tmp17 = tmp15 - tmp16
    tmp18 = tl.sigmoid(tmp17)
    tmp19 = tl.load(in_ptr1 + (x4 + 12 * (-1 + x2) + 48 * x3), tmp14 &
        xmask, other=0.0)
    tmp20 = tmp15 - tmp19
    tmp21 = tl.sigmoid(tmp20)
    tmp22 = tmp18 - tmp21
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp14, tmp22, tmp23)
    tmp25 = tmp0 >= tmp12
    tl.full([1], 5, tl.int64)
    tmp28 = tl.load(in_ptr0 + x0, tmp25 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp29 = tl.load(in_ptr1 + (36 + x4 + 48 * x3), tmp25 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp30 = tmp28 - tmp29
    tmp31 = tl.sigmoid(tmp30)
    tmp32 = 1.0
    tmp33 = tmp32 - tmp31
    tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype)
    tmp35 = tl.where(tmp25, tmp33, tmp34)
    tmp36 = tl.where(tmp14, tmp24, tmp35)
    tmp37 = tl.where(tmp4, tmp10, tmp36)
    tl.store(out_ptr0 + x5, tmp37, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (3,), (1,))
    assert_size_stride(primals_2, (4, 4, 4, 3), (48, 12, 3, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1,), (1,), torch.int64)
        get_raw_stream(0)
        triton_poi_fused_lift_fresh_0[grid(1)](buf0, 1, XBLOCK=1, num_warps
            =1, num_stages=1)
        buf1 = empty_strided_cuda((1,), (1,), torch.int64)
        triton_poi_fused_lift_fresh_1[grid(1)](buf1, 1, XBLOCK=1, num_warps
            =1, num_stages=1)
        buf2 = empty_strided_cuda((4, 5, 4, 3), (60, 12, 3, 1), torch.float32)
        triton_poi_fused_cat_2[grid(240)](primals_1, primals_2, buf2, 240,
            XBLOCK=128, num_warps=4, num_stages=1)
    return buf2, primals_1, primals_2, buf0, buf1


class LogisticCumulativeLinkNew(nn.Module):
    """
    Converts a single number to the proportional odds of belonging to a class.
    Parameters
    ----------
    num_classes : int
        Number of ordered classes to partition the odds into.
    init_cutpoints : str (default='ordered')
        How to initialize the cutpoints of the model. Valid values are
        - ordered : cutpoints are initialized to halfway between each class.
        - random : cutpoints are initialized with random values.
    """

    def __init__(self, num_classes: 'int', init_cutpoints: 'str'='ordered'
        ) ->None:
        assert num_classes > 2, 'Only use this model if you have 3 or more classes'
        super().__init__()
        self.num_classes = num_classes
        self.init_cutpoints = init_cutpoints
        if init_cutpoints == 'ordered':
            num_cutpoints = self.num_classes - 1
            cutpoints = torch.arange(num_cutpoints).float() - num_cutpoints / 2
            self.cutpoints = nn.Parameter(cutpoints)
        elif init_cutpoints == 'random':
            cutpoints = torch.rand(self.num_classes - 1).sort()[0]
            self.cutpoints = nn.Parameter(cutpoints)
        else:
            raise ValueError(
                f'{init_cutpoints} is not a valid init_cutpoints type')

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


Measured latency_ms: 0.01441