def test_1(self): a = np.arange(10) b = np.arange(10) res = np.zeros((a.shape[0] * b.shape[0], 2), dtype=np.int) cgmath.inter_index_array(a, b, res) ref = self._manual(a, b) 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_distance_array(cg1, cg2): """Calculate all pairwise distances between pairs in cg1 and cg2 :Returns: indices, distances indices - (n, 2) array of indices The first index refers to coordinates within cg1 The second index from cg2 distances - (n) Array of distances """ if not cg1 == cg2: raise ValueError("CellGrids are not compatible") # calculate required size of array Nreq = _calculate_distance_array_size(cg1, cg2) dist = np.empty(Nreq, dtype=np.float32) indices = np.empty((Nreq, 2), dtype=np.int) box = cg1.box # Calculate distances cell by cell pos = 0 # For each cell in cg1 for cell in cg1: # Iterate over all neighbours in other cellgrid for addr in itertools.chain([cell.address], cell.all_neighbours): other = cg2[addr] cgmath.inter_distance_array_withpbc( cell.coordinates, other.coordinates, box, dist[pos:] ) cgmath.inter_index_array( cell.indices, other.indices, indices[pos:] ) pos += len(cell) * 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
def cellgrid_distance_array(cg1, cg2): """Calculate all pairwise distances between pairs in cg1 and cg2 :Returns: indices, distances indices - (n, 2) array of indices The first index refers to coordinates within cg1 The second index from cg2 distances - (n) Array of distances """ if not cg1 == cg2: raise ValueError("CellGrids are not compatible") # calculate required size of array Nreq = _calculate_distance_array_size(cg1, cg2) dist = np.empty(Nreq, dtype=cg1.datatype) indices = np.empty((Nreq, 2), dtype=np.int) box = cg1.box # Calculate distances cell by cell pos = 0 # For each cell in cg1 for cell in cg1: # Iterate over all neighbours in other cellgrid for addr in itertools.chain([cell.address], cell.all_neighbours): other = cg2[addr] cgmath.inter_distance_array_withpbc(cell.coordinates, other.coordinates, box, dist[pos:]) cgmath.inter_index_array(cell.indices, other.indices, indices[pos:]) pos += len(cell) * len(other) return indices, dist