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