diff --git a/imperative/python/megengine/core/tensor/raw_tensor/__init__.py b/imperative/python/megengine/core/tensor/raw_tensor/__init__.py index a14fd1971998a13a2e01499a0c59c33a5e78a72e..ca62b105be7e76ea827fef4fd04ca3989440beb0 100644 --- a/imperative/python/megengine/core/tensor/raw_tensor/__init__.py +++ b/imperative/python/megengine/core/tensor/raw_tensor/__init__.py @@ -100,6 +100,8 @@ def _(data: DeviceTensorND): @as_raw_tensor.register(np.ndarray) def _(array: np.ndarray, dtype=None, device=None): device = None if device is None else as_device(device).to_c() + if 0 in array.strides: + array = array.squeeze().reshape(array.shape) return RawTensor(put(array, dtype=dtype, device=device)) diff --git a/imperative/python/test/unit/functional/test_functional.py b/imperative/python/test/unit/functional/test_functional.py index e8608954de00f550907191c008d5f40972f2a536..509b752a7cb0ad5852d0bd50e08c2f4dc347271b 100644 --- a/imperative/python/test/unit/functional/test_functional.py +++ b/imperative/python/test/unit/functional/test_functional.py @@ -458,6 +458,15 @@ def test_conv_bias(): run(10, 36, 8, 46, 26, 2, 2, 2, 1, 1, 2, True, "RELU") +def test_zero_stride_numpy_array(): + inp = np.random.randn(3, 224, 224).astype(np.float32) + inp = inp[np.newaxis, :] + + inp = tensor(inp, dtype=np.float32) + weight = tensor(np.random.randn(16, 3, 3, 3), dtype=np.float32) + out = F.conv2d(inp, weight, None, (2, 2), (3, 3), (1, 1), 1) + + def test_condtake(): x = np.array([[1, 2, 3], [4, 5, 6]]) y = np.array([[True, False, True], [False, True, True]])