Skip to main content

Lossy-compression utility for sequence data in NumPy

Project description

lilcom

This package lossily compresses floating-point NumPy arrays into byte strings, with an accuracy specified by the user. The main anticipated use is in machine learning applications, for storing things like training data and models.

This package requires Python 3 and is not compatible with Python 2.

Installation with PyPi

From PyPi you can install this with just

pip3 install lilcom

How to use

The most common usage pattern will be as follows (showing Python code):

import numpy as np
import lilcom

a = np.random.randn(300,500)
a_compressed = lilcom.compress(a)
# a_compressed is of type `bytes`, a byte string.
# In this case it will use about 1.3 bytes per element.

# decompress a
a_decompressed = lilcom.decompress(a_compressed)

The compression is lossy so a_decompressed will not be exactly the same as a. The amount of error (absolute, not relative!) is determined by the optional tick_power argument to lilcom.compress() (default: -8), which is the power of 2 used for the step size between discretized values. The maximum error per element is 2**(tick_power-1), e.g. for tick_power=-8, it is 1/512.

Installation from Github

To install lilcom from github, first clone the repository;

git clone https://github.com/danpovey/lilcom.git

then run setup with install argument.

python3 setup.py install

(you may need to add the --user flag if you don't have system privileges). You need to make sure a C++ compiler is installed, e.g. g++ or clang. To test it, you can then cd to test and run:

python3 test_lilcom.py

Technical details

The algorithm regresses each element on the previous element (for a 1-d array) or, for general n-d arrays, it regresses on the previous elements along each of the axes, i.e. we regress element a[i,j] on a[i-1,j] and a[i,j-1]. The regression coefficients are global and written as part of the header in the string.

The elements are then integerized and the integers are compressed using an algorithm that gives good compression when successive elements tend to have about the same magnitude (the number of bits we're transmitting varies dynamically acccording to the magnitudes of the elements).

The core parts of the code are implemented in C++.

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

lilcom-1.3.tar.gz (44.1 kB view details)

Uploaded Source

File details

Details for the file lilcom-1.3.tar.gz.

File metadata

  • Download URL: lilcom-1.3.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for lilcom-1.3.tar.gz
Algorithm Hash digest
SHA256 00a3c7944e44f55390d009bdc4c6685aee1a89fa0e25dfdec8b5039c5ebc1be4
MD5 5f8474d41a8191bc2625d59929522e73
BLAKE2b-256 38149f82e7c93186eae26eaf2c4462bb08a1e234d18822e50e4356c82bb1d837

See more details on using hashes here.

Supported by

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