• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15""" test_mean """
16import mindspore as ms
17from mindspore import nn
18from mindspore import context
19
20context.set_context(mode=context.GRAPH_MODE)
21
22
23def test_mean():
24    class Net(nn.Cell):
25        def __init__(self):
26            super().__init__()
27            self.value = ms.Tensor([[1, 2, 3], [4, 5, 6]], dtype=ms.float32)
28
29        def construct(self):
30            return self.value.mean()
31
32    net = Net()
33    net()
34
35
36def test_mean_axis():
37    class Net(nn.Cell):
38        def __init__(self):
39            super().__init__()
40            self.value = ms.Tensor([[1, 2, 3], [4, 5, 6]], dtype=ms.float32)
41
42        def construct(self):
43            return self.value.mean(axis=1)
44
45    net = Net()
46    net()
47
48
49def test_mean_parameter():
50    class Net(nn.Cell):
51        def __init__(self):
52            super().__init__()
53
54        def construct(self, x):
55            return x.mean()
56
57    x = ms.Tensor([[1, 2, 3], [1, 2, 3]], dtype=ms.float32)
58    net = Net()
59    net(x)
60
61
62def test_mean_parameter_axis():
63    class Net(nn.Cell):
64        def __init__(self):
65            super().__init__()
66
67        def construct(self, x):
68            return x.mean(axis=1)
69
70    x = ms.Tensor([[1, 2, 3], [1, 2, 3]], dtype=ms.float32)
71    net = Net()
72    net(x)
73