Realm

oa::ml::loss::triplet_margin

Compute the triplet margin loss mean(max(0, d(a, p) - d(a, n) + margin)) with L2 distances over the last axis. All three inputs share one [N, D] shape; swap (the donor’s distance exchange) is not part of this contract. Errors Returns an error for mismatched, empty, non-rank-two, or non-FP32 inputs, or when runtime recording fails.

FnRust public API

Function Documentation

pub fn triplet_margin( anchor: &Matrix, positive: &Matrix, negative: &Matrix, margin: f32 ) -> Result<Matrix>
Compute the triplet margin loss mean(max(0, d(a, p) - d(a, n) + margin)) with L2 distances over the last axis. All three inputs share one [N, D] shape; swap (the donor’s distance exchange) is not part of this contract. Errors Returns an error for mismatched, empty, non-rank-two, or non-FP32 inputs, or when runtime recording fails.