Skip to main content

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

Project description

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/.

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fpq-0.10.0.tar.gz (187.6 kB view details)

Uploaded Source

Built Distribution

fpq-0.10.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file fpq-0.10.0.tar.gz.

File metadata

  • Download URL: fpq-0.10.0.tar.gz
  • Upload date:
  • Size: 187.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for fpq-0.10.0.tar.gz
Algorithm Hash digest
SHA256 c20e50a0726df67907b8606b043e305ba745b48cd7948a03d67235b8148a73b4
MD5 93dbde75eb56731533cb39b81eadd7b7
BLAKE2b-256 c6c1e04b46c867f41df591d4a4e285690bdef672892961b0ee942049f5b88eaf

See more details on using hashes here.

File details

Details for the file fpq-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: fpq-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for fpq-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1fd1eeafe3ca269245c6cef0398360ecdb87517e046032600b6b2ff5da70527
MD5 2afd7ac46e7b33f6d6028294991f31b9
BLAKE2b-256 6b68fdddd42a42c7796cb2f417611f4807f93d5a68cac1dfb4aed9b556d23bc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page