test_hash_op.py 2.5 KB
Newer Older
M
minqiyang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

import unittest
import numpy as np
from op_test import OpTest


class TestScaleOp(OpTest):
    def setUp(self):
        self.op_type = "hash"
        self.init_test_case()
        self.inputs = {'X': (self.in_seq, self.lod)}
M
minqiyang 已提交
25
        self.attrs = {'num_hash': 4, 'mod_by': 10000}
M
minqiyang 已提交
26 27 28
        self.outputs = {'Out': (self.out_seq, self.lod)}

    def init_test_case(self):
M
minqiyang 已提交
29
        np.random.seed = 1
M
minqiyang 已提交
30 31
        self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32")
        self.lod = [[9, 4, 11, 6]]
M
minqiyang 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        #  self.out_seq = np.ones([30, 4, 1], dtype=np.int32)
        self.out_seq = [
            [[9662], [9217], [1129], [8487]], [[9662], [9217], [1129], [8487]],
            [[8310], [1327], [1654], [4567]], [[6897], [3218], [2013], [1241]],
            [[9407], [6715], [6949], [8094]], [[8473], [694], [5142], [2479]],
            [[8310], [1327], [1654], [4567]], [[6897], [3218], [2013], [1241]],
            [[4372], [9456], [8204], [6695]], [[6897], [3218], [2013], [1241]],
            [[8473], [694], [5142], [2479]], [[4372], [9456], [8204], [6695]],
            [[4372], [9456], [8204], [6695]], [[8473], [694], [5142], [2479]],
            [[9407], [6715], [6949], [8094]], [[9369], [4525], [8935], [9210]],
            [[4372], [9456], [8204], [6695]], [[4372], [9456], [8204], [6695]],
            [[9369], [4525], [8935], [9210]], [[6897], [3218], [2013], [1241]],
            [[9038], [7951], [5953], [8657]], [[9407], [6715], [6949], [8094]],
            [[9662], [9217], [1129], [8487]], [[9369], [4525], [8935], [9210]],
            [[9038], [7951], [5953], [8657]], [[9662], [9217], [1129], [8487]],
            [[9369], [4525], [8935], [9210]], [[1719], [5986], [9919], [3421]],
            [[4372], [9456], [8204], [6695]], [[9038], [7951], [5953], [8657]]
        ]
        self.out_seq = np.array(self.out_seq)
M
minqiyang 已提交
51 52 53 54 55 56 57

    def test_check_output(self):
        self.check_output()


if __name__ == "__main__":
    unittest.main()