|
| 1 | +# Copyright 2020 The AutoKeras Authors. |
| 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 | +import numpy as np |
| 16 | +import pytest |
| 17 | + |
| 18 | +from autokeras.engine.analyser import Analyser |
| 19 | + |
| 20 | + |
| 21 | +def test_analyser_update_unicode_string_dtype(): |
| 22 | + analyser = Analyser() |
| 23 | + data = np.array(["hello", "world"], dtype="U10") |
| 24 | + |
| 25 | + analyser.update(data) |
| 26 | + |
| 27 | + assert analyser.dtype == "string" |
| 28 | + assert analyser.shape == [2] |
| 29 | + assert analyser.batch_size == 2 |
| 30 | + assert analyser.num_samples == 2 |
| 31 | + |
| 32 | + |
| 33 | +def test_analyser_update_byte_string_dtype(): |
| 34 | + analyser = Analyser() |
| 35 | + data = np.array([b"hello", b"world"], dtype="S10") |
| 36 | + |
| 37 | + analyser.update(data) |
| 38 | + |
| 39 | + assert analyser.dtype == "string" |
| 40 | + assert analyser.shape == [2] |
| 41 | + assert analyser.batch_size == 2 |
| 42 | + assert analyser.num_samples == 2 |
| 43 | + |
| 44 | + |
| 45 | +def test_analyser_update_numeric_dtype(): |
| 46 | + analyser = Analyser() |
| 47 | + data = np.array([1, 2, 3], dtype=np.int32) |
| 48 | + |
| 49 | + analyser.update(data) |
| 50 | + |
| 51 | + assert analyser.dtype == "int32" |
| 52 | + assert analyser.shape == [3] |
| 53 | + assert analyser.batch_size == 3 |
| 54 | + assert analyser.num_samples == 3 |
| 55 | + |
| 56 | + |
| 57 | +def test_analyser_update_float_dtype(): |
| 58 | + analyser = Analyser() |
| 59 | + data = np.array([1.0, 2.0, 3.0], dtype=np.float64) |
| 60 | + |
| 61 | + analyser.update(data) |
| 62 | + |
| 63 | + assert analyser.dtype == "float64" |
| 64 | + assert analyser.shape == [3] |
| 65 | + assert analyser.batch_size == 3 |
| 66 | + assert analyser.num_samples == 3 |
| 67 | + |
| 68 | + |
| 69 | +def test_analyser_finalize_not_implemented(): |
| 70 | + analyser = Analyser() |
| 71 | + |
| 72 | + with pytest.raises(NotImplementedError): |
| 73 | + analyser.finalize() |
0 commit comments