jverma-quic commented on code in PR #12340: URL: https://github.com/apache/tvm/pull/12340#discussion_r950284384
########## tests/python/contrib/test_hexagon/test_fixed_point_conversion.py: ########## @@ -0,0 +1,58 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 math +import struct +import numpy as np +import tvm.topi.hexagon.utils as utils + +""" +Test float to fixed-point conversion. We do it by constructing a numpy array with the +wide range of floating-point values. These values are converted into the +fixed-point value using topi.hexagon.utils.get_fixed_point_value. Then, these values are +converted back into float using scale_factor provided by the function. These converted +floating point values are then compared against the original values and an assertion is +raised if they happened to be outside of the expected tolerance. +""" + + +class TestFixedPointConversion: + def test_fixed_point_conversion(self): + # Construct array with wide range of values + fp1 = np.random.uniform(0.00001, 0.0002, size=(10)) + fp2 = np.random.uniform(0.001, 0.02, size=(10)) + fp3 = np.random.uniform(1, 20, size=(10)) + fp4 = np.random.uniform(900, 1000, size=(10)) + fp5 = np.random.uniform(1e9, 1e10, size=(10)) + fp6 = np.random.uniform(2.44885652993e38, 2.54885652993e38, size=(1)) + fp7 = np.random.uniform(1.46711479073e-34, 1.76098837843e-34, size=(1)) Review Comment: The numbers don't really mean anything but I just wanted to test with some very large and small floating-point values to make sure that the conversion function is handling them properly, i.e., doesn't introduce large error. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
