• 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 Dense """
16import numpy as np
17
18import mindspore.nn as nn
19from mindspore import Tensor
20from ..ut_filter import non_graph_engine
21
22
23class Net(nn.Cell):
24    """Net definition"""
25
26    def __init__(self,
27                 input_channels,
28                 output_channels,
29                 weight='normal',
30                 bias='zeros',
31                 has_bias=True):
32        super(Net, self).__init__()
33        self.fc = nn.Dense(input_channels,
34                           output_channels,
35                           weight,
36                           bias,
37                           has_bias)
38
39    def construct(self, input_x):
40        return self.fc(input_x)
41
42
43@non_graph_engine
44def test_compile():
45    weight = Tensor(np.ones([12, 8], np.float32))
46    bias = Tensor(np.ones([12], np.float32))
47    net = Net(8, 12, weight=weight, bias=bias)
48    input_data = Tensor(np.ones([1, 8], np.float32))
49    # since simulator currently not support matMul
50    output = net(input_data)
51    print(output.asnumpy())
52
53
54@non_graph_engine
55def test_compile_nobias():
56    weight = Tensor(np.ones([12, 8], np.float32))
57    net = Net(8, 12, weight=weight, has_bias=False)
58    input_data = Tensor(np.ones([1, 8], np.float32))
59    # since simulator currently not support matMu
60    # enable it when staging function is ready
61    output = net(input_data)
62    print(output.asnumpy())
63