We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] Cannot pass numpy array into mt.swapaxes
<!--
Thank you for your contribution!

Please review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.
-->

## Describe the bug
I met a bug when i passed numpy array into `mt.swapaxes`. See below:
```
In [35]: p = np.random.rand(3,4,5)                                                                                                                                                                   

In [36]: mt.swapaxes(p, 0, -1)                                                                                                                                                                       
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-36-016cb9916fdb> in <module>
----> 1 mt.swapaxes(p, 0, -1)

~/anaconda3/envs/pymars0.6/lib/python3.7/site-packages/mars/tensor/base/swapaxes.py in swapaxes(a, axis1, axis2)
    150         return a
    151 
--> 152     op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())
    153     return op(a)

AttributeError: 'numpy.ndarray' object has no attribute 'issparse'
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mars/tensor/base/swapaxes.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright 1999-2020 Alibaba Group Holding Ltd.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 from ... import opcodes as OperandDef
18 from ...serialize import KeyField, Int32Field
19 from ..utils import validate_axis, reverse_order
20 from ..operands import TensorHasInput, TensorOperandMixin
21 from ..array_utils import as_same_device, device
22 from ..core import TensorOrder
23 
24 
25 def _swap(it, axis1, axis2):
26     new_it = list(it)
27     new_it[axis1], new_it[axis2] = it[axis2], it[axis1]
28 
29     return tuple(new_it)
30 
31 
32 class TensorSwapAxes(TensorHasInput, TensorOperandMixin):
33     _op_type_ = OperandDef.SWAPAXES
34 
35     _input = KeyField('input')
36     _axis1 = Int32Field('axis1')
37     _axis2 = Int32Field('axis2')
38 
39     def __init__(self, axis1=None, axis2=None, dtype=None, sparse=False, **kw):
40         super().__init__(_axis1=axis1, _axis2=axis2, _dtype=dtype, _sparse=sparse,
41                          _create_view=True, **kw)
42 
43     @property
44     def axis1(self):
45         return self._axis1
46 
47     @property
48     def axis2(self):
49         return self._axis2
50 
51     def __call__(self, a):
52         axis1, axis2 = self._axis1, self._axis2
53         if (axis1 == 0 and axis2 == a.ndim - 1) or (axis1 == a.ndim - 1 and axis2 == 0):
54             tensor_order = reverse_order(a.order)
55         else:
56             tensor_order = TensorOrder.C_ORDER
57         shape = _swap(a.shape, self.axis1, self.axis2)
58         return self.new_tensor([a], shape, order=tensor_order)
59 
60     def _set_inputs(self, inputs):
61         super()._set_inputs(inputs)
62         self._input = self._inputs[0]
63 
64     def on_output_modify(self, new_output):
65         op = TensorSwapAxes(axis1=self._axis2, axis2=self._axis1, dtype=new_output.dtype,
66                             sparse=new_output.issparse())
67         return op(new_output)
68 
69     def on_input_modify(self, new_input):
70         op = self.copy().reset_key()
71         return op(new_input)
72 
73     @classmethod
74     def tile(cls, op):
75         axis1, axis2 = op.axis1, op.axis2
76         in_tensor = op.inputs[0]
77         out_tensor = op.outputs[0]
78 
79         out_chunks = []
80         for c in in_tensor.chunks:
81             chunk_shape = _swap(c.shape, axis1, axis2)
82             chunk_idx = _swap(c.index, axis1, axis2)
83             chunk_op = op.copy().reset_key()
84             out_chunk = chunk_op.new_chunk([c], shape=chunk_shape,
85                                            index=chunk_idx, order=out_tensor.order)
86             out_chunks.append(out_chunk)
87 
88         new_op = op.copy()
89         nsplits = _swap(in_tensor.nsplits, axis1, axis2)
90         return new_op.new_tensors([in_tensor], out_tensor.shape, order=out_tensor.order,
91                                   chunks=out_chunks, nsplits=nsplits)
92 
93     @classmethod
94     def execute(cls, ctx, op):
95         (x,), device_id, xp = as_same_device(
96             [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True)
97 
98         axis1, axis2 = op.axis1, op.axis2
99         with device(device_id):
100             ctx[op.outputs[0].key] = xp.swapaxes(x, axis1, axis2)
101 
102 
103 def swapaxes(a, axis1, axis2):
104     """
105     Interchange two axes of a tensor.
106 
107     Parameters
108     ----------
109     a : array_like
110         Input tensor.
111     axis1 : int
112         First axis.
113     axis2 : int
114         Second axis.
115 
116     Returns
117     -------
118     a_swapped : Tensor
119         If `a` is a Tensor, then a view of `a` is
120         returned; otherwise a new tensor is created.
121 
122     Examples
123     --------
124     >>> import mars.tensor as mt
125 
126     >>> x = mt.array([[1,2,3]])
127     >>> mt.swapaxes(x,0,1).execute()
128     array([[1],
129            [2],
130            [3]])
131 
132     >>> x = mt.array([[[0,1],[2,3]],[[4,5],[6,7]]])
133     >>> x.execute()
134     array([[[0, 1],
135             [2, 3]],
136            [[4, 5],
137             [6, 7]]])
138 
139     >>> mt.swapaxes(x,0,2).execute()
140     array([[[0, 4],
141             [2, 6]],
142            [[1, 5],
143             [3, 7]]])
144 
145     """
146     axis1 = validate_axis(a.ndim, axis1)
147     axis2 = validate_axis(a.ndim, axis2)
148 
149     if axis1 == axis2:
150         return a
151 
152     op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())
153     return op(a)
154
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mars/tensor/base/swapaxes.py b/mars/tensor/base/swapaxes.py
--- a/mars/tensor/base/swapaxes.py
+++ b/mars/tensor/base/swapaxes.py
@@ -16,10 +16,11 @@
 
 from ... import opcodes as OperandDef
 from ...serialize import KeyField, Int32Field
-from ..utils import validate_axis, reverse_order
-from ..operands import TensorHasInput, TensorOperandMixin
 from ..array_utils import as_same_device, device
 from ..core import TensorOrder
+from ..datasource import tensor as astensor
+from ..operands import TensorHasInput, TensorOperandMixin
+from ..utils import validate_axis, reverse_order
 
 
 def _swap(it, axis1, axis2):
@@ -143,6 +144,7 @@
             [3, 7]]])
 
     """
+    a = astensor(a)
     axis1 = validate_axis(a.ndim, axis1)
     axis2 = validate_axis(a.ndim, axis2)

{"golden_diff": "diff --git a/mars/tensor/base/swapaxes.py b/mars/tensor/base/swapaxes.py\n--- a/mars/tensor/base/swapaxes.py\n+++ b/mars/tensor/base/swapaxes.py\n@@ -16,10 +16,11 @@\n \n from ... import opcodes as OperandDef\n from ...serialize import KeyField, Int32Field\n-from ..utils import validate_axis, reverse_order\n-from ..operands import TensorHasInput, TensorOperandMixin\n from ..array_utils import as_same_device, device\n from ..core import TensorOrder\n+from ..datasource import tensor as astensor\n+from ..operands import TensorHasInput, TensorOperandMixin\n+from ..utils import validate_axis, reverse_order\n \n \n def _swap(it, axis1, axis2):\n@@ -143,6 +144,7 @@\n             [3, 7]]])\n \n     \"\"\"\n+    a = astensor(a)\n     axis1 = validate_axis(a.ndim, axis1)\n     axis2 = validate_axis(a.ndim, axis2)\n", "issue": "[BUG] Cannot pass numpy array into mt.swapaxes\n<!--\r\nThank you for your contribution!\r\n\r\nPlease review https://github.com/mars-project/mars/blob/master/CONTRIBUTING.rst before opening an issue.\r\n-->\r\n\r\n## Describe the bug\r\nI met a bug when i passed numpy array into `mt.swapaxes`. See below:\r\n```\r\nIn [35]: p = np.random.rand(3,4,5)                                                                                                                                                                   \r\n\r\nIn [36]: mt.swapaxes(p, 0, -1)                                                                                                                                                                       \r\n---------------------------------------------------------------------------\r\nAttributeError                            Traceback (most recent call last)\r\n<ipython-input-36-016cb9916fdb> in <module>\r\n----> 1 mt.swapaxes(p, 0, -1)\r\n\r\n~/anaconda3/envs/pymars0.6/lib/python3.7/site-packages/mars/tensor/base/swapaxes.py in swapaxes(a, axis1, axis2)\r\n    150         return a\r\n    151 \r\n--> 152     op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())\r\n    153     return op(a)\r\n\r\nAttributeError: 'numpy.ndarray' object has no attribute 'issparse'\r\n```\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n# Copyright 1999-2020 Alibaba Group Holding Ltd.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom ... import opcodes as OperandDef\nfrom ...serialize import KeyField, Int32Field\nfrom ..utils import validate_axis, reverse_order\nfrom ..operands import TensorHasInput, TensorOperandMixin\nfrom ..array_utils import as_same_device, device\nfrom ..core import TensorOrder\n\n\ndef _swap(it, axis1, axis2):\n    new_it = list(it)\n    new_it[axis1], new_it[axis2] = it[axis2], it[axis1]\n\n    return tuple(new_it)\n\n\nclass TensorSwapAxes(TensorHasInput, TensorOperandMixin):\n    _op_type_ = OperandDef.SWAPAXES\n\n    _input = KeyField('input')\n    _axis1 = Int32Field('axis1')\n    _axis2 = Int32Field('axis2')\n\n    def __init__(self, axis1=None, axis2=None, dtype=None, sparse=False, **kw):\n        super().__init__(_axis1=axis1, _axis2=axis2, _dtype=dtype, _sparse=sparse,\n                         _create_view=True, **kw)\n\n    @property\n    def axis1(self):\n        return self._axis1\n\n    @property\n    def axis2(self):\n        return self._axis2\n\n    def __call__(self, a):\n        axis1, axis2 = self._axis1, self._axis2\n        if (axis1 == 0 and axis2 == a.ndim - 1) or (axis1 == a.ndim - 1 and axis2 == 0):\n            tensor_order = reverse_order(a.order)\n        else:\n            tensor_order = TensorOrder.C_ORDER\n        shape = _swap(a.shape, self.axis1, self.axis2)\n        return self.new_tensor([a], shape, order=tensor_order)\n\n    def _set_inputs(self, inputs):\n        super()._set_inputs(inputs)\n        self._input = self._inputs[0]\n\n    def on_output_modify(self, new_output):\n        op = TensorSwapAxes(axis1=self._axis2, axis2=self._axis1, dtype=new_output.dtype,\n                            sparse=new_output.issparse())\n        return op(new_output)\n\n    def on_input_modify(self, new_input):\n        op = self.copy().reset_key()\n        return op(new_input)\n\n    @classmethod\n    def tile(cls, op):\n        axis1, axis2 = op.axis1, op.axis2\n        in_tensor = op.inputs[0]\n        out_tensor = op.outputs[0]\n\n        out_chunks = []\n        for c in in_tensor.chunks:\n            chunk_shape = _swap(c.shape, axis1, axis2)\n            chunk_idx = _swap(c.index, axis1, axis2)\n            chunk_op = op.copy().reset_key()\n            out_chunk = chunk_op.new_chunk([c], shape=chunk_shape,\n                                           index=chunk_idx, order=out_tensor.order)\n            out_chunks.append(out_chunk)\n\n        new_op = op.copy()\n        nsplits = _swap(in_tensor.nsplits, axis1, axis2)\n        return new_op.new_tensors([in_tensor], out_tensor.shape, order=out_tensor.order,\n                                  chunks=out_chunks, nsplits=nsplits)\n\n    @classmethod\n    def execute(cls, ctx, op):\n        (x,), device_id, xp = as_same_device(\n            [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True)\n\n        axis1, axis2 = op.axis1, op.axis2\n        with device(device_id):\n            ctx[op.outputs[0].key] = xp.swapaxes(x, axis1, axis2)\n\n\ndef swapaxes(a, axis1, axis2):\n    \"\"\"\n    Interchange two axes of a tensor.\n\n    Parameters\n    ----------\n    a : array_like\n        Input tensor.\n    axis1 : int\n        First axis.\n    axis2 : int\n        Second axis.\n\n    Returns\n    -------\n    a_swapped : Tensor\n        If `a` is a Tensor, then a view of `a` is\n        returned; otherwise a new tensor is created.\n\n    Examples\n    --------\n    >>> import mars.tensor as mt\n\n    >>> x = mt.array([[1,2,3]])\n    >>> mt.swapaxes(x,0,1).execute()\n    array([[1],\n           [2],\n           [3]])\n\n    >>> x = mt.array([[[0,1],[2,3]],[[4,5],[6,7]]])\n    >>> x.execute()\n    array([[[0, 1],\n            [2, 3]],\n           [[4, 5],\n            [6, 7]]])\n\n    >>> mt.swapaxes(x,0,2).execute()\n    array([[[0, 4],\n            [2, 6]],\n           [[1, 5],\n            [3, 7]]])\n\n    \"\"\"\n    axis1 = validate_axis(a.ndim, axis1)\n    axis2 = validate_axis(a.ndim, axis2)\n\n    if axis1 == axis2:\n        return a\n\n    op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())\n    return op(a)\n", "path": "mars/tensor/base/swapaxes.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n# Copyright 1999-2020 Alibaba Group Holding Ltd.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom ... import opcodes as OperandDef\nfrom ...serialize import KeyField, Int32Field\nfrom ..array_utils import as_same_device, device\nfrom ..core import TensorOrder\nfrom ..datasource import tensor as astensor\nfrom ..operands import TensorHasInput, TensorOperandMixin\nfrom ..utils import validate_axis, reverse_order\n\n\ndef _swap(it, axis1, axis2):\n    new_it = list(it)\n    new_it[axis1], new_it[axis2] = it[axis2], it[axis1]\n\n    return tuple(new_it)\n\n\nclass TensorSwapAxes(TensorHasInput, TensorOperandMixin):\n    _op_type_ = OperandDef.SWAPAXES\n\n    _input = KeyField('input')\n    _axis1 = Int32Field('axis1')\n    _axis2 = Int32Field('axis2')\n\n    def __init__(self, axis1=None, axis2=None, dtype=None, sparse=False, **kw):\n        super().__init__(_axis1=axis1, _axis2=axis2, _dtype=dtype, _sparse=sparse,\n                         _create_view=True, **kw)\n\n    @property\n    def axis1(self):\n        return self._axis1\n\n    @property\n    def axis2(self):\n        return self._axis2\n\n    def __call__(self, a):\n        axis1, axis2 = self._axis1, self._axis2\n        if (axis1 == 0 and axis2 == a.ndim - 1) or (axis1 == a.ndim - 1 and axis2 == 0):\n            tensor_order = reverse_order(a.order)\n        else:\n            tensor_order = TensorOrder.C_ORDER\n        shape = _swap(a.shape, self.axis1, self.axis2)\n        return self.new_tensor([a], shape, order=tensor_order)\n\n    def _set_inputs(self, inputs):\n        super()._set_inputs(inputs)\n        self._input = self._inputs[0]\n\n    def on_output_modify(self, new_output):\n        op = TensorSwapAxes(axis1=self._axis2, axis2=self._axis1, dtype=new_output.dtype,\n                            sparse=new_output.issparse())\n        return op(new_output)\n\n    def on_input_modify(self, new_input):\n        op = self.copy().reset_key()\n        return op(new_input)\n\n    @classmethod\n    def tile(cls, op):\n        axis1, axis2 = op.axis1, op.axis2\n        in_tensor = op.inputs[0]\n        out_tensor = op.outputs[0]\n\n        out_chunks = []\n        for c in in_tensor.chunks:\n            chunk_shape = _swap(c.shape, axis1, axis2)\n            chunk_idx = _swap(c.index, axis1, axis2)\n            chunk_op = op.copy().reset_key()\n            out_chunk = chunk_op.new_chunk([c], shape=chunk_shape,\n                                           index=chunk_idx, order=out_tensor.order)\n            out_chunks.append(out_chunk)\n\n        new_op = op.copy()\n        nsplits = _swap(in_tensor.nsplits, axis1, axis2)\n        return new_op.new_tensors([in_tensor], out_tensor.shape, order=out_tensor.order,\n                                  chunks=out_chunks, nsplits=nsplits)\n\n    @classmethod\n    def execute(cls, ctx, op):\n        (x,), device_id, xp = as_same_device(\n            [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True)\n\n        axis1, axis2 = op.axis1, op.axis2\n        with device(device_id):\n            ctx[op.outputs[0].key] = xp.swapaxes(x, axis1, axis2)\n\n\ndef swapaxes(a, axis1, axis2):\n    \"\"\"\n    Interchange two axes of a tensor.\n\n    Parameters\n    ----------\n    a : array_like\n        Input tensor.\n    axis1 : int\n        First axis.\n    axis2 : int\n        Second axis.\n\n    Returns\n    -------\n    a_swapped : Tensor\n        If `a` is a Tensor, then a view of `a` is\n        returned; otherwise a new tensor is created.\n\n    Examples\n    --------\n    >>> import mars.tensor as mt\n\n    >>> x = mt.array([[1,2,3]])\n    >>> mt.swapaxes(x,0,1).execute()\n    array([[1],\n           [2],\n           [3]])\n\n    >>> x = mt.array([[[0,1],[2,3]],[[4,5],[6,7]]])\n    >>> x.execute()\n    array([[[0, 1],\n            [2, 3]],\n           [[4, 5],\n            [6, 7]]])\n\n    >>> mt.swapaxes(x,0,2).execute()\n    array([[[0, 4],\n            [2, 6]],\n           [[1, 5],\n            [3, 7]]])\n\n    \"\"\"\n    a = astensor(a)\n    axis1 = validate_axis(a.ndim, axis1)\n    axis2 = validate_axis(a.ndim, axis2)\n\n    if axis1 == axis2:\n        return a\n\n    op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())\n    return op(a)\n", "path": "mars/tensor/base/swapaxes.py"}]}