Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 8 | # not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | |
| 19 | |
| 20 | # Simple example of the usage of mlw_codec. |
| 21 | |
| 22 | import sys |
| 23 | |
| 24 | from ethosu import mlw_codec |
| 25 | |
| 26 | |
| 27 | # Simple example |
| 28 | if __name__ == "__main__": |
| 29 | weights = [0, 2, 3, 0, -1, -2, -3, 0, 0, 0, 1, -250, 240] * 3 |
| 30 | print("Original weights :", weights) |
| 31 | |
| 32 | compressed_weights = mlw_codec.encode(weights) |
| 33 | print("Compressed weights :", len(compressed_weights), compressed_weights) |
| 34 | |
| 35 | uncompressed_weights = mlw_codec.decode(compressed_weights) |
| 36 | print("Uncompressed weights:", uncompressed_weights) |
| 37 | |
| 38 | if weights != uncompressed_weights: |
| 39 | print("TEST FAILED") |
| 40 | sys.exit(1) |
| 41 | else: |
| 42 | print("TEST PASSED") |
| 43 | sys.exit(0) |