Source code for hiphive.core.tensors

Module containing tensor related functions

import numpy as np

[docs]def get_einsum_path(indices_list, optimize='optimal'): contr = [] for indices in indices_list: arr = np.random.random((3,)*len(indices)) contr.append(arr) contr.append(list(indices)) path = np.einsum_path(*contr, optimize=optimize) return path[0]
[docs]def rotate_tensor(T, R, path=None): """Equivalent to T_abc... = T_ijk... R_ia R_jb R_kc ... """ kw = dict() if path is not None: kw['optimize'] = path order = len(T.shape) einsum_input = [T, list(range(order))] for i in range(order): einsum_input.append(R) einsum_input.append([i, order + i]) return np.einsum(*einsum_input, **kw)
[docs]def rotation_to_cart_coord(R, cell): """Return the rotation matrix in cart coord given a cell metric """ return, R), np.linalg.inv(cell.T))