list add list
This commit is contained in:
commit
76b884dea9
|
@ -179,6 +179,23 @@ def _tensor_add_list(x, y):
|
|||
return F.tensor_add(x, y)
|
||||
|
||||
|
||||
@add.register("List", "List")
|
||||
def _list_add_list(x, y):
|
||||
"""
|
||||
list is added to list.
|
||||
|
||||
Args:
|
||||
x (list): x
|
||||
y (list): y.
|
||||
|
||||
Returns:
|
||||
list, has the same dtype as x.
|
||||
"""
|
||||
for i in y:
|
||||
x.append(i)
|
||||
return x
|
||||
|
||||
|
||||
@add.register("Tensor", "Tensor")
|
||||
def _tensor_add_tensor(x, y):
|
||||
"""
|
||||
|
|
|
@ -134,7 +134,7 @@ class TestProfiler:
|
|||
""" Run after class end."""
|
||||
cleanup()
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_gpu_profiler(self):
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
""" test list add list """
|
||||
|
||||
import numpy as np
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
from mindspore import context
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def __init__(self):
|
||||
super(Net, self).__init__()
|
||||
self.value1 = [Tensor([1, 2, 3]), Tensor([4, 5, 6])]
|
||||
self.value2 = [Tensor([7, 8, 9]), Tensor([10, 11, 12])]
|
||||
|
||||
def construct(self):
|
||||
return self.value1 + self.value2
|
||||
|
||||
def test_list_add_list():
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
net = Net()
|
||||
expect_ret = (Tensor([1, 2, 3]), Tensor([4, 5, 6]), Tensor([7, 8, 9]), Tensor([10, 11, 12]))
|
||||
for i in range(len(net())):
|
||||
assert (np.array_equal(net()[i].asnumpy(), expect_ret[i].asnumpy()))
|
Loading…
Reference in New Issue