def trace(P, offset=0, ax1=0, ax2=1): A = P.A.copy() if P.dtype==f.frac: for key in P.keys: A[key] = f.trace(A[key], ax1, ax2) else: for key in P.keys: A[key] = np.trace(A[key], ax1, ax2) return Poly(A, P.dim, None, P.dtype)
def trace(P, offset=0, ax1=0, ax2=1): A = P.A.copy() if P.dtype == f.frac: for key in P.keys: A[key] = f.trace(A[key], ax1, ax2) else: for key in P.keys: A[key] = np.trace(A[key], ax1, ax2) return Poly(A, P.dim, None, P.dtype)
def trace(A, offset=0, ax1=0, ax2=1): if isinstance(A, (int, long, float, np.ndarray)): return np.trace(A, offset, ax1, ax2) elif isinstance(A, f.frac): return f.trace(A, offset, ax1, ax2) elif isinstance(A, p.Poly): return p.trace(A, offset, ax1, ax2) raise NotImplementedError