def test_1(self): a = np.arange(30).reshape(10, 3).astype(np.float32) n = 10 res = np.zeros(n * (n-1) // 2, dtype=np.float32) box = np.ones(3).astype(np.float32) * 30 cgmath.intra_distance_array_withpbc(a, box, res) ref = util.slow_intra_distance_withpbc(a, box) assert_array_almost_equal(ref, res)
def test_1(self): for prec in self.precs: a = np.arange(30).reshape(10, 3).astype(prec) n = 10 res = np.zeros(n * (n-1) // 2, dtype=prec) box = np.ones(3).astype(prec) * 30 cgmath.intra_distance_array_withpbc(a, box, res) ref = util.slow_intra_distance_withpbc(a, box) 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