def matvec(self, v, c, format='cython', axis=0):
N, M = self.shape
c.fill(0)
if format == 'self':
if axis > 0:
c = np.moveaxis(c, axis, 0)
v = np.moveaxis(v, axis, 0)
s = (slice(None),) + (np.newaxis,)*(v.ndim-1) # broadcasting
c[1:N] = self[-1][s]*v[:M-3]
c[:N] += self[1][s]*v[1:M-1]
c[:N-1] += self[3][s]*v[3:M]
if axis > 0:
c = np.moveaxis(c, 0, axis)
v = np.moveaxis(v, 0, axis)
elif format == 'cython' and v.ndim == 3:
CBD_matvec3D(v, c, self[-1], self[1], self[3], axis)
elif format == 'cython' and v.ndim == 1:
CBD_matvec(v, c, self[-1], self[1], self[3])
else:
c = super(SpectralMatrix, self).matvec(v, c, format=format, axis=axis)
return c
评论列表
文章目录