Convert the distances recorded in the ``shape_dist_traveled``
    columns of the given Feed to the given distance units.
    New distance units must lie in :const:`.constants.DIST_UNITS`.
    Return the resulting feed.
549748
def convert_dist(feed: "Feed", new_dist_units: str) -> "Feed":
    
    feed = feed.copy()

    if feed.dist_units == new_dist_units:
        # Nothing to do
        return feed

    old_dist_units = feed.dist_units
    feed.dist_units = new_dist_units

    converter = hp.get_convert_dist(old_dist_units, new_dist_units)

    if hp.is_not_null(feed.stop_times, "shape_dist_traveled"):
        feed.stop_times["shape_dist_traveled"] = feed.stop_times[
            "shape_dist_traveled"
        ].map(converter)

    if hp.is_not_null(feed.shapes, "shape_dist_traveled"):
        feed.shapes["shape_dist_traveled"] = feed.shapes[
            "shape_dist_traveled"
        ].map(converter)

    return feed
216274
def geo_distance_range(cls, field, center, from_distance, to_distance, distance_type=None):
        '''
        


        '''
        instance = cls(geo_distance_range={'from': from_distance, 'to': to_distance, field: center})
        if distance_type is not None:
            instance['geo_distance_range']['distance_type'] = distance_type
        return instance
428508
def furthest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
        
        assert self.exists
        if isinstance(position, Unit):
            position = position.position
        return position.distance_to_furthest([u.position for u in self])
936264
def _construct_auto_distance(feature_names, column_names, column_types, sample):
    

    ## Make a dictionary from the column_names and column_types
    col_type_dict = {k: v for k, v in zip(column_names, column_types)}

    ## Loop through feature names, appending a distance component if the
    #  feature's type is *not* numeric. If the type *is* numeric, append it to
    #  the numeric_cols list, then at the end make a numeric columns distance
    #  component.
    composite_distance_params = []
    numeric_cols = []

    for c in feature_names:
        if col_type_dict[c] == str:
            composite_distance_params.append([[c], _turicreate.distances.levenshtein, 1])
        elif col_type_dict[c] == dict:
            composite_distance_params.append([[c], _turicreate.distances.jaccard, 1])
        elif col_type_dict[c] == array.array:
            composite_distance_params.append([[c], _turicreate.distances.euclidean, 1])
        elif col_type_dict[c] == list:
            only_str_lists = _validate_lists(sample[c], allowed_types=[str])
            if not only_str_lists:
                raise TypeError("Only lists of all str objects are currently supported")
            composite_distance_params.append([[c], _turicreate.distances.jaccard, 1])
        elif col_type_dict[c] in [int, float, array.array, list]:
            numeric_cols.append(c)
        else:
            raise TypeError("Unable to automatically determine a distance "+\
                "for column {}".format(c))

    # Make the standalone numeric column distance component
    if len(numeric_cols) > 0:
        composite_distance_params.append([numeric_cols, _turicreate.distances.euclidean, 1])

    return composite_distance_params
487570
protected static <I> double[][] computeSquaredDistanceMatrix(final List<I> col, PrimitiveDistanceFunction<? super I> dist) {
    final int size = col.size();
    double[][] imat = new double[size][size];
    boolean squared = dist.isSquared();
    FiniteProgress dprog = LOG.isVerbose() ? new FiniteProgress("Computing distance matrix", (size * (size - 1)) >>> 1, LOG) : null;
    for(int x = 0; x < size; x++) {
      final I ox = col.get(x);
      for(int y = x + 1; y < size; y++) {
        final I oy = col.get(y);
        double distance = dist.distance(ox, oy);
        distance *= squared ? -.5 : (-.5 * distance);
        imat[x][y] = imat[y][x] = distance;
      }
      if(dprog != null) {
        dprog.setProcessed(dprog.getProcessed() + size - x - 1, LOG);
      }
    }
    LOG.ensureCompleted(dprog);
    return imat;
  }
1078393
def get_distance_term(self, C, dists, rup):
        
        x_ij = dists.rrup
        gn_exp = np.exp(C["c1"] + 6.5 * C["c2"])
        g_n = C["gcrN"] * np.log(self.CONSTANTS["xcro"] + 30. + gn_exp) *\
            np.ones_like(x_ij)
        idx = x_ij <= 30.0
        if np.any(idx):
            g_n[idx] = C["gcrN"] * np.log(self.CONSTANTS["xcro"] +
                                          x_ij[idx] + gn_exp)
        c_m = min(rup.mag, self.CONSTANTS["m_c"])
        r_ij = self.CONSTANTS["xcro"] + x_ij + np.exp(C["c1"] + C["c2"] * c_m)
        return C["gUM"] * np.log(r_ij) +\
            C["gcrL"] * np.log(x_ij + 200.0) +\
            g_n + C["eum"] * x_ij + C["ecrV"] * dists.rvolc + C["gamma_S"]
52336
def segment_radial_distances(neurites, neurite_type=NeuriteType.all, origin=None):
    ''''''
    def _seg_rd(sec, pos):
        '''list of radial distances of all segments of a section'''
        # TODO: remove this disable when pylint is fixed
        # pylint: disable=assignment-from-no-return
        mid_pts = np.divide(np.add(sec.points[:-1], sec.points[1:])[:, :3], 2.0)
        return np.sqrt([morphmath.point_dist2(p, pos) for p in mid_pts])

    dist = []
    for n in iter_neurites(neurites, filt=is_type(neurite_type)):
        pos = n.root_node.points[0] if origin is None else origin
        dist.extend([s for ss in n.iter_sections() for s in _seg_rd(ss, pos)])

    return dist
690223
def get_distr(center=0.0, stdev=default_stdev, length=50):
    " "
    # distr = np.random.random(length)

    # sticking to normal distibution to easily control separability
    distr = rng.normal(center, stdev, size=[length, 1])

    return distr
1131244
def _get_hanging_wall_distance_term(self, dists, ztor):
        
        fhngr = np.ones_like(dists.rjb, dtype=float)
        idx = dists.rjb > 0.
        if ztor < 1.:
            temp_rjb = np.sqrt(dists.rjb[idx] ** 2. + 1.)
            r_max = np.max(np.column_stack([dists.rrup[idx], temp_rjb]),
                           axis=1)
            fhngr[idx] = (r_max - dists.rjb[idx]) / r_max
        else:
            fhngr[idx] = (dists.rrup[idx] - dists.rjb[idx]) / dists.rrup[idx]
        return fhngr
204775
def get_redshift(self, dist):
        
        dist, input_is_array = ensurearray(dist)
        try:
            zs = self.nearby_d2z(dist)
        except TypeError:
            # interpolant hasn't been setup yet
            self.setup_interpolant()
            zs = self.nearby_d2z(dist)
        # if any points had red shifts beyond the nearby, will have nans;
        # replace using the faraway interpolation
        replacemask = numpy.isnan(zs)
        if replacemask.any():
            zs[replacemask] = self.faraway_d2z(dist[replacemask])
            replacemask = numpy.isnan(zs)
        # if we still have nans, means that some distances are beyond our
        # furthest default; fall back to using astropy
        if replacemask.any():
            # well... check that the distance is positive and finite first
            if not (dist > 0.).all() and numpy.isfinite(dist).all():
                raise ValueError("distance must be finite and > 0")
            zs[replacemask] = _redshift(dist[replacemask],
                                        cosmology=self.cosmology)
        return formatreturn(zs, input_is_array)
1173736
def convert(self, value, fromunits, tounits):
        ''''''
        if fromunits == tounits:
            return value
        if (fromunits,tounits) in self.unitmap:
            return value * self.unitmap[(fromunits,tounits)]
        if (tounits,fromunits) in self.unitmap:
            return value / self.unitmap[(tounits,fromunits)]
        raise fgFDMError("unknown unit mapping (%s,%s)" % (fromunits, tounits))
1166382
def _compute_distance(self, rup, dists, C):
        
        rval = np.sqrt(dists.repi ** 2 + C['h'] ** 2)
        return C['c1'] * np.log10(rval)
1019167
def truncate(self, distance):
        
        position = np.searchsorted(self._cum_norm, distance)
        offset = distance - self._cum_norm[position - 1]

        if offset < constants.tol_path.merge:
            truncated = self._points[:position + 1]
        else:
            vector = unitize(np.diff(self._points[np.arange(2) + position],
                                     axis=0).reshape(-1))
            vector *= offset
            endpoint = self._points[position] + vector
            truncated = np.vstack((self._points[:position + 1],
                                   endpoint))

        assert (np.linalg.norm(np.diff(truncated, axis=0),
                               axis=1).sum() - distance) < constants.tol_path.merge

        return truncated
888238
def _calculate_dispersion(X: Union[pd.DataFrame, np.ndarray], labels: np.ndarray, centroids: np.ndarray) -> float:
        
        disp = np.sum(np.sum([np.abs(inst - centroids[label]) ** 2 for inst, label in zip(X, labels)]))  # type: float
        return disp
413331
def convert_units_to_base_units(units):
    
    total_factor = 1
    new_units = []
    for unit in units:
        if unit not in BASE_UNIT_CONVERSIONS:
            continue

        factor, new_unit = BASE_UNIT_CONVERSIONS[unit]
        total_factor *= factor
        new_units.append(new_unit)

    new_units.sort()
    return total_factor, tuple(new_units)
1053946
def volume_to_distance_with_errors(vol, vol_err):
    
    dist = (vol * 3.0/4.0/numpy.pi) ** (1.0/3.0)
    ehigh = ((vol + vol_err) * 3.0/4.0/numpy.pi) ** (1.0/3.0) - dist
    delta = numpy.where(vol >= vol_err, vol - vol_err, 0)
    elow = dist - (delta * 3.0/4.0/numpy.pi) ** (1.0/3.0)
    return dist, ehigh, elow
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