MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / dist

Function dist

std/math/src/main/float.rs:111–125  ·  view source on GitHub ↗
(p: Handle, q: Handle)

Source from the content-addressed store, hash-verified

109// Euclidean distance between two equal-length coordinate sequences.
110#[plugin_fn]
111fn dist(p: Handle, q: Handle) -> Result<f64> {
112 let (pi, qi) = (p.iter()?, q.iter()?);
113 let mut sum = 0.0;
114 loop {
115 match (pi.iter_next()?, qi.iter_next()?) {
116 (Some(a), Some(b)) => {
117 let d = f64::from_handle(a.raw())? - f64::from_handle(b.raw())?;
118 sum += d * d;
119 }
120 (None, None) => break,
121 _ => return Err(Error::Value(String::from("both points must have the same number of dimensions"))),
122 }
123 }
124 Ok(libm::sqrt(sum))
125}
126
127/* Hyperbolic */
128

Callers

nothing calls this directly

Calls 5

sqrtFunction · 0.85
iter_nextMethod · 0.80
ValueEnum · 0.50
iterMethod · 0.45
rawMethod · 0.45

Tested by

no test coverage detected