提交 c84455a3 authored 作者: Frederic's avatar Frederic

fix garray_to_cudandarray for dimensions of 0. CudaNdarray need a strides of 0…

fix garray_to_cudandarray for dimensions of 0. CudaNdarray need a strides of 0 in those cases, not 1. Error was raised in filter about this.
上级 93f4933f
...@@ -106,8 +106,11 @@ try: ...@@ -106,8 +106,11 @@ try:
strides = [1] strides = [1]
for i in x.shape[::-1][:-1]: for i in x.shape[::-1][:-1]:
strides.append(strides[-1]*i) strides.append(strides[-1]*i)
strides = tuple(strides[::-1]) strides = strides[::-1]
for i in range(len(strides)):
if x.shape[i] == 1:
strides[i] = 0
strides = tuple(strides)
import ctypes import ctypes
ptr_long = long(ctypes.cast(x._base.mat.data_device, ctypes.c_void_p).value) ptr_long = long(ctypes.cast(x._base.mat.data_device, ctypes.c_void_p).value)
......
...@@ -63,3 +63,16 @@ def test2(shape=(3, 4, 5)): ...@@ -63,3 +63,16 @@ def test2(shape=(3, 4, 5)):
assert A_cnd.gpudata == B.gpudata assert A_cnd.gpudata == B.gpudata
v = numpy.asarray(B) v = numpy.asarray(B)
assert (v == A).all() assert (v == A).all()
def test_broadcast_dims():
"""
Test with some dimensions being 1.
CudaNdarray use 0 for strides for those dimensions.
"""
test((1, 2, 3))
test((2, 1, 3))
test((2, 3, 1))
test2((1, 2, 3))
test2((2, 1, 3))
test2((2, 3, 1))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论