forked from mindspore-Ecosystem/mindspore
!40260 support create tensor using np.array which is not c contiguous
Merge pull request !40260 from lianliguang/master
This commit is contained in:
commit
91cc57c315
|
@ -434,6 +434,9 @@ class Tensor(Tensor_):
|
||||||
>>> print(output)
|
>>> print(output)
|
||||||
[1 2]
|
[1 2]
|
||||||
"""
|
"""
|
||||||
|
if isinstance(array, np.ndarray) and not array.flags['C_CONTIGUOUS']:
|
||||||
|
array = np.ascontiguousarray(array)
|
||||||
|
|
||||||
return Tensor(Tensor_.from_numpy(array))
|
return Tensor(Tensor_.from_numpy(array))
|
||||||
|
|
||||||
def assign_value(self, value):
|
def assign_value(self, value):
|
||||||
|
|
|
@ -555,3 +555,7 @@ def test_tensor_from_numpy():
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
# incorrect input.
|
# incorrect input.
|
||||||
t = ms.Tensor.from_numpy([1, 2, 3])
|
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]]))
|
||||||
|
|
Loading…
Reference in New Issue