def __init__(self, first, second=None, third=None): self.metadata = {} cb = None if type(first) == gpt.grid: self.grid = first if type(second) == str: # from desc p = second.split(";") self.otype = gpt.str_to_otype(p[0]) cb = gpt.str_to_cb(p[1]) self.v_obj = [ cgpt.create_lattice(self.grid.obj, t, self.grid.precision) for t in self.otype.v_otype ] else: self.otype = second if third is not None: self.v_obj = third else: self.v_obj = [ cgpt.create_lattice(self.grid.obj, t, self.grid.precision) for t in self.otype.v_otype ] elif type(first) == gpt.lattice: # Note that copy constructor only creates a compatible lattice but does not copy its contents! self.grid = first.grid self.otype = first.otype self.v_obj = [ cgpt.create_lattice(self.grid.obj, t, self.grid.precision) for t in self.otype.v_otype ] cb = first.checkerboard() else: raise Exception("Unknown lattice constructor") # use first pointer to index page in memory book mem_book[self.v_obj[0]] = ( self.grid, self.otype, gpt.time(), gpt.get_call_stack() if verbose_lattice_creation else None, ) if cb is not None: self.checkerboard(cb)
g.message(f"Done with {dti.otype.__name__}") assert eps == 0.0 # test numpy versus lattice tensor multiplication for a_type in [ g.ot_matrix_spin_color(4, 3), g.ot_vector_spin_color(4, 3), g.ot_matrix_spin(4), g.ot_vector_spin(4), g.ot_matrix_color(3), g.ot_vector_color(3), ]: # mtab for e in a_type.mtab: if a_type.mtab[e][1] is not None: b_type = g.str_to_otype(e) a = rng.cnormal(g.lattice(grid, a_type)) b = rng.cnormal(g.lattice(grid, b_type)) mul_lat = g(a * b)[0, 0, 0, 0] mul_np = a[0, 0, 0, 0] * b[0, 0, 0, 0] eps2 = g.norm2(mul_lat - mul_np) / g.norm2(mul_lat) g.message(f"Test {a_type.__name__} * {b_type.__name__}: {eps2}") if eps2 > 1e-12: g.message(mul_lat) g.message( np.tensordot(a[0, 0, 0, 0].array, b[0, 0, 0, 0].array, axes=a_type.mtab[e][1]).shape) assert eps2 < 1e-12 # rmtab