Skip to main content

triplet_margin_loss_forward

Function triplet_margin_loss_forward 

Source
pub fn triplet_margin_loss_forward<T: Triton, const BLOCK_SIZE: i32>(
    anchor_ptr: T::Pointer<f32>,
    positive_ptr: T::Pointer<f32>,
    negative_ptr: T::Pointer<f32>,
    out_ptr: T::Pointer<f32>,
    _n_rows: i32,
    n_dim: i32,
    margin: f32,
    eps: f32,
)
where T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>, T::Pointer<f32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<f32>>>,
Expand description

Triplet margin loss forward (per-row).

d(a,p) = sqrt(||a-p||^2 + eps), d(a,n) = sqrt(||a-n||^2 + eps) out[i] = max(0, d(a,p) - d(a,n) + margin)

Grid: [n_rows, 1, 1]. BLOCK_SIZE must equal next_power_of_two(n_dim).