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 math as tl_math
from torch import 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_poi_fused_max_min_pow_sub_0(in_ptr0, out_ptr0, out_ptr1,
    out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp4 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp8 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp13 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp20 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp26 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp29 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp33 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp38 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp39 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp46 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp5 = tmp1 - tmp4
    tmp6 = tmp5 * tmp5
    tmp7 = triton_helpers.minimum(tmp3, tmp6)
    tmp9 = tmp4 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = triton_helpers.minimum(tmp7, tmp10)
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 * tmp14
    tmp17 = tmp13 - tmp16
    tmp18 = tmp17 * tmp17
    tmp19 = triton_helpers.minimum(tmp15, tmp18)
    tmp21 = tmp16 - tmp20
    tmp22 = tmp21 * tmp21
    tmp23 = triton_helpers.minimum(tmp19, tmp22)
    tmp24 = triton_helpers.minimum(tmp11, tmp23)
    tmp27 = tmp25 - tmp26
    tmp28 = tmp27 * tmp27
    tmp30 = tmp26 - tmp29
    tmp31 = tmp30 * tmp30
    tmp32 = triton_helpers.minimum(tmp28, tmp31)
    tmp34 = tmp29 - tmp33
    tmp35 = tmp34 * tmp34
    tmp36 = triton_helpers.minimum(tmp32, tmp35)
    tmp37 = triton_helpers.minimum(tmp24, tmp36)
    tmp40 = tmp38 - tmp39
    tmp41 = tmp40 * tmp40
    tmp43 = tmp39 - tmp42
    tmp44 = tmp43 * tmp43
    tmp45 = triton_helpers.minimum(tmp41, tmp44)
    tmp47 = tmp42 - tmp46
    tmp48 = tmp47 * tmp47
    tmp49 = triton_helpers.minimum(tmp45, tmp48)
    tmp50 = triton_helpers.minimum(tmp37, tmp49)
    tmp51 = triton_helpers.maximum(tmp3, tmp6)
    tmp52 = triton_helpers.maximum(tmp51, tmp10)
    tmp53 = triton_helpers.maximum(tmp15, tmp18)
    tmp54 = triton_helpers.maximum(tmp53, tmp22)
    tmp55 = triton_helpers.maximum(tmp52, tmp54)
    tmp56 = triton_helpers.maximum(tmp28, tmp31)
    tmp57 = triton_helpers.maximum(tmp56, tmp35)
    tmp58 = triton_helpers.maximum(tmp55, tmp57)
    tmp59 = triton_helpers.maximum(tmp41, tmp44)
    tmp60 = triton_helpers.maximum(tmp59, tmp48)
    tmp61 = triton_helpers.maximum(tmp58, tmp60)
    tmp62 = tmp0 - tmp12
    tmp63 = tmp62 * tmp62
    tmp64 = tmp1 - tmp13
    tmp65 = tmp64 * tmp64
    tmp66 = triton_helpers.minimum(tmp63, tmp65)
    tmp67 = tmp4 - tmp16
    tmp68 = tmp67 * tmp67
    tmp69 = triton_helpers.minimum(tmp66, tmp68)
    tmp70 = tmp8 - tmp20
    tmp71 = tmp70 * tmp70
    tmp72 = triton_helpers.minimum(tmp69, tmp71)
    tmp73 = tmp12 - tmp25
    tmp74 = tmp73 * tmp73
    tmp75 = tmp13 - tmp26
    tmp76 = tmp75 * tmp75
    tmp77 = triton_helpers.minimum(tmp74, tmp76)
    tmp78 = tmp16 - tmp29
    tmp79 = tmp78 * tmp78
    tmp80 = triton_helpers.minimum(tmp77, tmp79)
    tmp81 = tmp20 - tmp33
    tmp82 = tmp81 * tmp81
    tmp83 = triton_helpers.minimum(tmp80, tmp82)
    tmp84 = triton_helpers.minimum(tmp72, tmp83)
    tmp85 = tmp25 - tmp38
    tmp86 = tmp85 * tmp85
    tmp87 = tmp26 - tmp39
    tmp88 = tmp87 * tmp87
    tmp89 = triton_helpers.minimum(tmp86, tmp88)
    tmp90 = tmp29 - tmp42
    tmp91 = tmp90 * tmp90
    tmp92 = triton_helpers.minimum(tmp89, tmp91)
    tmp93 = tmp33 - tmp46
    tmp94 = tmp93 * tmp93
    tmp95 = triton_helpers.minimum(tmp92, tmp94)
    tmp96 = triton_helpers.minimum(tmp84, tmp95)
    tmp97 = triton_helpers.maximum(tmp63, tmp65)
    tmp98 = triton_helpers.maximum(tmp97, tmp68)
    tmp99 = triton_helpers.maximum(tmp98, tmp71)
    tmp100 = triton_helpers.maximum(tmp74, tmp76)
    tmp101 = triton_helpers.maximum(tmp100, tmp79)
    tmp102 = triton_helpers.maximum(tmp101, tmp82)
    tmp103 = triton_helpers.maximum(tmp99, tmp102)
    tmp104 = triton_helpers.maximum(tmp86, tmp88)
    tmp105 = triton_helpers.maximum(tmp104, tmp91)
    tmp106 = triton_helpers.maximum(tmp105, tmp94)
    tmp107 = triton_helpers.maximum(tmp103, tmp106)
    tl.store(out_ptr0 + x0, tmp50, xmask)
    tl.store(out_ptr1 + x0, tmp61, xmask)
    tl.store(out_ptr2 + x0, tmp96, xmask)
    tl.store(out_ptr3 + x0, tmp107, xmask)


@triton.jit
def triton_per_fused_abs_add_div_exp_gt_log_mean_mul_neg_pow_sub_sum_1(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    rnumel = 48
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    rmask = rindex < rnumel
    r0 = rindex % 3
    r1 = rindex // 3 % 4
    r2 = rindex // 12
    r4 = rindex % 12
    tmp0 = tl.load(in_ptr0 + (r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + (1 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp4 = tl.load(in_ptr0 + (16 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp5 = tl.load(in_ptr0 + (17 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp9 = tl.load(in_ptr0 + (32 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp10 = tl.load(in_ptr0 + (33 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp14 = tl.load(in_ptr0 + (48 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp15 = tl.load(in_ptr0 + (49 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp19 = tl.load(in_ptr1 + (r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp20 = tl.load(in_ptr1 + (1 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp23 = tl.load(in_ptr1 + (16 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp24 = tl.load(in_ptr1 + (17 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp28 = tl.load(in_ptr1 + (32 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp29 = tl.load(in_ptr1 + (33 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp33 = tl.load(in_ptr1 + (48 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp34 = tl.load(in_ptr1 + (49 + r0 + 4 * r1 + 64 * r2), rmask, other=0.0)
    tmp43 = tl.load(in_ptr2 + 4 * r2, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp45 = tl.load(in_ptr3 + 4 * r2, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp50 = tl.load(in_ptr2 + (1 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp52 = tl.load(in_ptr3 + (1 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp57 = tl.load(in_ptr2 + (2 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp59 = tl.load(in_ptr3 + (2 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp64 = tl.load(in_ptr2 + (3 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp66 = tl.load(in_ptr3 + (3 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp89 = tl.load(in_ptr0 + (r4 + 64 * r2), rmask, other=0.0)
    tmp90 = tl.load(in_ptr0 + (4 + r4 + 64 * r2), rmask, other=0.0)
    tmp93 = tl.load(in_ptr0 + (16 + r4 + 64 * r2), rmask, other=0.0)
    tmp94 = tl.load(in_ptr0 + (20 + r4 + 64 * r2), rmask, other=0.0)
    tmp98 = tl.load(in_ptr0 + (32 + r4 + 64 * r2), rmask, other=0.0)
    tmp99 = tl.load(in_ptr0 + (36 + r4 + 64 * r2), rmask, other=0.0)
    tmp103 = tl.load(in_ptr0 + (48 + r4 + 64 * r2), rmask, other=0.0)
    tmp104 = tl.load(in_ptr0 + (52 + r4 + 64 * r2), rmask, other=0.0)
    tmp108 = tl.load(in_ptr1 + (r4 + 64 * r2), rmask, other=0.0)
    tmp109 = tl.load(in_ptr1 + (4 + r4 + 64 * r2), rmask, other=0.0)
    tmp112 = tl.load(in_ptr1 + (16 + r4 + 64 * r2), rmask, other=0.0)
    tmp113 = tl.load(in_ptr1 + (20 + r4 + 64 * r2), rmask, other=0.0)
    tmp117 = tl.load(in_ptr1 + (32 + r4 + 64 * r2), rmask, other=0.0)
    tmp118 = tl.load(in_ptr1 + (36 + r4 + 64 * r2), rmask, other=0.0)
    tmp122 = tl.load(in_ptr1 + (48 + r4 + 64 * r2), rmask, other=0.0)
    tmp123 = tl.load(in_ptr1 + (52 + r4 + 64 * r2), rmask, other=0.0)
    tmp131 = tl.load(in_ptr4 + 4 * r2, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp133 = tl.load(in_ptr5 + 4 * r2, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp137 = tl.load(in_ptr4 + (1 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp139 = tl.load(in_ptr5 + (1 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp144 = tl.load(in_ptr4 + (2 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp146 = tl.load(in_ptr5 + (2 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp151 = tl.load(in_ptr4 + (3 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp153 = tl.load(in_ptr5 + (3 + 4 * r2), rmask, eviction_policy=
        'evict_last', other=0.0)
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp6 = tmp4 - tmp5
    tmp7 = tl_math.abs(tmp6)
    tmp8 = tmp3 + tmp7
    tmp11 = tmp9 - tmp10
    tmp12 = tl_math.abs(tmp11)
    tmp13 = tmp8 + tmp12
    tmp16 = tmp14 - tmp15
    tmp17 = tl_math.abs(tmp16)
    tmp18 = tmp13 + tmp17
    tmp21 = tmp19 - tmp20
    tmp22 = tmp21 * tmp21
    tmp25 = tmp23 - tmp24
    tmp26 = tmp25 * tmp25
    tmp27 = tmp22 + tmp26
    tmp30 = tmp28 - tmp29
    tmp31 = tmp30 * tmp30
    tmp32 = tmp27 + tmp31
    tmp35 = tmp33 - tmp34
    tmp36 = tmp35 * tmp35
    tmp37 = tmp32 + tmp36
    tmp38 = -tmp37
    tmp39 = 0.125
    tmp40 = tmp38 * tmp39
    tmp41 = tl_math.exp(tmp40)
    tmp42 = tmp18 * tmp41
    tmp44 = tmp22 - tmp43
    tmp46 = tmp45 - tmp43
    tmp47 = 1e-16
    tmp48 = tmp46 + tmp47
    tmp49 = tmp44 / tmp48
    tmp51 = tmp26 - tmp50
    tmp53 = tmp52 - tmp50
    tmp54 = tmp53 + tmp47
    tmp55 = tmp51 / tmp54
    tmp56 = tmp49 + tmp55
    tmp58 = tmp31 - tmp57
    tmp60 = tmp59 - tmp57
    tmp61 = tmp60 + tmp47
    tmp62 = tmp58 / tmp61
    tmp63 = tmp56 + tmp62
    tmp65 = tmp36 - tmp64
    tmp67 = tmp66 - tmp64
    tmp68 = tmp67 + tmp47
    tmp69 = tmp65 / tmp68
    tmp70 = tmp63 + tmp69
    tmp71 = 2.0
    tmp72 = tmp70 * tmp71
    tmp73 = 1.0
    tmp74 = tmp72 > tmp73
    tmp75 = tmp74.to(tl.float32)
    tmp76 = tmp18 * tmp75
    tmp77 = tmp72 * tmp75
    tmp78 = tmp76 + tmp47
    tmp79 = tl_math.log(tmp78)
    tmp80 = tmp77 * tmp79
    tmp81 = tl.broadcast_to(tmp80, [XBLOCK, RBLOCK])
    tmp83 = tl.where(rmask, tmp81, 0)
    tmp84 = tl.sum(tmp83, 1)[:, None]
    tmp85 = tl.broadcast_to(tmp42, [XBLOCK, RBLOCK])
    tmp87 = tl.where(rmask, tmp85, 0)
    tmp88 = tl.sum(tmp87, 1)[:, None]
    tmp91 = tmp89 - tmp90
    tmp92 = tl_math.abs(tmp91)
    tmp95 = tmp93 - tmp94
    tmp96 = tl_math.abs(tmp95)
    tmp97 = tmp92 + tmp96
    tmp100 = tmp98 - tmp99
    tmp101 = tl_math.abs(tmp100)
    tmp102 = tmp97 + tmp101
    tmp105 = tmp103 - tmp104
    tmp106 = tl_math.abs(tmp105)
    tmp107 = tmp102 + tmp106
    tmp110 = tmp108 - tmp109
    tmp111 = tmp110 * tmp110
    tmp114 = tmp112 - tmp113
    tmp115 = tmp114 * tmp114
    tmp116 = tmp111 + tmp115
    tmp119 = tmp117 - tmp118
    tmp120 = tmp119 * tmp119
    tmp121 = tmp116 + tmp120
    tmp124 = tmp122 - tmp123
    tmp125 = tmp124 * tmp124
    tmp126 = tmp121 + tmp125
    tmp127 = -tmp126
    tmp128 = tmp127 * tmp39
    tmp129 = tl_math.exp(tmp128)
    tmp130 = tmp107 * tmp129
    tmp132 = tmp111 - tmp131
    tmp134 = tmp133 - tmp131
    tmp135 = tmp134 + tmp47
    tmp136 = tmp132 / tmp135
    tmp138 = tmp115 - tmp137
    tmp140 = tmp139 - tmp137
    tmp141 = tmp140 + tmp47
    tmp142 = tmp138 / tmp141
    tmp143 = tmp136 + tmp142
    tmp145 = tmp120 - tmp144
    tmp147 = tmp146 - tmp144
    tmp148 = tmp147 + tmp47
    tmp149 = tmp145 / tmp148
    tmp150 = tmp143 + tmp149
    tmp152 = tmp125 - tmp151
    tmp154 = tmp153 - tmp151
    tmp155 = tmp154 + tmp47
    tmp156 = tmp152 / tmp155
    tmp157 = tmp150 + tmp156
    tmp158 = tmp157 * tmp71
    tmp159 = tmp158 > tmp73
    tmp160 = tmp159.to(tl.float32)
    tmp161 = tmp107 * tmp160
    tmp162 = tmp158 * tmp160
    tmp163 = tmp161 + tmp47
    tmp164 = tl_math.log(tmp163)
    tmp165 = tmp162 * tmp164
    tmp166 = tl.broadcast_to(tmp165, [XBLOCK, RBLOCK])
    tmp168 = tl.where(rmask, tmp166, 0)
    tmp169 = tl.sum(tmp168, 1)[:, None]
    tmp170 = tl.broadcast_to(tmp130, [XBLOCK, RBLOCK])
    tmp172 = tl.where(rmask, tmp170, 0)
    tmp173 = tl.sum(tmp172, 1)[:, None]
    tmp174 = 48.0
    tmp175 = tmp88 / tmp174
    tmp176 = 0.0
    tmp177 = tmp175 + tmp176
    tmp178 = tmp173 / tmp174
    tmp179 = tmp177 + tmp178
    tmp180 = tmp179 * tmp73
    tmp181 = tmp84 / tmp174
    tmp182 = -tmp181
    tmp183 = tmp182 + tmp176
    tmp184 = tmp169 / tmp174
    tmp185 = -tmp184
    tmp186 = tmp183 + tmp185
    tmp187 = tmp186 * tmp73
    tmp188 = tmp180 + tmp187
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp188, None)


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((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        buf3 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_max_min_pow_sub_0[grid(16)](arg1_1, buf0, buf1,
            buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((), (), torch.float32)
        buf14 = buf10
        del buf10
        triton_per_fused_abs_add_div_exp_gt_log_mean_mul_neg_pow_sub_sum_1[grid
            (1)](buf14, arg0_1, arg1_1, buf0, buf1, buf2, buf3, 1, 48,
            XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del buf0
        del buf1
        del buf2
        del buf3
    return buf14,


class SmoothContourLossNew(nn.Module):
    """
        Loss function that contains smoothness loss derived from ss-with-RIM
        and contour-aware loss.
        Smoothness loss concerns about smoothness of local patterns, while
        contour-aware loss is interested in whether two patches are divided.
        Cross entropy (or KL divergence) is applied to calculate Contour-aware 
        loss. When calculating the gradients of probability, i.e. dp, and that 
        of image, i.e. di, we desire that the distribution of dp should appoximate
        that of di.

        Args:
            logits: torch.tensor
                A trainable tensor of shape (b, nSpixel, h, w)
                It should be softmaxed before calling this loss function.
            image: torch.tensor
                A tensor derived from color channels of input with shape
                (b, c, h, w)
            sigma: float
                Parameter of transformed Gaussian kernel size
            weights: List[float]
                A List contains 2 coefficients that control the amplitudes of
                2 losses
            thresh: float
                Parameter for controling the amplitude of edge
            margin: int
                Parameter for finding edge width
    """

    def __init__(self, sigma=2, weights=[1, 1], thresh=1.0, margin=1):
        super().__init__()
        self.sigma = 2 * sigma ** 2
        self.weights = weights
        self.thresh = thresh
        self.margin = margin

    def get_gradients(self, logits, image):
        dp_dx = logits[..., :-self.margin] - logits[..., self.margin:]
        dp_dy = logits[..., :-self.margin, :] - logits[..., self.margin:, :]
        di_dx = image[..., :-self.margin] - image[..., self.margin:]
        di_dy = image[..., :-self.margin, :] - image[..., self.margin:, :]
        return [dp_dx, dp_dy], [di_dx, di_dy]

    def smooth_loss(self, dp, di):
        return (dp.abs().sum(1) * (-di.pow(2).sum(1) / self.sigma).exp()).mean(
            )

    def contour_loss(self, dp, di):
        di_norm = di.pow(2)
        di_min = di_norm.min(-1, keepdim=True).values.min(-2, keepdim=True
            ).values
        di_max = di_norm.max(-1, keepdim=True).values.max(-2, keepdim=True
            ).values
        di_norm = ((di_norm - di_min) / (di_max - di_min + 1e-16)).sum(1) * 2
        isValidEdges = di_norm > self.thresh
        dp_valid = dp.abs().sum(1) * isValidEdges
        di_valid = di_norm * isValidEdges
        return -(di_valid * torch.log(dp_valid + 1e-16)).mean()

    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.034719