def convert(first, second): if second in [gpt.single, gpt.double]: # if first is a list, distribute if type(first) == list: return [convert(x, second) for x in first] # if first is no list, evaluate src = gpt.eval(first) dst_grid = src.grid.converted(second) return convert(gpt.lattice(dst_grid, src.otype), src) elif type(first) == list: assert len(first) == len(second) for i in range(len(first)): convert(first[i], second[i]) return first elif type(first) == gpt.lattice: # second may be expression second = gpt.eval(second) # now second is lattice assert len(first.otype.v_idx) == len(second.otype.v_idx) for i in first.otype.v_idx: cgpt.convert(first.v_obj[i], second.v_obj[i]) # set checkerboard first.checkerboard(second.checkerboard()) return first else: assert 0
def convert(first, second): if second in [gpt.single, gpt.double]: # if first is a list, distribute if type(first) == list: return [convert(x, second) for x in first] # if first is no list, evaluate src = gpt.eval(first) dst_grid = src.grid.converted(second) return convert(gpt.lattice(dst_grid, src.otype), src) elif isinstance(second, gpt.ot_base): # if first is a list, distribute if type(first) == list: return [convert(x, second) for x in first] # if first is no list, evaluate src = gpt.eval(first) if src.otype.__name__ == second.__name__: return src return convert(gpt.lattice(src.grid, second), src) elif type(first) == list: assert len(first) == len(second) for i in range(len(first)): convert(first[i], second[i]) return first elif type(first) == gpt.lattice: # second may be expression second = gpt.eval(second) # if otypes differ, attempt otype conversion first if first.otype.__name__ != second.otype.__name__: assert first.otype.__name__ in second.otype.ctab tmp = gpt.lattice(first) second.otype.ctab[first.otype.__name__](tmp, second) second = tmp assert first.otype.__name__ == second.otype.__name__ # convert precision if needed if first.grid == second.grid: gpt.copy(first, second) else: assert len(first.otype.v_idx) == len(second.otype.v_idx) for i in first.otype.v_idx: cgpt.convert(first.v_obj[i], second.v_obj[i]) first.checkerboard(second.checkerboard()) return first else: assert 0
def convert(first, second): if type(first) == gpt.lattice and type(second) == gpt.lattice: assert (len(first.otype.v_idx) == len(second.otype.v_idx)) for i in first.otype.v_idx: cgpt.convert(first.v_obj[i], second.v_obj[i]) return first elif second == gpt.single or second == gpt.double: if type(first) == list: src_grid = first[0].grid else: src_grid = first.grid dst_prec = second dst_grid = gpt.grid(src_grid.fdimensions, dst_prec, src_grid.cb) if type(first) == list: dst = [ convert(gpt.lattice(dst_grid, src.otype), src) for src in first ] else: src = first dst = convert(gpt.lattice(dst_grid, src.otype), src) return dst else: assert (0)