!40260 support create tensor using np.array which is not c contiguous

Merge pull request !40260 from lianliguang/master
This commit is contained in:
i-robot 2022-08-12 01:58:14 +00:00 committed by Gitee
commit 91cc57c315
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 7 additions and 0 deletions

View File

@ -434,6 +434,9 @@ class Tensor(Tensor_):
>>> print(output)
[1 2]
"""
if isinstance(array, np.ndarray) and not array.flags['C_CONTIGUOUS']:
array = np.ascontiguousarray(array)
return Tensor(Tensor_.from_numpy(array))
def assign_value(self, value):

View File

@ -555,3 +555,7 @@ def test_tensor_from_numpy():
with pytest.raises(TypeError):
# incorrect input.
t = ms.Tensor.from_numpy([1, 2, 3])
x = np.array([[1, 2], [3, 4]], order='F')
b = Tensor.from_numpy(x)
assert np.all(b.asnumpy() == np.array([[1, 2], [3, 4]]))