def test_1(self): a = np.arange(10) n = a.shape[0] res = np.zeros((n * (n-1) // 2, 2), dtype=np.int) cgmath.intra_index_array(a, res) ref = self._manual(a) assert_array_almost_equal(ref, res)
def cellgrid_self_distance_array(cg1): """Calculate all pairwise distances within a certain CellGrid :Returns: indices, distances indices - (n, 2) distances (n) """ box = cg1.box Nreq = _calculate_self_distance_array_size(cg1) indices = np.empty((Nreq, 2), dtype=np.int) dist = np.empty(Nreq, dtype=np.float32) pos = 0 for cell in cg1: n = len(cell) if n > 1: # Do own cell as a self distance comparison cgmath.intra_distance_array_withpbc( cell.coordinates, box, dist[pos:] ) cgmath.intra_index_array( cell.indices, indices[pos:] ) pos += n * (n - 1) // 2 # Then all half neighbours as a full comparison for addr in cell.half_neighbours: other = cg1[addr] if not other: continue cgmath.inter_distance_array_withpbc( cell.coordinates, other.coordinates, box, dist[pos:] ) cgmath.inter_index_array( cell.indices, other.indices, indices[pos:] ) pos += n * len(other) return indices, dist
def cellgrid_self_distance_array(cg1): """Calculate all pairwise distances within a certain CellGrid :Returns: indices, distances indices - (n, 2) distances (n) """ box = cg1.box Nreq = _calculate_self_distance_array_size(cg1) indices = np.empty((Nreq, 2), dtype=np.int) dist = np.empty(Nreq, dtype=cg1.datatype) pos = 0 for cell in cg1: n = len(cell) if n > 1: # Do own cell as a self distance comparison cgmath.intra_distance_array_withpbc(cell.coordinates, box, dist[pos:]) cgmath.intra_index_array(cell.indices, indices[pos:]) pos += n * (n - 1) // 2 # Then all half neighbours as a full comparison for addr in cell.half_neighbours: other = cg1[addr] if not other: continue cgmath.inter_distance_array_withpbc(cell.coordinates, other.coordinates, box, dist[pos:]) cgmath.inter_index_array(cell.indices, other.indices, indices[pos:]) pos += n * len(other) return indices, dist