Skip to content

Commit

Permalink
[BACKPORT] Support creating tensor from list of tensors (#426) (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighingnow authored and hekaisheng committed May 31, 2019
1 parent 8dcf28f commit cc18826
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mars/tensor/expressions/datasource/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def tensor(data, dtype=None, chunk_size=None, gpu=None, sparse=False):
if dtype is not None and data.dtype != dtype:
return data.astype(dtype)
return data
elif isinstance(data, tuple) and all(isinstance(d, TENSOR_TYPE) for d in data):
elif isinstance(data, (tuple, list)) and all(isinstance(d, TENSOR_TYPE) for d in data):
from ..merge import stack

data = stack(data)
Expand Down
12 changes: 11 additions & 1 deletion mars/tensor/expressions/tests/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@
tiledb = None

from mars.tests.core import TestBase
from mars.tensor.expressions.datasource import fromtiledb, TensorTileDBDataSource
from mars.tensor.expressions.datasource import array, fromtiledb, TensorTileDBDataSource


class Test(TestBase):
def testFromArray(self):
x = array([1, 2, 3])
self.assertEqual(x.shape, (3,))

y = array([x, x])
self.assertEqual(y.shape, (2, 3))

z = array((x, x, x))
self.assertEqual(z.shape, (3, 3))

@unittest.skipIf(tiledb is None, 'TileDB not installed')
def testFromTileDB(self):
ctx = tiledb.Ctx()
Expand Down

0 comments on commit cc18826

Please sign in to comment.