class SymmetricArray:
'''
Attributes:
A (np.ndarray): an [m, (a,b,c...)] array.
idx (np.ndarray): an [n,] array where idx[n] points to A[idx[n], ...]
to be used.
reflect (np.ndarray): an [n, d] array where every entry is 1 or -1 and
reflect[n, i] indicates whether or not the ith dimension of
A[idx[n], ...] should be reflected, and d = len(A.shape - 1).
'''
def __init__(self, A, idx, reflect):
self.A = np.asarray(A)
self.idx = np.asarray(idx, dtype=int)
self.reflect = np.asarray(reflect, dtype=int)
def __getitem__(self, ii):
'''
Returns:
np.ndarray: appropriately reflected A[idx[ii], ...]
'''
a_mask = [slice(None, None, a) for a in self.reflect[ii, :]]
return self.A[self.idx[ii], ...][a_mask]
我最后做的是创建一个类来返回a的任意反射部分的视图。在返回这个视图之后,我按C和summas进行缩放,现在看来已经足够快了。这是它没有错误检查:
相关问题 更多 >
编程相关推荐