GithubHelp home page GithubHelp logo

hasenpfote / fpq Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 541 KB

This python package provides modules for manipulating floating-points quantization.

License: MIT License

Python 75.27% Makefile 1.51% Batchfile 0.46% Jupyter Notebook 22.76%
python floating-point quantization quaternion

fpq's Introduction

License Build Status PyPI version Pyversions

fpq

About

This package provides modules for manipulating floating point numbers quantization using NumPy.

Feature

  • Supports multidimensional arrays.
  • Supports encoding and decoding between 64/32/16-bits floating point numbers and N-bits unsigned normalized integers.
  • Supports encoding and decoding between 64/32/16-bits floating point numbers and N-bits signed normalized integers.
  • Supports encoding and decoding between 3d-vectors and N-bits unsigned integers.
  • Supports encoding and decoding between Quaternions and N-bits unsigned integers.

Compatibility

fpq works with Python 3.4 or higher.

Dependencies

  • NumPy
  • Numba

Installation

pip install fpq

Usage

encoding and decoding between 32-bits floating point numbers and 5-bits unsigned normalized integers.

>>> import numpy as np
>>> from fpq.fp import *
>>> fp = np.array([0., 0.25, 1.], dtype=np.float32)
>>> enc = encode_fp_to_std_unorm(fp, dtype=np.uint8, nbits=5)
>>> enc
array([ 0,  8, 31], dtype=uint8)
>>> dec = decode_std_unorm_to_fp(enc, dtype=np.float32, nbits=5)
>>> dec
array([0.       , 0.2580645, 1.       ], dtype=float32)

encoding and decoding between 32-bits floating point numbers and 5-bits signed normalized integers.

>>> import numpy as np
>>> from fpq.fp import *
>>> fp = np.array([-1., -0.25, -0., 0., 0.25, 1.], dtype=np.float32)
>>> enc = encode_fp_to_std_snorm(fp, dtype=np.uint8, nbits=5)
>>> enc
array([31,  9,  1,  0,  8, 30], dtype=uint8)
>>> dec = decode_std_snorm_to_fp(enc, dtype=np.float32, nbits=5)
>>> dec
array([-1.        , -0.26666668, -0.        ,  0.        ,  0.26666668,
        1.        ], dtype=float32)
>>> enc = encode_fp_to_ogl_snorm(fp, dtype=np.uint8, nbits=5)
>>> enc
array([17, 28,  0,  0,  4, 15], dtype=uint8)
>>> dec = decode_ogl_snorm_to_fp(enc, dtype=np.float32, nbits=5)
>>> dec
array([-1.        , -0.26666668,  0.        ,  0.        ,  0.26666668,
        1.        ], dtype=float32)

encoding and decoding between 3d-vectors and 64-bits(2:20:20:22) unsigned integers.

>>> import math
>>> import random
>>> import numpy as np
>>> from fpq.vector import *
>>> v = np.array([vec_random(norm=100.) for _ in range(3)], dtype=np.float64)
>>> v
array([[-54.70386501, -22.45578546, -52.18237577],
       [-85.46791152,  -5.69032986,   1.21334561],
       [ 16.02886205,   1.94634654, -30.35219431]])
>>> enc = encode_vec_to_uint(v, dtype=np.uint64, nbits=20)
>>> enc
array([ 1313110064653969262,   306332797892602581, 11373476070061802081],
      dtype=uint64)
>>> dec = decode_uint_to_vec(enc, dtype=np.float64, nbits=20)
>>> dec
array([[-54.69957531, -22.45404536, -52.17828412],
       [-85.4662517 ,  -5.69027392,   1.21334561],
       [ 16.02845595,   1.94632843, -30.3514349 ]])

encoding and decoding between Quaternions and 64-bits(2:20:20:20) unsigned integers.

>>> import numpy as np
>>> from fpq.quaternion import *
>>> q = np.array([quat_random() for _ in range(3)], dtype=np.float64)
>>> q
array([[ 0.25679071, -0.15512517,  0.88804262,  0.34838917],
       [ 0.71399177,  0.05729705, -0.69728753, -0.02688697],
       [-0.66527338, -0.62596543, -0.40672262, -0.01246296]])
>>> enc = encode_quat_to_uint(q, dtype=np.uint64)
>>> enc
array([2724532880236077588,   93422189206870975, 1020620101889574962],
      dtype=uint64)
>>> dec = decode_uint_to_quat(enc, dtype=np.float64)
>>> dec
array([[ 0.25679011, -0.15512497,  0.88804308,  0.34838854],
       [ 0.71399243,  0.0572969 , -0.69728688, -0.02688637],
       [ 0.66527395,  0.62596484,  0.40672258,  0.01246335]])

Here are a few examples.

Documentation

For users, docs are now available at https://hasenpfote.github.io/fpq/.

References and links

D3D: Data Conversion Rules OGL: Normalized Integer Vulkan: Fixed-Point Data Conversions

License

This software is released under the MIT License, see LICENSE.

fpq's People

Contributors

hasenpfote avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.