from torch.autograd import Function
import torch
import torch.nn as nn


def sparsemax_bisect(X, dim=-1, n_iter=50, ensure_sum_one=True):
    """sparsemax: normalizing sparse transform (a la softmax), via bisection.

    Solves the projection:

        min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.

    Parameters
    ----------
    X : torch.Tensor
        The input tensor.

    dim : int
        The dimension along which to apply sparsemax.

    n_iter : int
        Number of bisection iterations. For float32, 24 iterations should
        suffice for machine precision.

    ensure_sum_one : bool,
        Whether to divide the result by its sum. If false, the result might
        sum to close but not exactly 1, which might cause downstream problems.

    Note: This function does not yet support normalizing along anything except
    the last dimension. Please use transposing and views to achieve more
    general behavior.

    Returns
    -------
    P : torch tensor, same shape as X
        The projection result, such that P.sum(dim=dim) == 1 elementwise.
    """
    return SparsemaxBisectFunction.apply(X, dim, n_iter, ensure_sum_one)


class EntmaxBisectFunction(Function):

    @classmethod
    def _gp(cls, x, alpha):
        return x ** (alpha - 1)

    @classmethod
    def _gp_inv(cls, y, alpha):
        return y ** (1 / (alpha - 1))

    @classmethod
    def _p(cls, X, alpha):
        return cls._gp_inv(torch.clamp(X, min=0), alpha)

    @classmethod
    def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True
        ):
        if not isinstance(alpha, torch.Tensor):
            alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device)
        alpha_shape = list(X.shape)
        alpha_shape[dim] = 1
        alpha = alpha.expand(*alpha_shape)
        ctx.alpha = alpha
        ctx.dim = dim
        d = X.shape[dim]
        X = X * (alpha - 1)
        max_val, _ = X.max(dim=dim, keepdim=True)
        tau_lo = max_val - cls._gp(1, alpha)
        tau_hi = max_val - cls._gp(1 / d, alpha)
        f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1
        dm = tau_hi - tau_lo
        for it in range(n_iter):
            dm /= 2
            tau_m = tau_lo + dm
            p_m = cls._p(X - tau_m, alpha)
            f_m = p_m.sum(dim) - 1
            mask = (f_m * f_lo >= 0).unsqueeze(dim)
            tau_lo = torch.where(mask, tau_m, tau_lo)
        if ensure_sum_one:
            p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim)
        ctx.save_for_backward(p_m)
        return p_m

    @classmethod
    def backward(cls, ctx, dY):
        Y, = ctx.saved_tensors
        gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1))
        dX = dY * gppr
        q = dX.sum(ctx.dim) / gppr.sum(ctx.dim)
        q = q.unsqueeze(ctx.dim)
        dX -= q * gppr
        d_alpha = None
        if ctx.needs_input_grad[1]:
            S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1))
            ent = S.sum(ctx.dim).unsqueeze(ctx.dim)
            Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim)
            d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2
            d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1)
            d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim)
        return dX, d_alpha, None, None, None


class SparsemaxBisectFunction(EntmaxBisectFunction):

    @classmethod
    def _gp(cls, x, alpha):
        return x

    @classmethod
    def _gp_inv(cls, y, alpha):
        return y

    @classmethod
    def _p(cls, x, alpha):
        return torch.clamp(x, min=0)

    @classmethod
    def forward(cls, ctx, X, dim=-1, n_iter=50, ensure_sum_one=True):
        return super().forward(ctx, X, alpha=2, dim=dim, n_iter=50,
            ensure_sum_one=True)

    @classmethod
    def backward(cls, ctx, dY):
        Y, = ctx.saved_tensors
        gppr = Y > 0
        dX = dY * gppr
        q = dX.sum(ctx.dim) / gppr.sum(ctx.dim)
        q = q.unsqueeze(ctx.dim)
        dX -= q * gppr
        return dX, None, None, None


class SparsemaxBisect(nn.Module):

    def __init__(self, dim=-1, n_iter=None):
        """sparsemax: normalizing sparse transform (a la softmax) via bisection

        Solves the projection:

            min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.

        Parameters
        ----------
        dim : int
            The dimension along which to apply sparsemax.

        n_iter : int
            Number of bisection iterations. For float32, 24 iterations should
            suffice for machine precision.
        """
        self.dim = dim
        self.n_iter = n_iter
        super().__init__()

    def forward(self, X):
        return sparsemax_bisect(X, dim=self.dim, n_iter=self.n_iter)


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


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

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.autograd import Function
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_add_clamp_div_max_mul_sub_sum_where_0(in_out_ptr8,
    in_ptr0, 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 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp7 = 1.0
    tmp8 = tmp6 - tmp7
    tmp9 = 0.25
    tmp10 = tmp6 - tmp9
    tmp11 = tmp10 - tmp8
    tmp12 = 0.5
    tmp13 = tmp11 * tmp12
    tmp14 = tmp8 + tmp13
    tmp15 = tmp0 - tmp14
    tmp16 = 0.0
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp18 = tmp1 - tmp14
    tmp19 = triton_helpers.maximum(tmp18, tmp16)
    tmp20 = tmp17 + tmp19
    tmp21 = tmp3 - tmp14
    tmp22 = triton_helpers.maximum(tmp21, tmp16)
    tmp23 = tmp20 + tmp22
    tmp24 = tmp5 - tmp14
    tmp25 = triton_helpers.maximum(tmp24, tmp16)
    tmp26 = tmp23 + tmp25
    tmp27 = tmp26 - tmp7
    tmp28 = tmp0 - tmp8
    tmp29 = triton_helpers.maximum(tmp28, tmp16)
    tmp30 = tmp1 - tmp8
    tmp31 = triton_helpers.maximum(tmp30, tmp16)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp3 - tmp8
    tmp34 = triton_helpers.maximum(tmp33, tmp16)
    tmp35 = tmp32 + tmp34
    tmp36 = tmp5 - tmp8
    tmp37 = triton_helpers.maximum(tmp36, tmp16)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp38 - tmp7
    tmp40 = tmp27 * tmp39
    tmp41 = tmp40 >= tmp16
    tmp42 = tl.where(tmp41, tmp14, tmp8)
    tmp43 = tmp13 * tmp12
    tmp44 = tmp42 + tmp43
    tmp45 = tmp0 - tmp44
    tmp46 = triton_helpers.maximum(tmp45, tmp16)
    tmp47 = tmp1 - tmp44
    tmp48 = triton_helpers.maximum(tmp47, tmp16)
    tmp49 = tmp46 + tmp48
    tmp50 = tmp3 - tmp44
    tmp51 = triton_helpers.maximum(tmp50, tmp16)
    tmp52 = tmp49 + tmp51
    tmp53 = tmp5 - tmp44
    tmp54 = triton_helpers.maximum(tmp53, tmp16)
    tmp55 = tmp52 + tmp54
    tmp56 = tmp55 - tmp7
    tmp57 = tmp56 * tmp39
    tmp58 = tmp57 >= tmp16
    tmp59 = tl.where(tmp58, tmp44, tmp42)
    tmp60 = tmp43 * tmp12
    tmp61 = tmp59 + tmp60
    tmp62 = tmp0 - tmp61
    tmp63 = triton_helpers.maximum(tmp62, tmp16)
    tmp64 = tmp1 - tmp61
    tmp65 = triton_helpers.maximum(tmp64, tmp16)
    tmp66 = tmp63 + tmp65
    tmp67 = tmp3 - tmp61
    tmp68 = triton_helpers.maximum(tmp67, tmp16)
    tmp69 = tmp66 + tmp68
    tmp70 = tmp5 - tmp61
    tmp71 = triton_helpers.maximum(tmp70, tmp16)
    tmp72 = tmp69 + tmp71
    tmp73 = tmp72 - tmp7
    tmp74 = tmp73 * tmp39
    tmp75 = tmp74 >= tmp16
    tmp76 = tl.where(tmp75, tmp61, tmp59)
    tmp77 = tmp60 * tmp12
    tmp78 = tmp76 + tmp77
    tmp79 = tmp0 - tmp78
    tmp80 = triton_helpers.maximum(tmp79, tmp16)
    tmp81 = tmp1 - tmp78
    tmp82 = triton_helpers.maximum(tmp81, tmp16)
    tmp83 = tmp80 + tmp82
    tmp84 = tmp3 - tmp78
    tmp85 = triton_helpers.maximum(tmp84, tmp16)
    tmp86 = tmp83 + tmp85
    tmp87 = tmp5 - tmp78
    tmp88 = triton_helpers.maximum(tmp87, tmp16)
    tmp89 = tmp86 + tmp88
    tmp90 = tmp89 - tmp7
    tmp91 = tmp90 * tmp39
    tmp92 = tmp91 >= tmp16
    tmp93 = tl.where(tmp92, tmp78, tmp76)
    tmp94 = tmp77 * tmp12
    tmp95 = tmp93 + tmp94
    tmp96 = tmp0 - tmp95
    tmp97 = triton_helpers.maximum(tmp96, tmp16)
    tmp98 = tmp1 - tmp95
    tmp99 = triton_helpers.maximum(tmp98, tmp16)
    tmp100 = tmp97 + tmp99
    tmp101 = tmp3 - tmp95
    tmp102 = triton_helpers.maximum(tmp101, tmp16)
    tmp103 = tmp100 + tmp102
    tmp104 = tmp5 - tmp95
    tmp105 = triton_helpers.maximum(tmp104, tmp16)
    tmp106 = tmp103 + tmp105
    tmp107 = tmp106 - tmp7
    tmp108 = tmp107 * tmp39
    tmp109 = tmp108 >= tmp16
    tmp110 = tl.where(tmp109, tmp95, tmp93)
    tmp111 = tmp94 * tmp12
    tmp112 = tmp110 + tmp111
    tmp113 = tmp0 - tmp112
    tmp114 = triton_helpers.maximum(tmp113, tmp16)
    tmp115 = tmp1 - tmp112
    tmp116 = triton_helpers.maximum(tmp115, tmp16)
    tmp117 = tmp114 + tmp116
    tmp118 = tmp3 - tmp112
    tmp119 = triton_helpers.maximum(tmp118, tmp16)
    tmp120 = tmp117 + tmp119
    tmp121 = tmp5 - tmp112
    tmp122 = triton_helpers.maximum(tmp121, tmp16)
    tmp123 = tmp120 + tmp122
    tmp124 = tmp123 - tmp7
    tmp125 = tmp124 * tmp39
    tmp126 = tmp125 >= tmp16
    tmp127 = tl.where(tmp126, tmp112, tmp110)
    tmp128 = tmp111 * tmp12
    tmp129 = tmp127 + tmp128
    tmp130 = tmp0 - tmp129
    tmp131 = triton_helpers.maximum(tmp130, tmp16)
    tmp132 = tmp1 - tmp129
    tmp133 = triton_helpers.maximum(tmp132, tmp16)
    tmp134 = tmp131 + tmp133
    tmp135 = tmp3 - tmp129
    tmp136 = triton_helpers.maximum(tmp135, tmp16)
    tmp137 = tmp134 + tmp136
    tmp138 = tmp5 - tmp129
    tmp139 = triton_helpers.maximum(tmp138, tmp16)
    tmp140 = tmp137 + tmp139
    tmp141 = tmp140 - tmp7
    tmp142 = tmp141 * tmp39
    tmp143 = tmp142 >= tmp16
    tmp144 = tl.where(tmp143, tmp129, tmp127)
    tmp145 = tmp128 * tmp12
    tmp146 = tmp144 + tmp145
    tmp147 = tmp0 - tmp146
    tmp148 = triton_helpers.maximum(tmp147, tmp16)
    tmp149 = tmp1 - tmp146
    tmp150 = triton_helpers.maximum(tmp149, tmp16)
    tmp151 = tmp148 + tmp150
    tmp152 = tmp3 - tmp146
    tmp153 = triton_helpers.maximum(tmp152, tmp16)
    tmp154 = tmp151 + tmp153
    tmp155 = tmp5 - tmp146
    tmp156 = triton_helpers.maximum(tmp155, tmp16)
    tmp157 = tmp154 + tmp156
    tmp158 = tmp157 - tmp7
    tmp159 = tmp158 * tmp39
    tmp160 = tmp159 >= tmp16
    tmp161 = tl.where(tmp160, tmp146, tmp144)
    tmp162 = tmp145 * tmp12
    tmp163 = tmp161 + tmp162
    tmp164 = tmp0 - tmp163
    tmp165 = triton_helpers.maximum(tmp164, tmp16)
    tmp166 = tmp1 - tmp163
    tmp167 = triton_helpers.maximum(tmp166, tmp16)
    tmp168 = tmp165 + tmp167
    tmp169 = tmp3 - tmp163
    tmp170 = triton_helpers.maximum(tmp169, tmp16)
    tmp171 = tmp168 + tmp170
    tmp172 = tmp5 - tmp163
    tmp173 = triton_helpers.maximum(tmp172, tmp16)
    tmp174 = tmp171 + tmp173
    tmp175 = tmp174 - tmp7
    tmp176 = tmp175 * tmp39
    tmp177 = tmp176 >= tmp16
    tmp178 = tl.where(tmp177, tmp163, tmp161)
    tmp179 = tmp162 * tmp12
    tmp180 = tmp178 + tmp179
    tmp181 = tmp0 - tmp180
    tmp182 = triton_helpers.maximum(tmp181, tmp16)
    tmp183 = tmp1 - tmp180
    tmp184 = triton_helpers.maximum(tmp183, tmp16)
    tmp185 = tmp182 + tmp184
    tmp186 = tmp3 - tmp180
    tmp187 = triton_helpers.maximum(tmp186, tmp16)
    tmp188 = tmp185 + tmp187
    tmp189 = tmp5 - tmp180
    tmp190 = triton_helpers.maximum(tmp189, tmp16)
    tmp191 = tmp188 + tmp190
    tmp192 = tmp191 - tmp7
    tmp193 = tmp192 * tmp39
    tmp194 = tmp193 >= tmp16
    tmp195 = tl.where(tmp194, tmp180, tmp178)
    tmp196 = tmp179 * tmp12
    tmp197 = tmp195 + tmp196
    tmp198 = tmp0 - tmp197
    tmp199 = triton_helpers.maximum(tmp198, tmp16)
    tmp200 = tmp1 - tmp197
    tmp201 = triton_helpers.maximum(tmp200, tmp16)
    tmp202 = tmp199 + tmp201
    tmp203 = tmp3 - tmp197
    tmp204 = triton_helpers.maximum(tmp203, tmp16)
    tmp205 = tmp202 + tmp204
    tmp206 = tmp5 - tmp197
    tmp207 = triton_helpers.maximum(tmp206, tmp16)
    tmp208 = tmp205 + tmp207
    tmp209 = tmp208 - tmp7
    tmp210 = tmp209 * tmp39
    tmp211 = tmp210 >= tmp16
    tmp212 = tl.where(tmp211, tmp197, tmp195)
    tmp213 = tmp196 * tmp12
    tmp214 = tmp212 + tmp213
    tmp215 = tmp0 - tmp214
    tmp216 = triton_helpers.maximum(tmp215, tmp16)
    tmp217 = tmp1 - tmp214
    tmp218 = triton_helpers.maximum(tmp217, tmp16)
    tmp219 = tmp216 + tmp218
    tmp220 = tmp3 - tmp214
    tmp221 = triton_helpers.maximum(tmp220, tmp16)
    tmp222 = tmp219 + tmp221
    tmp223 = tmp5 - tmp214
    tmp224 = triton_helpers.maximum(tmp223, tmp16)
    tmp225 = tmp222 + tmp224
    tmp226 = tmp225 - tmp7
    tmp227 = tmp226 * tmp39
    tmp228 = tmp227 >= tmp16
    tmp229 = tl.where(tmp228, tmp214, tmp212)
    tmp230 = tmp213 * tmp12
    tmp231 = tmp229 + tmp230
    tmp232 = tmp0 - tmp231
    tmp233 = triton_helpers.maximum(tmp232, tmp16)
    tmp234 = tmp1 - tmp231
    tmp235 = triton_helpers.maximum(tmp234, tmp16)
    tmp236 = tmp233 + tmp235
    tmp237 = tmp3 - tmp231
    tmp238 = triton_helpers.maximum(tmp237, tmp16)
    tmp239 = tmp236 + tmp238
    tmp240 = tmp5 - tmp231
    tmp241 = triton_helpers.maximum(tmp240, tmp16)
    tmp242 = tmp239 + tmp241
    tmp243 = tmp242 - tmp7
    tmp244 = tmp243 * tmp39
    tmp245 = tmp244 >= tmp16
    tmp246 = tl.where(tmp245, tmp231, tmp229)
    tmp247 = tmp230 * tmp12
    tmp248 = tmp246 + tmp247
    tmp249 = tmp0 - tmp248
    tmp250 = triton_helpers.maximum(tmp249, tmp16)
    tmp251 = tmp1 - tmp248
    tmp252 = triton_helpers.maximum(tmp251, tmp16)
    tmp253 = tmp250 + tmp252
    tmp254 = tmp3 - tmp248
    tmp255 = triton_helpers.maximum(tmp254, tmp16)
    tmp256 = tmp253 + tmp255
    tmp257 = tmp5 - tmp248
    tmp258 = triton_helpers.maximum(tmp257, tmp16)
    tmp259 = tmp256 + tmp258
    tmp260 = tmp259 - tmp7
    tmp261 = tmp260 * tmp39
    tmp262 = tmp261 >= tmp16
    tmp263 = tl.where(tmp262, tmp248, tmp246)
    tmp264 = tmp247 * tmp12
    tmp265 = tmp263 + tmp264
    tmp266 = tmp0 - tmp265
    tmp267 = triton_helpers.maximum(tmp266, tmp16)
    tmp268 = tmp1 - tmp265
    tmp269 = triton_helpers.maximum(tmp268, tmp16)
    tmp270 = tmp267 + tmp269
    tmp271 = tmp3 - tmp265
    tmp272 = triton_helpers.maximum(tmp271, tmp16)
    tmp273 = tmp270 + tmp272
    tmp274 = tmp5 - tmp265
    tmp275 = triton_helpers.maximum(tmp274, tmp16)
    tmp276 = tmp273 + tmp275
    tmp277 = tmp276 - tmp7
    tmp278 = tmp277 * tmp39
    tmp279 = tmp278 >= tmp16
    tmp280 = tl.where(tmp279, tmp265, tmp263)
    tmp281 = tmp264 * tmp12
    tmp282 = tmp280 + tmp281
    tmp283 = tmp0 - tmp282
    tmp284 = triton_helpers.maximum(tmp283, tmp16)
    tmp285 = tmp1 - tmp282
    tmp286 = triton_helpers.maximum(tmp285, tmp16)
    tmp287 = tmp284 + tmp286
    tmp288 = tmp3 - tmp282
    tmp289 = triton_helpers.maximum(tmp288, tmp16)
    tmp290 = tmp287 + tmp289
    tmp291 = tmp5 - tmp282
    tmp292 = triton_helpers.maximum(tmp291, tmp16)
    tmp293 = tmp290 + tmp292
    tmp294 = tmp293 - tmp7
    tmp295 = tmp294 * tmp39
    tmp296 = tmp295 >= tmp16
    tmp297 = tl.where(tmp296, tmp282, tmp280)
    tmp298 = tmp281 * tmp12
    tmp299 = tmp297 + tmp298
    tmp300 = tmp0 - tmp299
    tmp301 = triton_helpers.maximum(tmp300, tmp16)
    tmp302 = tmp1 - tmp299
    tmp303 = triton_helpers.maximum(tmp302, tmp16)
    tmp304 = tmp301 + tmp303
    tmp305 = tmp3 - tmp299
    tmp306 = triton_helpers.maximum(tmp305, tmp16)
    tmp307 = tmp304 + tmp306
    tmp308 = tmp5 - tmp299
    tmp309 = triton_helpers.maximum(tmp308, tmp16)
    tmp310 = tmp307 + tmp309
    tmp311 = tmp310 - tmp7
    tmp312 = tmp311 * tmp39
    tmp313 = tmp312 >= tmp16
    tmp314 = tl.where(tmp313, tmp299, tmp297)
    tl.store(in_out_ptr8 + x0, tmp314, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_1(in_out_ptr16,
    in_ptr0, in_ptr1, out_ptr0, 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 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp31 = tl.load(in_ptr1 + x0, xmask)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp7 = 0.25
    tmp8 = tmp6 - tmp7
    tmp9 = 1.0
    tmp10 = tmp6 - tmp9
    tmp11 = tmp8 - tmp10
    tmp12 = 0.5
    tmp13 = tmp11 * tmp12
    tmp14 = tmp13 * tmp12
    tmp15 = tmp14 * tmp12
    tmp16 = tmp15 * tmp12
    tmp17 = tmp16 * tmp12
    tmp18 = tmp17 * tmp12
    tmp19 = tmp18 * tmp12
    tmp20 = tmp19 * tmp12
    tmp21 = tmp20 * tmp12
    tmp22 = tmp21 * tmp12
    tmp23 = tmp22 * tmp12
    tmp24 = tmp23 * tmp12
    tmp25 = tmp24 * tmp12
    tmp26 = tmp25 * tmp12
    tmp27 = tmp26 * tmp12
    tmp28 = tmp27 * tmp12
    tmp29 = tmp28 * tmp12
    tmp30 = tmp29 * tmp12
    tmp32 = tmp31 + tmp30
    tmp33 = tmp0 - tmp32
    tmp34 = 0.0
    tmp35 = triton_helpers.maximum(tmp33, tmp34)
    tmp36 = tmp1 - tmp32
    tmp37 = triton_helpers.maximum(tmp36, tmp34)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp3 - tmp32
    tmp40 = triton_helpers.maximum(tmp39, tmp34)
    tmp41 = tmp38 + tmp40
    tmp42 = tmp5 - tmp32
    tmp43 = triton_helpers.maximum(tmp42, tmp34)
    tmp44 = tmp41 + tmp43
    tmp45 = tmp44 - tmp9
    tmp46 = tmp0 - tmp10
    tmp47 = triton_helpers.maximum(tmp46, tmp34)
    tmp48 = tmp1 - tmp10
    tmp49 = triton_helpers.maximum(tmp48, tmp34)
    tmp50 = tmp47 + tmp49
    tmp51 = tmp3 - tmp10
    tmp52 = triton_helpers.maximum(tmp51, tmp34)
    tmp53 = tmp50 + tmp52
    tmp54 = tmp5 - tmp10
    tmp55 = triton_helpers.maximum(tmp54, tmp34)
    tmp56 = tmp53 + tmp55
    tmp57 = tmp56 - tmp9
    tmp58 = tmp45 * tmp57
    tmp59 = tmp58 >= tmp34
    tmp60 = tl.where(tmp59, tmp32, tmp31)
    tmp61 = tmp30 * tmp12
    tmp62 = tmp60 + tmp61
    tmp63 = tmp0 - tmp62
    tmp64 = triton_helpers.maximum(tmp63, tmp34)
    tmp65 = tmp1 - tmp62
    tmp66 = triton_helpers.maximum(tmp65, tmp34)
    tmp67 = tmp64 + tmp66
    tmp68 = tmp3 - tmp62
    tmp69 = triton_helpers.maximum(tmp68, tmp34)
    tmp70 = tmp67 + tmp69
    tmp71 = tmp5 - tmp62
    tmp72 = triton_helpers.maximum(tmp71, tmp34)
    tmp73 = tmp70 + tmp72
    tmp74 = tmp73 - tmp9
    tmp75 = tmp74 * tmp57
    tmp76 = tmp75 >= tmp34
    tmp77 = tl.where(tmp76, tmp62, tmp60)
    tmp78 = tmp61 * tmp12
    tmp79 = tmp77 + tmp78
    tmp80 = tmp0 - tmp79
    tmp81 = triton_helpers.maximum(tmp80, tmp34)
    tmp82 = tmp1 - tmp79
    tmp83 = triton_helpers.maximum(tmp82, tmp34)
    tmp84 = tmp81 + tmp83
    tmp85 = tmp3 - tmp79
    tmp86 = triton_helpers.maximum(tmp85, tmp34)
    tmp87 = tmp84 + tmp86
    tmp88 = tmp5 - tmp79
    tmp89 = triton_helpers.maximum(tmp88, tmp34)
    tmp90 = tmp87 + tmp89
    tmp91 = tmp90 - tmp9
    tmp92 = tmp91 * tmp57
    tmp93 = tmp92 >= tmp34
    tmp94 = tl.where(tmp93, tmp79, tmp77)
    tmp95 = tmp78 * tmp12
    tmp96 = tmp94 + tmp95
    tmp97 = tmp0 - tmp96
    tmp98 = triton_helpers.maximum(tmp97, tmp34)
    tmp99 = tmp1 - tmp96
    tmp100 = triton_helpers.maximum(tmp99, tmp34)
    tmp101 = tmp98 + tmp100
    tmp102 = tmp3 - tmp96
    tmp103 = triton_helpers.maximum(tmp102, tmp34)
    tmp104 = tmp101 + tmp103
    tmp105 = tmp5 - tmp96
    tmp106 = triton_helpers.maximum(tmp105, tmp34)
    tmp107 = tmp104 + tmp106
    tmp108 = tmp107 - tmp9
    tmp109 = tmp108 * tmp57
    tmp110 = tmp109 >= tmp34
    tmp111 = tl.where(tmp110, tmp96, tmp94)
    tmp112 = tmp95 * tmp12
    tmp113 = tmp111 + tmp112
    tmp114 = tmp0 - tmp113
    tmp115 = triton_helpers.maximum(tmp114, tmp34)
    tmp116 = tmp1 - tmp113
    tmp117 = triton_helpers.maximum(tmp116, tmp34)
    tmp118 = tmp115 + tmp117
    tmp119 = tmp3 - tmp113
    tmp120 = triton_helpers.maximum(tmp119, tmp34)
    tmp121 = tmp118 + tmp120
    tmp122 = tmp5 - tmp113
    tmp123 = triton_helpers.maximum(tmp122, tmp34)
    tmp124 = tmp121 + tmp123
    tmp125 = tmp124 - tmp9
    tmp126 = tmp125 * tmp57
    tmp127 = tmp126 >= tmp34
    tmp128 = tl.where(tmp127, tmp113, tmp111)
    tmp129 = tmp112 * tmp12
    tmp130 = tmp128 + tmp129
    tmp131 = tmp0 - tmp130
    tmp132 = triton_helpers.maximum(tmp131, tmp34)
    tmp133 = tmp1 - tmp130
    tmp134 = triton_helpers.maximum(tmp133, tmp34)
    tmp135 = tmp132 + tmp134
    tmp136 = tmp3 - tmp130
    tmp137 = triton_helpers.maximum(tmp136, tmp34)
    tmp138 = tmp135 + tmp137
    tmp139 = tmp5 - tmp130
    tmp140 = triton_helpers.maximum(tmp139, tmp34)
    tmp141 = tmp138 + tmp140
    tmp142 = tmp141 - tmp9
    tmp143 = tmp142 * tmp57
    tmp144 = tmp143 >= tmp34
    tmp145 = tl.where(tmp144, tmp130, tmp128)
    tmp146 = tmp129 * tmp12
    tmp147 = tmp145 + tmp146
    tmp148 = tmp0 - tmp147
    tmp149 = triton_helpers.maximum(tmp148, tmp34)
    tmp150 = tmp1 - tmp147
    tmp151 = triton_helpers.maximum(tmp150, tmp34)
    tmp152 = tmp149 + tmp151
    tmp153 = tmp3 - tmp147
    tmp154 = triton_helpers.maximum(tmp153, tmp34)
    tmp155 = tmp152 + tmp154
    tmp156 = tmp5 - tmp147
    tmp157 = triton_helpers.maximum(tmp156, tmp34)
    tmp158 = tmp155 + tmp157
    tmp159 = tmp158 - tmp9
    tmp160 = tmp159 * tmp57
    tmp161 = tmp160 >= tmp34
    tmp162 = tl.where(tmp161, tmp147, tmp145)
    tmp163 = tmp146 * tmp12
    tmp164 = tmp162 + tmp163
    tmp165 = tmp0 - tmp164
    tmp166 = triton_helpers.maximum(tmp165, tmp34)
    tmp167 = tmp1 - tmp164
    tmp168 = triton_helpers.maximum(tmp167, tmp34)
    tmp169 = tmp166 + tmp168
    tmp170 = tmp3 - tmp164
    tmp171 = triton_helpers.maximum(tmp170, tmp34)
    tmp172 = tmp169 + tmp171
    tmp173 = tmp5 - tmp164
    tmp174 = triton_helpers.maximum(tmp173, tmp34)
    tmp175 = tmp172 + tmp174
    tmp176 = tmp175 - tmp9
    tmp177 = tmp176 * tmp57
    tmp178 = tmp177 >= tmp34
    tmp179 = tl.where(tmp178, tmp164, tmp162)
    tmp180 = tmp163 * tmp12
    tmp181 = tmp179 + tmp180
    tmp182 = tmp0 - tmp181
    tmp183 = triton_helpers.maximum(tmp182, tmp34)
    tmp184 = tmp1 - tmp181
    tmp185 = triton_helpers.maximum(tmp184, tmp34)
    tmp186 = tmp183 + tmp185
    tmp187 = tmp3 - tmp181
    tmp188 = triton_helpers.maximum(tmp187, tmp34)
    tmp189 = tmp186 + tmp188
    tmp190 = tmp5 - tmp181
    tmp191 = triton_helpers.maximum(tmp190, tmp34)
    tmp192 = tmp189 + tmp191
    tmp193 = tmp192 - tmp9
    tmp194 = tmp193 * tmp57
    tmp195 = tmp194 >= tmp34
    tmp196 = tl.where(tmp195, tmp181, tmp179)
    tmp197 = tmp180 * tmp12
    tmp198 = tmp196 + tmp197
    tmp199 = tmp0 - tmp198
    tmp200 = triton_helpers.maximum(tmp199, tmp34)
    tmp201 = tmp1 - tmp198
    tmp202 = triton_helpers.maximum(tmp201, tmp34)
    tmp203 = tmp200 + tmp202
    tmp204 = tmp3 - tmp198
    tmp205 = triton_helpers.maximum(tmp204, tmp34)
    tmp206 = tmp203 + tmp205
    tmp207 = tmp5 - tmp198
    tmp208 = triton_helpers.maximum(tmp207, tmp34)
    tmp209 = tmp206 + tmp208
    tmp210 = tmp209 - tmp9
    tmp211 = tmp210 * tmp57
    tmp212 = tmp211 >= tmp34
    tmp213 = tl.where(tmp212, tmp198, tmp196)
    tmp214 = tmp197 * tmp12
    tmp215 = tmp213 + tmp214
    tmp216 = tmp0 - tmp215
    tmp217 = triton_helpers.maximum(tmp216, tmp34)
    tmp218 = tmp1 - tmp215
    tmp219 = triton_helpers.maximum(tmp218, tmp34)
    tmp220 = tmp217 + tmp219
    tmp221 = tmp3 - tmp215
    tmp222 = triton_helpers.maximum(tmp221, tmp34)
    tmp223 = tmp220 + tmp222
    tmp224 = tmp5 - tmp215
    tmp225 = triton_helpers.maximum(tmp224, tmp34)
    tmp226 = tmp223 + tmp225
    tmp227 = tmp226 - tmp9
    tmp228 = tmp227 * tmp57
    tmp229 = tmp228 >= tmp34
    tmp230 = tl.where(tmp229, tmp215, tmp213)
    tmp231 = tmp214 * tmp12
    tmp232 = tmp230 + tmp231
    tmp233 = tmp0 - tmp232
    tmp234 = triton_helpers.maximum(tmp233, tmp34)
    tmp235 = tmp1 - tmp232
    tmp236 = triton_helpers.maximum(tmp235, tmp34)
    tmp237 = tmp234 + tmp236
    tmp238 = tmp3 - tmp232
    tmp239 = triton_helpers.maximum(tmp238, tmp34)
    tmp240 = tmp237 + tmp239
    tmp241 = tmp5 - tmp232
    tmp242 = triton_helpers.maximum(tmp241, tmp34)
    tmp243 = tmp240 + tmp242
    tmp244 = tmp243 - tmp9
    tmp245 = tmp244 * tmp57
    tmp246 = tmp245 >= tmp34
    tmp247 = tl.where(tmp246, tmp232, tmp230)
    tmp248 = tmp231 * tmp12
    tmp249 = tmp247 + tmp248
    tmp250 = tmp0 - tmp249
    tmp251 = triton_helpers.maximum(tmp250, tmp34)
    tmp252 = tmp1 - tmp249
    tmp253 = triton_helpers.maximum(tmp252, tmp34)
    tmp254 = tmp251 + tmp253
    tmp255 = tmp3 - tmp249
    tmp256 = triton_helpers.maximum(tmp255, tmp34)
    tmp257 = tmp254 + tmp256
    tmp258 = tmp5 - tmp249
    tmp259 = triton_helpers.maximum(tmp258, tmp34)
    tmp260 = tmp257 + tmp259
    tmp261 = tmp260 - tmp9
    tmp262 = tmp261 * tmp57
    tmp263 = tmp262 >= tmp34
    tmp264 = tl.where(tmp263, tmp249, tmp247)
    tmp265 = tmp248 * tmp12
    tmp266 = tmp264 + tmp265
    tmp267 = tmp0 - tmp266
    tmp268 = triton_helpers.maximum(tmp267, tmp34)
    tmp269 = tmp1 - tmp266
    tmp270 = triton_helpers.maximum(tmp269, tmp34)
    tmp271 = tmp268 + tmp270
    tmp272 = tmp3 - tmp266
    tmp273 = triton_helpers.maximum(tmp272, tmp34)
    tmp274 = tmp271 + tmp273
    tmp275 = tmp5 - tmp266
    tmp276 = triton_helpers.maximum(tmp275, tmp34)
    tmp277 = tmp274 + tmp276
    tmp278 = tmp277 - tmp9
    tmp279 = tmp278 * tmp57
    tmp280 = tmp279 >= tmp34
    tmp281 = tl.where(tmp280, tmp266, tmp264)
    tmp282 = tmp265 * tmp12
    tmp283 = tmp281 + tmp282
    tmp284 = tmp0 - tmp283
    tmp285 = triton_helpers.maximum(tmp284, tmp34)
    tmp286 = tmp1 - tmp283
    tmp287 = triton_helpers.maximum(tmp286, tmp34)
    tmp288 = tmp285 + tmp287
    tmp289 = tmp3 - tmp283
    tmp290 = triton_helpers.maximum(tmp289, tmp34)
    tmp291 = tmp288 + tmp290
    tmp292 = tmp5 - tmp283
    tmp293 = triton_helpers.maximum(tmp292, tmp34)
    tmp294 = tmp291 + tmp293
    tmp295 = tmp294 - tmp9
    tmp296 = tmp295 * tmp57
    tmp297 = tmp296 >= tmp34
    tmp298 = tl.where(tmp297, tmp283, tmp281)
    tmp299 = tmp282 * tmp12
    tmp300 = tmp298 + tmp299
    tmp301 = tmp0 - tmp300
    tmp302 = triton_helpers.maximum(tmp301, tmp34)
    tmp303 = tmp1 - tmp300
    tmp304 = triton_helpers.maximum(tmp303, tmp34)
    tmp305 = tmp302 + tmp304
    tmp306 = tmp3 - tmp300
    tmp307 = triton_helpers.maximum(tmp306, tmp34)
    tmp308 = tmp305 + tmp307
    tmp309 = tmp5 - tmp300
    tmp310 = triton_helpers.maximum(tmp309, tmp34)
    tmp311 = tmp308 + tmp310
    tmp312 = tmp311 - tmp9
    tmp313 = tmp312 * tmp57
    tmp314 = tmp313 >= tmp34
    tmp315 = tl.where(tmp314, tmp300, tmp298)
    tmp316 = tmp299 * tmp12
    tmp317 = tmp315 + tmp316
    tmp318 = tmp0 - tmp317
    tmp319 = triton_helpers.maximum(tmp318, tmp34)
    tmp320 = tmp1 - tmp317
    tmp321 = triton_helpers.maximum(tmp320, tmp34)
    tmp322 = tmp319 + tmp321
    tmp323 = tmp3 - tmp317
    tmp324 = triton_helpers.maximum(tmp323, tmp34)
    tmp325 = tmp322 + tmp324
    tmp326 = tmp5 - tmp317
    tmp327 = triton_helpers.maximum(tmp326, tmp34)
    tmp328 = tmp325 + tmp327
    tmp329 = tmp328 - tmp9
    tmp330 = tmp329 * tmp57
    tmp331 = tmp330 >= tmp34
    tmp332 = tl.where(tmp331, tmp317, tmp315)
    tmp333 = tmp316 * tmp12
    tmp334 = tmp332 + tmp333
    tmp335 = tmp0 - tmp334
    tmp336 = triton_helpers.maximum(tmp335, tmp34)
    tmp337 = tmp1 - tmp334
    tmp338 = triton_helpers.maximum(tmp337, tmp34)
    tmp339 = tmp336 + tmp338
    tmp340 = tmp3 - tmp334
    tmp341 = triton_helpers.maximum(tmp340, tmp34)
    tmp342 = tmp339 + tmp341
    tmp343 = tmp5 - tmp334
    tmp344 = triton_helpers.maximum(tmp343, tmp34)
    tmp345 = tmp342 + tmp344
    tmp346 = tmp345 - tmp9
    tmp347 = tmp346 * tmp57
    tmp348 = tmp347 >= tmp34
    tmp349 = tl.where(tmp348, tmp334, tmp332)
    tmp350 = tmp333 * tmp12
    tmp351 = tmp349 + tmp350
    tmp352 = tmp0 - tmp351
    tmp353 = triton_helpers.maximum(tmp352, tmp34)
    tmp354 = tmp1 - tmp351
    tmp355 = triton_helpers.maximum(tmp354, tmp34)
    tmp356 = tmp353 + tmp355
    tmp357 = tmp3 - tmp351
    tmp358 = triton_helpers.maximum(tmp357, tmp34)
    tmp359 = tmp356 + tmp358
    tmp360 = tmp5 - tmp351
    tmp361 = triton_helpers.maximum(tmp360, tmp34)
    tmp362 = tmp359 + tmp361
    tmp363 = tmp362 - tmp9
    tmp364 = tmp363 * tmp57
    tmp365 = tmp364 >= tmp34
    tmp366 = tl.where(tmp365, tmp351, tmp349)
    tmp367 = tmp350 * tmp12
    tmp368 = tmp366 + tmp367
    tmp369 = tmp0 - tmp368
    tmp370 = triton_helpers.maximum(tmp369, tmp34)
    tmp371 = tmp1 - tmp368
    tmp372 = triton_helpers.maximum(tmp371, tmp34)
    tmp373 = tmp370 + tmp372
    tmp374 = tmp3 - tmp368
    tmp375 = triton_helpers.maximum(tmp374, tmp34)
    tmp376 = tmp373 + tmp375
    tmp377 = tmp5 - tmp368
    tmp378 = triton_helpers.maximum(tmp377, tmp34)
    tmp379 = tmp376 + tmp378
    tmp380 = tmp379 - tmp9
    tmp381 = tmp380 * tmp57
    tmp382 = tmp381 >= tmp34
    tmp383 = tl.where(tmp382, tmp368, tmp366)
    tmp384 = tmp367 * tmp12
    tmp385 = tmp383 + tmp384
    tmp386 = tmp0 - tmp385
    tmp387 = triton_helpers.maximum(tmp386, tmp34)
    tmp388 = tmp1 - tmp385
    tmp389 = triton_helpers.maximum(tmp388, tmp34)
    tmp390 = tmp387 + tmp389
    tmp391 = tmp3 - tmp385
    tmp392 = triton_helpers.maximum(tmp391, tmp34)
    tmp393 = tmp390 + tmp392
    tmp394 = tmp5 - tmp385
    tmp395 = triton_helpers.maximum(tmp394, tmp34)
    tmp396 = tmp393 + tmp395
    tmp397 = tmp396 - tmp9
    tmp398 = tmp397 * tmp57
    tmp399 = tmp398 >= tmp34
    tmp400 = tl.where(tmp399, tmp385, tmp383)
    tmp401 = tmp384 * tmp12
    tmp402 = tmp400 + tmp401
    tmp403 = tmp0 - tmp402
    tmp404 = triton_helpers.maximum(tmp403, tmp34)
    tmp405 = tmp1 - tmp402
    tmp406 = triton_helpers.maximum(tmp405, tmp34)
    tmp407 = tmp404 + tmp406
    tmp408 = tmp3 - tmp402
    tmp409 = triton_helpers.maximum(tmp408, tmp34)
    tmp410 = tmp407 + tmp409
    tmp411 = tmp5 - tmp402
    tmp412 = triton_helpers.maximum(tmp411, tmp34)
    tmp413 = tmp410 + tmp412
    tmp414 = tmp413 - tmp9
    tmp415 = tmp414 * tmp57
    tmp416 = tmp415 >= tmp34
    tmp417 = tl.where(tmp416, tmp402, tmp400)
    tmp418 = tmp401 * tmp12
    tmp419 = tmp417 + tmp418
    tmp420 = tmp0 - tmp419
    tmp421 = triton_helpers.maximum(tmp420, tmp34)
    tmp422 = tmp1 - tmp419
    tmp423 = triton_helpers.maximum(tmp422, tmp34)
    tmp424 = tmp421 + tmp423
    tmp425 = tmp3 - tmp419
    tmp426 = triton_helpers.maximum(tmp425, tmp34)
    tmp427 = tmp424 + tmp426
    tmp428 = tmp5 - tmp419
    tmp429 = triton_helpers.maximum(tmp428, tmp34)
    tmp430 = tmp427 + tmp429
    tmp431 = tmp430 - tmp9
    tmp432 = tmp431 * tmp57
    tmp433 = tmp432 >= tmp34
    tmp434 = tl.where(tmp433, tmp419, tmp417)
    tl.store(out_ptr0 + x0, tmp30, xmask)
    tl.store(in_out_ptr16 + x0, tmp434, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_sub_2(in_ptr0, in_ptr1, in_ptr2,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 0.5
    tmp4 = tmp2 * tmp3
    tmp5 = tmp4 * tmp3
    tmp6 = tmp5 * tmp3
    tmp7 = tmp6 * tmp3
    tmp8 = tmp7 * tmp3
    tmp9 = tmp8 * tmp3
    tmp10 = tmp9 * tmp3
    tmp11 = tmp10 * tmp3
    tmp12 = tmp11 * tmp3
    tmp13 = tmp12 * tmp3
    tmp14 = tmp13 * tmp3
    tmp15 = tmp14 * tmp3
    tmp16 = tmp15 * tmp3
    tmp17 = tmp16 * tmp3
    tmp18 = tmp17 * tmp3
    tmp19 = tmp18 * tmp3
    tmp20 = tmp19 * tmp3
    tmp21 = tmp20 * tmp3
    tmp22 = tmp21 * tmp3
    tmp23 = tmp22 * tmp3
    tmp24 = tmp23 * tmp3
    tmp25 = tmp24 * tmp3
    tmp26 = tmp25 * tmp3
    tmp27 = tmp1 + tmp26
    tmp28 = tmp0 - tmp27
    tmp29 = 0.0
    tmp30 = triton_helpers.maximum(tmp28, tmp29)
    tl.store(out_ptr0 + x2, tmp30, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_3(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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp32 = tl.load(in_out_ptr0 + x0, xmask)
    tmp33 = tl.load(in_ptr2 + x0, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 1.0
    tmp8 = tmp6 - tmp7
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp15 = triton_helpers.maximum(tmp13, tmp14)
    tmp16 = tmp15 - tmp7
    tmp17 = tmp9 - tmp16
    tmp18 = 0.0
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp20 = tmp10 - tmp16
    tmp21 = triton_helpers.maximum(tmp20, tmp18)
    tmp22 = tmp19 + tmp21
    tmp23 = tmp12 - tmp16
    tmp24 = triton_helpers.maximum(tmp23, tmp18)
    tmp25 = tmp22 + tmp24
    tmp26 = tmp14 - tmp16
    tmp27 = triton_helpers.maximum(tmp26, tmp18)
    tmp28 = tmp25 + tmp27
    tmp29 = tmp28 - tmp7
    tmp30 = tmp8 * tmp29
    tmp31 = tmp30 >= tmp18
    tmp34 = 0.5
    tmp35 = tmp33 * tmp34
    tmp36 = tmp35 * tmp34
    tmp37 = tmp36 * tmp34
    tmp38 = tmp37 * tmp34
    tmp39 = tmp38 * tmp34
    tmp40 = tmp39 * tmp34
    tmp41 = tmp40 * tmp34
    tmp42 = tmp41 * tmp34
    tmp43 = tmp42 * tmp34
    tmp44 = tmp43 * tmp34
    tmp45 = tmp44 * tmp34
    tmp46 = tmp45 * tmp34
    tmp47 = tmp46 * tmp34
    tmp48 = tmp47 * tmp34
    tmp49 = tmp48 * tmp34
    tmp50 = tmp49 * tmp34
    tmp51 = tmp50 * tmp34
    tmp52 = tmp51 * tmp34
    tmp53 = tmp52 * tmp34
    tmp54 = tmp53 * tmp34
    tmp55 = tmp54 * tmp34
    tmp56 = tmp55 * tmp34
    tmp57 = tmp56 * tmp34
    tmp58 = tmp32 + tmp57
    tmp59 = tl.where(tmp31, tmp58, tmp32)
    tl.store(in_out_ptr0 + x0, tmp59, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_sub_4(in_ptr0, in_ptr1, in_ptr2,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 0.5
    tmp4 = tmp2 * tmp3
    tmp5 = tmp4 * tmp3
    tmp6 = tmp5 * tmp3
    tmp7 = tmp6 * tmp3
    tmp8 = tmp7 * tmp3
    tmp9 = tmp8 * tmp3
    tmp10 = tmp9 * tmp3
    tmp11 = tmp10 * tmp3
    tmp12 = tmp11 * tmp3
    tmp13 = tmp12 * tmp3
    tmp14 = tmp13 * tmp3
    tmp15 = tmp14 * tmp3
    tmp16 = tmp15 * tmp3
    tmp17 = tmp16 * tmp3
    tmp18 = tmp17 * tmp3
    tmp19 = tmp18 * tmp3
    tmp20 = tmp19 * tmp3
    tmp21 = tmp20 * tmp3
    tmp22 = tmp21 * tmp3
    tmp23 = tmp22 * tmp3
    tmp24 = tmp23 * tmp3
    tmp25 = tmp24 * tmp3
    tmp26 = tmp25 * tmp3
    tmp27 = tmp26 * tmp3
    tmp28 = tmp1 + tmp27
    tmp29 = tmp0 - tmp28
    tmp30 = 0.0
    tmp31 = triton_helpers.maximum(tmp29, tmp30)
    tl.store(out_ptr0 + x2, tmp31, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_5(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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp32 = tl.load(in_out_ptr0 + x0, xmask)
    tmp33 = tl.load(in_ptr2 + x0, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 1.0
    tmp8 = tmp6 - tmp7
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp15 = triton_helpers.maximum(tmp13, tmp14)
    tmp16 = tmp15 - tmp7
    tmp17 = tmp9 - tmp16
    tmp18 = 0.0
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp20 = tmp10 - tmp16
    tmp21 = triton_helpers.maximum(tmp20, tmp18)
    tmp22 = tmp19 + tmp21
    tmp23 = tmp12 - tmp16
    tmp24 = triton_helpers.maximum(tmp23, tmp18)
    tmp25 = tmp22 + tmp24
    tmp26 = tmp14 - tmp16
    tmp27 = triton_helpers.maximum(tmp26, tmp18)
    tmp28 = tmp25 + tmp27
    tmp29 = tmp28 - tmp7
    tmp30 = tmp8 * tmp29
    tmp31 = tmp30 >= tmp18
    tmp34 = 0.5
    tmp35 = tmp33 * tmp34
    tmp36 = tmp35 * tmp34
    tmp37 = tmp36 * tmp34
    tmp38 = tmp37 * tmp34
    tmp39 = tmp38 * tmp34
    tmp40 = tmp39 * tmp34
    tmp41 = tmp40 * tmp34
    tmp42 = tmp41 * tmp34
    tmp43 = tmp42 * tmp34
    tmp44 = tmp43 * tmp34
    tmp45 = tmp44 * tmp34
    tmp46 = tmp45 * tmp34
    tmp47 = tmp46 * tmp34
    tmp48 = tmp47 * tmp34
    tmp49 = tmp48 * tmp34
    tmp50 = tmp49 * tmp34
    tmp51 = tmp50 * tmp34
    tmp52 = tmp51 * tmp34
    tmp53 = tmp52 * tmp34
    tmp54 = tmp53 * tmp34
    tmp55 = tmp54 * tmp34
    tmp56 = tmp55 * tmp34
    tmp57 = tmp56 * tmp34
    tmp58 = tmp57 * tmp34
    tmp59 = tmp32 + tmp58
    tmp60 = tl.where(tmp31, tmp59, tmp32)
    tl.store(in_out_ptr0 + x0, tmp60, xmask)


@triton.jit
def triton_poi_fused_add_div_sub_6(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 0.5
    tmp4 = tmp2 * tmp3
    tmp5 = tmp4 * tmp3
    tmp6 = tmp5 * tmp3
    tmp7 = tmp6 * tmp3
    tmp8 = tmp7 * tmp3
    tmp9 = tmp8 * tmp3
    tmp10 = tmp9 * tmp3
    tmp11 = tmp10 * tmp3
    tmp12 = tmp11 * tmp3
    tmp13 = tmp12 * tmp3
    tmp14 = tmp13 * tmp3
    tmp15 = tmp14 * tmp3
    tmp16 = tmp15 * tmp3
    tmp17 = tmp16 * tmp3
    tmp18 = tmp17 * tmp3
    tmp19 = tmp18 * tmp3
    tmp20 = tmp19 * tmp3
    tmp21 = tmp20 * tmp3
    tmp22 = tmp21 * tmp3
    tmp23 = tmp22 * tmp3
    tmp24 = tmp23 * tmp3
    tmp25 = tmp24 * tmp3
    tmp26 = tmp25 * tmp3
    tmp27 = tmp26 * tmp3
    tmp28 = tmp27 * tmp3
    tmp29 = tmp1 + tmp28
    tmp30 = tmp0 - tmp29
    tl.store(out_ptr0 + x2, tmp30, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_7(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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp36 = tl.load(in_out_ptr0 + x0, xmask)
    tmp37 = tl.load(in_ptr2 + x0, xmask)
    tmp1 = 0.0
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp3, tmp1)
    tmp5 = tmp2 + tmp4
    tmp7 = triton_helpers.maximum(tmp6, tmp1)
    tmp8 = tmp5 + tmp7
    tmp10 = triton_helpers.maximum(tmp9, tmp1)
    tmp11 = tmp8 + tmp10
    tmp12 = 1.0
    tmp13 = tmp11 - tmp12
    tmp16 = triton_helpers.maximum(tmp14, tmp15)
    tmp18 = triton_helpers.maximum(tmp16, tmp17)
    tmp20 = triton_helpers.maximum(tmp18, tmp19)
    tmp21 = tmp20 - tmp12
    tmp22 = tmp14 - tmp21
    tmp23 = triton_helpers.maximum(tmp22, tmp1)
    tmp24 = tmp15 - tmp21
    tmp25 = triton_helpers.maximum(tmp24, tmp1)
    tmp26 = tmp23 + tmp25
    tmp27 = tmp17 - tmp21
    tmp28 = triton_helpers.maximum(tmp27, tmp1)
    tmp29 = tmp26 + tmp28
    tmp30 = tmp19 - tmp21
    tmp31 = triton_helpers.maximum(tmp30, tmp1)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp32 - tmp12
    tmp34 = tmp13 * tmp33
    tmp35 = tmp34 >= tmp1
    tmp38 = 0.5
    tmp39 = tmp37 * tmp38
    tmp40 = tmp39 * tmp38
    tmp41 = tmp40 * tmp38
    tmp42 = tmp41 * tmp38
    tmp43 = tmp42 * tmp38
    tmp44 = tmp43 * tmp38
    tmp45 = tmp44 * tmp38
    tmp46 = tmp45 * tmp38
    tmp47 = tmp46 * tmp38
    tmp48 = tmp47 * tmp38
    tmp49 = tmp48 * tmp38
    tmp50 = tmp49 * tmp38
    tmp51 = tmp50 * tmp38
    tmp52 = tmp51 * tmp38
    tmp53 = tmp52 * tmp38
    tmp54 = tmp53 * tmp38
    tmp55 = tmp54 * tmp38
    tmp56 = tmp55 * tmp38
    tmp57 = tmp56 * tmp38
    tmp58 = tmp57 * tmp38
    tmp59 = tmp58 * tmp38
    tmp60 = tmp59 * tmp38
    tmp61 = tmp60 * tmp38
    tmp62 = tmp61 * tmp38
    tmp63 = tmp62 * tmp38
    tmp64 = tmp36 + tmp63
    tmp65 = tl.where(tmp35, tmp64, tmp36)
    tl.store(in_out_ptr0 + x0, tmp65, xmask)


@triton.jit
def triton_poi_fused_add_div_sub_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 0.5
    tmp4 = tmp2 * tmp3
    tmp5 = tmp4 * tmp3
    tmp6 = tmp5 * tmp3
    tmp7 = tmp6 * tmp3
    tmp8 = tmp7 * tmp3
    tmp9 = tmp8 * tmp3
    tmp10 = tmp9 * tmp3
    tmp11 = tmp10 * tmp3
    tmp12 = tmp11 * tmp3
    tmp13 = tmp12 * tmp3
    tmp14 = tmp13 * tmp3
    tmp15 = tmp14 * tmp3
    tmp16 = tmp15 * tmp3
    tmp17 = tmp16 * tmp3
    tmp18 = tmp17 * tmp3
    tmp19 = tmp18 * tmp3
    tmp20 = tmp19 * tmp3
    tmp21 = tmp20 * tmp3
    tmp22 = tmp21 * tmp3
    tmp23 = tmp22 * tmp3
    tmp24 = tmp23 * tmp3
    tmp25 = tmp24 * tmp3
    tmp26 = tmp25 * tmp3
    tmp27 = tmp26 * tmp3
    tmp28 = tmp27 * tmp3
    tmp29 = tmp28 * tmp3
    tmp30 = tmp1 + tmp29
    tmp31 = tmp0 - tmp30
    tl.store(out_ptr0 + x2, tmp31, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_9(in_out_ptr0,
    in_out_ptr2, in_ptr0, in_ptr1, in_ptr2, out_ptr4, out_ptr7, 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 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp36 = tl.load(in_out_ptr0 + x0, xmask)
    tmp37 = tl.load(in_ptr2 + x0, xmask)
    tmp1 = 0.0
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp3, tmp1)
    tmp5 = tmp2 + tmp4
    tmp7 = triton_helpers.maximum(tmp6, tmp1)
    tmp8 = tmp5 + tmp7
    tmp10 = triton_helpers.maximum(tmp9, tmp1)
    tmp11 = tmp8 + tmp10
    tmp12 = 1.0
    tmp13 = tmp11 - tmp12
    tmp16 = triton_helpers.maximum(tmp14, tmp15)
    tmp18 = triton_helpers.maximum(tmp16, tmp17)
    tmp20 = triton_helpers.maximum(tmp18, tmp19)
    tmp21 = tmp20 - tmp12
    tmp22 = tmp14 - tmp21
    tmp23 = triton_helpers.maximum(tmp22, tmp1)
    tmp24 = tmp15 - tmp21
    tmp25 = triton_helpers.maximum(tmp24, tmp1)
    tmp26 = tmp23 + tmp25
    tmp27 = tmp17 - tmp21
    tmp28 = triton_helpers.maximum(tmp27, tmp1)
    tmp29 = tmp26 + tmp28
    tmp30 = tmp19 - tmp21
    tmp31 = triton_helpers.maximum(tmp30, tmp1)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp32 - tmp12
    tmp34 = tmp13 * tmp33
    tmp35 = tmp34 >= tmp1
    tmp38 = 0.5
    tmp39 = tmp37 * tmp38
    tmp40 = tmp39 * tmp38
    tmp41 = tmp40 * tmp38
    tmp42 = tmp41 * tmp38
    tmp43 = tmp42 * tmp38
    tmp44 = tmp43 * tmp38
    tmp45 = tmp44 * tmp38
    tmp46 = tmp45 * tmp38
    tmp47 = tmp46 * tmp38
    tmp48 = tmp47 * tmp38
    tmp49 = tmp48 * tmp38
    tmp50 = tmp49 * tmp38
    tmp51 = tmp50 * tmp38
    tmp52 = tmp51 * tmp38
    tmp53 = tmp52 * tmp38
    tmp54 = tmp53 * tmp38
    tmp55 = tmp54 * tmp38
    tmp56 = tmp55 * tmp38
    tmp57 = tmp56 * tmp38
    tmp58 = tmp57 * tmp38
    tmp59 = tmp58 * tmp38
    tmp60 = tmp59 * tmp38
    tmp61 = tmp60 * tmp38
    tmp62 = tmp61 * tmp38
    tmp63 = tmp62 * tmp38
    tmp64 = tmp63 * tmp38
    tmp65 = tmp36 + tmp64
    tmp66 = tl.where(tmp35, tmp65, tmp36)
    tmp67 = tmp64 * tmp38
    tmp68 = tmp66 + tmp67
    tmp69 = tmp14 - tmp68
    tmp70 = triton_helpers.maximum(tmp69, tmp1)
    tmp71 = tmp15 - tmp68
    tmp72 = triton_helpers.maximum(tmp71, tmp1)
    tmp73 = tmp70 + tmp72
    tmp74 = tmp17 - tmp68
    tmp75 = triton_helpers.maximum(tmp74, tmp1)
    tmp76 = tmp73 + tmp75
    tmp77 = tmp19 - tmp68
    tmp78 = triton_helpers.maximum(tmp77, tmp1)
    tmp79 = tmp76 + tmp78
    tmp80 = tmp79 - tmp12
    tmp81 = tmp80 * tmp33
    tmp82 = tmp81 >= tmp1
    tmp83 = tl.where(tmp82, tmp68, tmp66)
    tmp84 = tmp67 * tmp38
    tmp85 = tmp83 + tmp84
    tmp86 = tmp14 - tmp85
    tmp87 = triton_helpers.maximum(tmp86, tmp1)
    tmp88 = tmp15 - tmp85
    tmp89 = triton_helpers.maximum(tmp88, tmp1)
    tmp90 = tmp87 + tmp89
    tmp91 = tmp17 - tmp85
    tmp92 = triton_helpers.maximum(tmp91, tmp1)
    tmp93 = tmp90 + tmp92
    tmp94 = tmp19 - tmp85
    tmp95 = triton_helpers.maximum(tmp94, tmp1)
    tmp96 = tmp93 + tmp95
    tmp97 = tmp96 - tmp12
    tmp98 = tmp97 * tmp33
    tmp99 = tmp98 >= tmp1
    tmp100 = tl.where(tmp99, tmp85, tmp83)
    tmp101 = tmp84 * tmp38
    tmp102 = tmp100 + tmp101
    tmp103 = tmp14 - tmp102
    tmp104 = triton_helpers.maximum(tmp103, tmp1)
    tmp105 = tmp15 - tmp102
    tmp106 = triton_helpers.maximum(tmp105, tmp1)
    tmp107 = tmp104 + tmp106
    tmp108 = tmp17 - tmp102
    tmp109 = triton_helpers.maximum(tmp108, tmp1)
    tmp110 = tmp107 + tmp109
    tmp111 = tmp19 - tmp102
    tmp112 = triton_helpers.maximum(tmp111, tmp1)
    tmp113 = tmp110 + tmp112
    tmp114 = tmp113 - tmp12
    tmp115 = tmp114 * tmp33
    tmp116 = tmp115 >= tmp1
    tmp117 = tl.where(tmp116, tmp102, tmp100)
    tmp118 = tmp101 * tmp38
    tmp119 = tmp117 + tmp118
    tmp120 = tmp14 - tmp119
    tmp121 = triton_helpers.maximum(tmp120, tmp1)
    tmp122 = tmp15 - tmp119
    tmp123 = triton_helpers.maximum(tmp122, tmp1)
    tmp124 = tmp121 + tmp123
    tmp125 = tmp17 - tmp119
    tmp126 = triton_helpers.maximum(tmp125, tmp1)
    tmp127 = tmp124 + tmp126
    tmp128 = tmp19 - tmp119
    tmp129 = triton_helpers.maximum(tmp128, tmp1)
    tmp130 = tmp127 + tmp129
    tmp131 = tmp130 - tmp12
    tmp132 = tmp131 * tmp33
    tmp133 = tmp132 >= tmp1
    tmp134 = tl.where(tmp133, tmp119, tmp117)
    tmp135 = tmp118 * tmp38
    tmp136 = tmp134 + tmp135
    tmp137 = tmp14 - tmp136
    tmp138 = triton_helpers.maximum(tmp137, tmp1)
    tmp139 = tmp15 - tmp136
    tmp140 = triton_helpers.maximum(tmp139, tmp1)
    tmp141 = tmp138 + tmp140
    tmp142 = tmp17 - tmp136
    tmp143 = triton_helpers.maximum(tmp142, tmp1)
    tmp144 = tmp141 + tmp143
    tmp145 = tmp19 - tmp136
    tmp146 = triton_helpers.maximum(tmp145, tmp1)
    tmp147 = tmp144 + tmp146
    tmp148 = tmp147 - tmp12
    tmp149 = tmp148 * tmp33
    tmp150 = tmp149 >= tmp1
    tmp151 = tl.where(tmp150, tmp136, tmp134)
    tmp152 = tmp135 * tmp38
    tmp153 = tmp151 + tmp152
    tmp154 = tmp14 - tmp153
    tmp155 = triton_helpers.maximum(tmp154, tmp1)
    tmp156 = tmp15 - tmp153
    tmp157 = triton_helpers.maximum(tmp156, tmp1)
    tmp158 = tmp155 + tmp157
    tmp159 = tmp17 - tmp153
    tmp160 = triton_helpers.maximum(tmp159, tmp1)
    tmp161 = tmp158 + tmp160
    tmp162 = tmp19 - tmp153
    tmp163 = triton_helpers.maximum(tmp162, tmp1)
    tmp164 = tmp161 + tmp163
    tl.store(out_ptr4 + x0, tmp101, xmask)
    tl.store(in_out_ptr2 + x0, tmp151, xmask)
    tl.store(out_ptr7 + x0, tmp164, xmask)


@triton.jit
def triton_poi_fused_add_clamp_div_sub_10(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 0.5
    tmp4 = tmp2 * tmp3
    tmp5 = tmp4 * tmp3
    tmp6 = tmp5 * tmp3
    tmp7 = tmp1 + tmp6
    tmp8 = tmp0 - tmp7
    tmp9 = 0.0
    tmp10 = triton_helpers.maximum(tmp8, tmp9)
    tmp12 = tmp10 / tmp11
    tl.store(out_ptr0 + x2, tmp12, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf40 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf41 = reinterpret_tensor(buf40, (4, 4, 4, 1), (16, 4, 1, 64), 0)
        del buf40
        get_raw_stream(0)
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_0[grid(64)](buf41,
            arg0_1, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf42 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf81 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf82 = reinterpret_tensor(buf81, (4, 4, 4, 1), (16, 4, 1, 64), 0)
        del buf81
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_1[grid(64)](buf82,
            arg0_1, buf41, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf83 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_clamp_div_sub_2[grid(256)](arg0_1, buf82,
            buf42, buf83, 256, XBLOCK=128, num_warps=4, num_stages=1)
        buf85 = buf82
        del buf82
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_3[grid(64)](buf85,
            buf83, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf86 = buf83
        del buf83
        triton_poi_fused_add_clamp_div_sub_4[grid(256)](arg0_1, buf85,
            buf42, buf86, 256, XBLOCK=128, num_warps=4, num_stages=1)
        buf88 = buf85
        del buf85
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_5[grid(64)](buf88,
            buf86, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf89 = buf86
        del buf86
        triton_poi_fused_add_div_sub_6[grid(256)](arg0_1, buf88, buf42,
            buf89, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf91 = buf88
        del buf88
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_7[grid(64)](buf91,
            buf89, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf92 = buf89
        del buf89
        triton_poi_fused_add_div_sub_8[grid(256)](arg0_1, buf91, buf42,
            buf92, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf94 = buf91
        del buf91
        buf100 = buf41
        del buf41
        buf103 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf104 = reinterpret_tensor(buf103, (4, 4, 4, 1), (16, 4, 1, 64), 0)
        del buf103
        buf105 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_9[grid(64)](buf94,
            buf104, buf92, arg0_1, buf42, buf100, buf105, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf42
        del buf94
        buf106 = buf92
        del buf92
        triton_poi_fused_add_clamp_div_sub_10[grid(256)](arg0_1, buf104,
            buf100, buf105, buf106, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
        del buf100
        del buf104
        del buf105
    return buf106,


def sparsemax_bisect(X, dim=-1, n_iter=50, ensure_sum_one=True):
    """sparsemax: normalizing sparse transform (a la softmax), via bisection.

    Solves the projection:

        min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.

    Parameters
    ----------
    X : torch.Tensor
        The input tensor.

    dim : int
        The dimension along which to apply sparsemax.

    n_iter : int
        Number of bisection iterations. For float32, 24 iterations should
        suffice for machine precision.

    ensure_sum_one : bool,
        Whether to divide the result by its sum. If false, the result might
        sum to close but not exactly 1, which might cause downstream problems.

    Note: This function does not yet support normalizing along anything except
    the last dimension. Please use transposing and views to achieve more
    general behavior.

    Returns
    -------
    P : torch tensor, same shape as X
        The projection result, such that P.sum(dim=dim) == 1 elementwise.
    """
    return SparsemaxBisectFunction.apply(X, dim, n_iter, ensure_sum_one)


class EntmaxBisectFunction(Function):

    @classmethod
    def _gp(cls, x, alpha):
        return x ** (alpha - 1)

    @classmethod
    def _gp_inv(cls, y, alpha):
        return y ** (1 / (alpha - 1))

    @classmethod
    def _p(cls, X, alpha):
        return cls._gp_inv(torch.clamp(X, min=0), alpha)

    @classmethod
    def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True
        ):
        if not isinstance(alpha, torch.Tensor):
            alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device)
        alpha_shape = list(X.shape)
        alpha_shape[dim] = 1
        alpha = alpha.expand(*alpha_shape)
        ctx.alpha = alpha
        ctx.dim = dim
        d = X.shape[dim]
        X = X * (alpha - 1)
        max_val, _ = X.max(dim=dim, keepdim=True)
        tau_lo = max_val - cls._gp(1, alpha)
        tau_hi = max_val - cls._gp(1 / d, alpha)
        f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1
        dm = tau_hi - tau_lo
        for it in range(n_iter):
            dm /= 2
            tau_m = tau_lo + dm
            p_m = cls._p(X - tau_m, alpha)
            f_m = p_m.sum(dim) - 1
            mask = (f_m * f_lo >= 0).unsqueeze(dim)
            tau_lo = torch.where(mask, tau_m, tau_lo)
        if ensure_sum_one:
            p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim)
        ctx.save_for_backward(p_m)
        return p_m

    @classmethod
    def backward(cls, ctx, dY):
        Y, = ctx.saved_tensors
        gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1))
        dX = dY * gppr
        q = dX.sum(ctx.dim) / gppr.sum(ctx.dim)
        q = q.unsqueeze(ctx.dim)
        dX -= q * gppr
        d_alpha = None
        if ctx.needs_input_grad[1]:
            S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1))
            ent = S.sum(ctx.dim).unsqueeze(ctx.dim)
            Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim)
            d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2
            d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1)
            d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim)
        return dX, d_alpha, None, None, None


class SparsemaxBisectFunction(EntmaxBisectFunction):

    @classmethod
    def _gp(cls, x, alpha):
        return x

    @classmethod
    def _gp_inv(cls, y, alpha):
        return y

    @classmethod
    def _p(cls, x, alpha):
        return torch.clamp(x, min=0)

    @classmethod
    def forward(cls, ctx, X, dim=-1, n_iter=50, ensure_sum_one=True):
        return super().forward(ctx, X, alpha=2, dim=dim, n_iter=50,
            ensure_sum_one=True)

    @classmethod
    def backward(cls, ctx, dY):
        Y, = ctx.saved_tensors
        gppr = Y > 0
        dX = dY * gppr
        q = dX.sum(ctx.dim) / gppr.sum(ctx.dim)
        q = q.unsqueeze(ctx.dim)
        dX -= q * gppr
        return dX, None, None, None


class SparsemaxBisectNew(nn.Module):

    def __init__(self, dim=-1, n_iter=None):
        """sparsemax: normalizing sparse transform (a la softmax) via bisection

        Solves the projection:

            min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.

        Parameters
        ----------
        dim : int
            The dimension along which to apply sparsemax.

        n_iter : int
            Number of bisection iterations. For float32, 24 iterations should
            suffice for machine precision.
        """
        self.dim = dim
        self.n_iter = n_iter
        super().__init__()

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