Compute spatial distance using pure numpy
    (similar to scipy.spatial.distance.cdist())

    Thanks to Divakar Roy (@droyed) at stackoverflow.com

    Note this needs at least np.float64 precision!

    Returns: dist
337821
def pdist_squareformed_numpy(a):
    
    a = np.array(a, dtype=np.float64)
    a_sumrows = np.einsum('ij,ij->i', a, a)
    dist = a_sumrows[:, None] + a_sumrows - 2 * np.dot(a, a.T)
    np.fill_diagonal(dist, 0)
    return dist
144047
def compute_distance(x_ori, x_pert, constraint='l2'):
  
  if constraint == 'l2':
    dist = np.linalg.norm(x_ori - x_pert)
  elif constraint == 'linf':
    dist = np.max(abs(x_ori - x_pert))
  return dist
229679
def d(self):
        
        # TODO this will only work from a star or below. good thing?
        d = self.parent.d
        if ed_params.estimateMissingValues:
            if d is np.nan:
                d = self.estimateDistance()
                if d is not np.nan:
                    self.flags.addFlag('Estimated Distance')
            return d
        else:
            return np.nan
681936
def cdf(arr, pos=None):
    '''
    
    '''

    r = (arr.min(), arr.max())
    hist, bin_edges = np.histogram(arr, bins=2 * int(r[1] - r[0]), range=r)
    hist = np.asfarray(hist) / hist.sum()
    cdf = np.cumsum(hist)
    if pos is None:
        return cdf
    i = np.argmax(cdf > pos)
    return bin_edges[i]
568897
def vector_distance(v1, v2):
    """"""
    dist = 0
    for dim in v1:
        for x in v1[dim]:
            dd = int(v1[dim][x]) - int(v2[dim][x])
            dist = dist + dd**2
    return dist
390575
def cycle_dist(x, y, n):
    
    dist = abs(x - y) % n
    if dist >= 0.5 * n:
        dist = n - dist
    return dist
1099756
def cumulative_distance(lat, lon,dist_int=None):
    '''
    
    '''

    #   Define constants
    
    #Degree to radians conversion
    #deg_rad = np.pi/360.0
    
    #Earth radius (km)
    rt = 6378.137
    
    #;Remove repeated positions
    #IF (KEYWORD_SET(NOREPEAT)) THEN id = WHERE(~((lon_b_in EQ lon_a_in[0]) * (lat_b_in EQ lat_a_in[0])),okCnt) ELSE okcnt = 1 
    #IF (okCnt EQ 0) THEN RETURN lon_a_in, DOUBLE(0.)

    nelts=lon.size

    #Degree to radians conversion
    lon_a = np.deg2rad(lon[0:nelts - 1])
    lon_b = np.deg2rad(lon[1:nelts])
    lat_a = np.deg2rad(lat[0:nelts - 1])
    lat_b = np.deg2rad(lat[1:nelts])
    
    interm = np.cos(lat_a) * np.cos(lat_b) * np.cos(lon_a - lon_b) + np.sin(lat_a) * np.sin(lat_b) #Wolfram Math World definition
    
    dist_int=np.append(0,rt*np.arccos(interm))
    
    return dist_int.cumsum()
126617
def path_distance(points):
    
    vecs = np.diff(points, axis=0)[:, :3]
    d2 = [np.dot(p, p) for p in vecs]
    return np.sum(np.sqrt(d2))
395842
def distance(self, other):
        
        return np.linalg.norm(other.coords - self.coords)
1210673
def dist_points(bin_edges, d):
    
    bc = bin_centers(bin_edges)
    if d is not None:
        d = DISTS[d['type']](d, bc)
    return d, bc
366599
def distance(self, point):
        
        return sqrt((self.x-point.x)**2+(self.y-point.y)**2)
1221009
def get_pixel_distance(self, x1, y1, x2, y2):
        
        dx = abs(x2 - x1)
        dy = abs(y2 - y1)
        dist = np.sqrt(dx * dx + dy * dy)
        dist = np.round(dist)
        return dist
157294
def _euclidean_dist(vector_a, vector_b):
    
    dist = 0
    for (x, y) in zip(vector_a, vector_b):
        dist += (x-y)*(x-y)
    return math.sqrt(dist)
813875
def distance(self) -> ErrorValue:
        """"""
        if 'DistCalibrated' in self._data:
            dist = self._data['DistCalibrated']
        else:
            dist = self._data["Dist"]
        if 'DistCalibratedError' in self._data:
            disterr = self._data['DistCalibratedError']
        elif 'DistError' in self._data:
            disterr = self._data['DistError']
        else:
            disterr = 0.0
        return ErrorValue(dist, disterr)
190548
def _cal_dist2center(X, center):
    
    dmemb2cen = scipy.spatial.distance.cdist(X, center.reshape(1,X.shape[1]), metric='seuclidean')
    return(np.sum(dmemb2cen))
1195398
def _compute_distance_terms(cls, dists, coeffs):
        
        return - np.log(dists.rhypo) - coeffs['c4']*dists.rhypo
1091227
void get_distance_features(final Context ctx,
                               List<Integer> features)
    {
        if (!use_distance)
        {
            return;
        }

        int dist = 8;
        if (ctx.S0 >= 0 && ctx.S1 >= 0)
        {
            dist = math.binned_1_2_3_4_5_6_10[ctx.S0 - ctx.S1];
            if (dist == 10)
            {
                dist = 7;
            }
        }
        features.add(dist + kDistanceInFeaturespace);
    }