提交 9e7a11cf authored 作者: Shawn Tan's avatar Shawn Tan

Implemented offset.

上级 e3726097
...@@ -6557,14 +6557,16 @@ class AllocDiag(Op): ...@@ -6557,14 +6557,16 @@ class AllocDiag(Op):
axis1 = np.minimum(self.axis1, self.axis2) axis1 = np.minimum(self.axis1, self.axis2)
axis2 = np.maximum(self.axis1, self.axis2) axis2 = np.maximum(self.axis1, self.axis2)
offset = self.offset
# Create array with one extra dimension for resulting matrix # Create array with one extra dimension for resulting matrix
result_shape = x.shape[:-1] + (x.shape[-1],) * 2 result_shape = x.shape[:-1] + (x.shape[-1] + offset,) * 2
result = np.zeros(result_shape, dtype=x.dtype) result = np.zeros(result_shape, dtype=x.dtype)
# Create slice for diagonal in final 2 axes # Create slice for diagonal in final 2 axes
diagonal_slice = ((len(result_shape) - 2) * [slice(None)] + diagonal_slice = ((len(result_shape) - 2) * [slice(None)] +
[np.arange(x.shape[-1])] * 2) [np.arange(x.shape[-1]) + max(0, -offset),
np.arange(x.shape[-1]) + max(0, offset)])
# Fill in final 2 axes with x # Fill in final 2 axes with x
result[diagonal_slice] = x result[diagonal_slice] = x
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论