Periodic distance between two arrays. Periodic is a 3
    dimensional array containing the 3 box sizes.
353387
def periodic_distance(a, b, periodic):
    '''

    '''
    delta = np.abs(a - b)
    delta = np.where(delta > 0.5 * periodic, periodic - delta, delta)
    return np.sqrt((delta ** 2).sum(axis=-1))
1227647
function arrayDiff(a1, a2) {
    var o1={}, o2={}, diff=[], i, len, k;
    for (i=0, len=a1.length; i<len; i++) { o1[a1[i]] = true; }
    for (i=0, len=a2.length; i<len; i++) { o2[a2[i]] = true; }
    for (k in o1) { if (!(k in o2)) { diff.push(k); } }
    //for (k in o2) { if (!(k in o1)) { diff.push(k); } }
    return diff;
}
1197632
function compactSparseArray (array) {
        var index = -1,
            length = array ? array.length : 0,
            result = [];

        while (++index < length) {
            var value = array[index];

            if (value) {
                result.push(value);
            }
        }

        return result;
    }
1292418
function() {
        var invLen = 1 / vec3.len(this.normal.array);
        vec3.scale(this.normal.array, invLen);
        this.distance *= invLen;
    }
1236727
def minimum_image(self):
        """"""
        if self.box_vectors is None:
            raise ValueError('No periodic vectors defined')
        else:
            self.r_array = minimum_image(self.r_array, self.box_vectors.diagonal())
        
        return self
250043
public function distance(array $a, array $b): float
    {
        if (count($a) !== count($b)) {
            throw InvalidArgumentException::arraySizeNotMatch();
        }

        $differences = [];
        $count = count($a);

        for ($i = 0; $i < $count; ++$i) {
            $differences[] = abs($a[$i] - $b[$i]);
        }

        return max($differences);
    }
684092
function median(array) {
  var length = array.length;

  if (length === 0) {
    throw new RangeError("Error");
  }

  array.sort(function(a, b) {
    return a - b;
  });

  var middle = Math.floor(length / 2);

  return length % 2 ? array[middle] : (array[middle] + array[middle - 1]) / 2;
}
1190560
private static int[] freq(int[][] itemsets) {
        int[] f = new int[Math.max(itemsets) + 1];
        for (int[] itemset : itemsets) {
            for (int i : itemset) {
                f[i]++;
            }
        }
        return f;
    }
1038426
function distanceFrom(Centroids) {
                var distances = [];

                for(var i = 1; i <= this.Observations.rows(); i++) {
                    var distance = [];

                    for(var j = 1; j <= Centroids.rows(); j++) {
                        distance.push(this.Observations.row(i).distanceFrom(Centroids.row(j)));
                    }

                    distances.push(distance);
                }

                return $M(distances);
            }
890877
function getDamerauLevenshteinDistance(a, b) {
  if (!a) {
    if (!b) {
      return 0;
    }
    return b.length;
  }
  if (!b) {
    return a.length;
  }

  var aLength = a.length;
  var bLength = b.length;
  var matrix = [];

  var INF = aLength + bLength;
  matrix[0] = [INF];
  for (var i = 0; i <= aLength; i++) {
    matrix[i + 1] = [INF, i];
  }
  for (i = 0; i <= bLength; i++) {
    matrix[1][i + 1] = i;
    matrix[0][i + 1] = INF;
  }

  var sd = {};
  var ab = a + b;
  var abLength = ab.length;
  for (i = 0; i < abLength; i++) {
    var letter = ab[i];
    if (!sd.hasOwnProperty(letter)) {
      sd[letter] = 0;
    }
  }

  for (i = 1; i <= aLength; i++) {
    var DB = 0;
    for (var j = 1; j <= bLength; j++) {
      var i1 = sd[b[j - 1]];
      var j1 = DB;

      if (a[i - 1] === b[j - 1]) {
        matrix[i + 1][j + 1] = matrix[i][j];
        DB = j;
      }
      else {
        matrix[i + 1][j + 1] = Math.min(matrix[i][j], Math.min(matrix[i + 1][j], matrix[i][j + 1])) + 1;
      }
      matrix[i + 1][j + 1] = Math.min(matrix[i + 1][j + 1], matrix[i1][j1] + (i - i1 - 1) + 1 + (j - j1 - 1));
    }
    sd[a[i - 1]] = i;
  }
  return matrix[aLength + 1][bLength + 1];
}
443354
public static void shellSort(int[] arrays) {
        int h = 1;
        while (h <= arrays.length / ValueConsts.THREE_INT) {
            h = h * 3 + 1;
        }
        while (h > 0) {
            for (int i = h; i < arrays.length; i += h) {
                if (arrays[i] < arrays[i - h]) {
                    int tmp = arrays[i];
                    int j = i - h;
                    while (j >= 0 && arrays[j] > tmp) {
                        arrays[j + h] = arrays[j];
                        j -= h;
                    }
                    arrays[j + h] = tmp;
                }
            }
            h = (h - 1) / 3;
        }
    }
192432
def radius_of_gyration(coords, periodic):
    '''

    '''
    gc = geometric_center(coords, periodic)
    return (periodic_distance(coords, gc, periodic) ** 2).sum() / len(coords)
1176291
function(frustum) {
        // Check if all coords of frustum is on plane all under plane
        var coords = frustum.vertices;
        var normal = this.normal.array;
        var onPlane = vec3.dot(coords[0].array, normal) > this.distance;
        for (var i = 1; i < 8; i++) {
            if ((vec3.dot(coords[i].array, normal) > this.distance) != onPlane) {
                return true;
            }
        }
    }
1066286
def _period_array_cmp(cls, op):
    
    opname = '__{name}__'.format(name=op.__name__)
    nat_result = opname == '__ne__'

    def wrapper(self, other):
        op = getattr(self.asi8, opname)

        if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):
            return NotImplemented

        if is_list_like(other) and len(other) != len(self):
            raise ValueError("Lengths must match")

        if isinstance(other, Period):
            self._check_compatible_with(other)

            result = op(other.ordinal)
        elif isinstance(other, cls):
            self._check_compatible_with(other)

            result = op(other.asi8)

            mask = self._isnan | other._isnan
            if mask.any():
                result[mask] = nat_result

            return result
        elif other is NaT:
            result = np.empty(len(self.asi8), dtype=bool)
            result.fill(nat_result)
        else:
            other = Period(other, freq=self.freq)
            result = op(other.ordinal)

        if self._hasnans:
            result[self._isnan] = nat_result

        return result

    return compat.set_function_name(wrapper, opname, cls)
969452
def multiplicity(self):
        
        sga = SpacegroupAnalyzer(self.bulk_structure)
        periodic_struc = sga.get_symmetrized_structure()
        poss_deflist = sorted(
            periodic_struc.get_sites_in_sphere(self.site.coords, 2, include_index=True), key=lambda x: x[1])
        defindex = poss_deflist[0][2]

        equivalent_sites = periodic_struc.find_equivalent_sites(self.bulk_structure[defindex])
        return len(equivalent_sites)
616924
function (arr) {
      for (var i = 1; i < arr.length; i++) {
        var tmp = arr[i],
          j = i;
        while (arr[j - 1] && parseInt(arr[j - 1].width, 10) > parseInt(tmp.width, 10)) {
          arr[j] = arr[j - 1];
          --j;
        }
        arr[j] = tmp;
      }

      return arr;
    }
310228
def array(self):
        
        if self._intervals_len:
            if self._array_len != self._intervals_len:
                if not self._array_len:
                    self._array = np.array(self.intervals) \
                        if hasattr(np, 'array') else self.intervals
                else:
                    self._array = np.concatenate((
                        self._array, self.intervals), axis=0) \
                        if hasattr(np, 'concatenate') else \
                        (self._array + self.intervals)
                self._array_len += len(self.intervals)
                self.intervals = []
            return self._array
        return []