semvec/pypi-packages huggingface dataset:
lshash3 0.0.8
A fast Python implementation of locality sensitive hashing with persistance (Redis) support.
License: MIT

======
LSHash
======

:Version: 0.0.4dev

A fast Python implementation of locality sensitive hashing with persistance
support.

Highlights
==========

- Fast hash calculation for large amount of high dimensional data through the use of `numpy` arrays.
- Built-in support for persistency through Redis.
- Multiple hash indexes support.
- Built-in support for common distance/objective functions for ranking outputs.

Installation
============
``LSHash`` depends on the following libraries:

- numpy
- redis (if persistency through Redis is needed)
- bitarray (if hamming distance is used as distance function)

To install:

.. code-block:: bash

    $ pip install lshash

Quickstart
==========
To create 6-bit hashes for input data of 8 dimensions:

.. code-block:: python

    >>> from lshash import LSHash

    >>> lsh = LSHash(6, 8)
    >>> lsh.index([1,2,3,4,5,6,7,8])
    >>> lsh.index([2,3,4,5,6,7,8,9])
    >>> lsh.index([10,12,99,1,5,31,2,3])
    >>> lsh.query([1,2,3,4,5,6,7,7])
    [((1, 2, 3, 4, 5, 6, 7, 8), 1.0),
     ((2, 3, 4, 5, 6, 7, 8, 9), 11)]


Main Interface
==============

- To initialize a ``LSHash`` instance:

.. code-block:: python

    LSHash(hash_size, input_dim, num_of_hashtables=1, storage=None, matrices_filename=None, overwrite=False)

parameters:

``hash_size``:
    The length of the resulting binary hash.
``input_dim``:
    The dimension of the input vector.
``num_hashtables = 1``:
    (optional) The number of hash tables used for multiple lookups.
``storage = None``:
    (optional) Specify the name of the storage to be used for the index
    storage. Options include "redis".
``matrices_filename = None``:
    (optional) Specify the path to the .npz file random matrices are stored
    or to be stored if the file does not exist yet
``overwrite = False``:
    (optional) Whether to overwrite the matrices file if it already exist

- To index a data point of a given ``LSHash`` instance, e.g., ``lsh``:

.. code-block:: python

    lsh.index(input_point, extra_data=None):

parameters:

``input_point``:
    The input data point is an array or tuple of numbers of input_dim.
``extra_data = None``:
    (optional) Extra data to be added along with the input_point.

- To query a data point against a given ``LSHash`` instance, e.g., ``lsh``:

.. code-block:: python

    lsh.query(query_point, num_results=None, distance_func="euclidean"):

parameters:

``query_point``:
    The query data point is an array or tuple of numbers of input_dim.
``num_results = None``:
    (optional) The number of query results to return in ranked order. By
    default all results will be returned.
``distance_func = "euclidean"``:
    (optional) Distance function to use to rank the candidates. By default
    euclidean distance function will be used.
serialstruct 1.1.0
Implements a StructuredPacket for pySerial's serial.threaded module
License: MIT

============
serialstruct
============

|build-status| |pypi|

Installation
============

.. code-block:: bash

        $ pip install serialstruct


Motivation
==========
When sending a structured binary packet over Serial, the only way (that I'm aware
of) to guarantee packet alignment with arbitrary data is to send a header that's
larger than any of the elements and add padding between each element. Here's an
example:

.. code-block:: c

        struct Packet {
                int sensor1;
                int sensor2;
        }

If we send this over the wire and start reading at an arbitrary time, it's
impossible to know what byte of the packet we're reading. To mitigate this we can
add a header and some padding.

.. code-block:: c

        struct Packet {
                char header[5]; // Any sequence without a '\0'
                int sensor1;
                char pad1;      // '\0'
                int sensor2;
                char pad2;      // '\0'
        }

Now we just need to wait until the header sequence is read and we can consume the
rest of the packet without worrying about alignment.

pySerial only implements a FramedPacket which expects a unicode sequence that
starts with a '(' (0x28) and ends with a ')' (0x29). This means the bytes 0x28 and
0x29 cannot appear anywhere in the binary data.

Usage
=====
Subclass ``serialstruct.StructuredPacket`` to specify the data size in the packet
and to implement the ``handle_packet()`` callback function.

.. code-block:: python

        import struct

        import serial
        import serialstruct
        import time


        PACKET_STRUCT = struct.Struct("<IxIx")

        class MyPacket(serialstruct.StructuredPacket):

            DATA_SIZE = 10 # Excluding header: 4+1+4+1

            def __init__(self):
                super(MyPacket, self).__init__(self.DATA_SIZE)

            def handle_packet(self, packet):
                print(PACKET_STRUCT.unpack(packet))

            def send_packet(self, packet):
                self.transport.write(self.HEADER)
                self.transport.write(packet)


        ser = serial.serial_for_url("loop://", baudrate=115200, timeout=1)
        with serial.threaded.ReaderThread(ser, MyPacket) as protocol:
            # unsigned int, pad, unsigned int, pad; with no alignment
            packet = PACKET_STRUCT.pack(1, 2)
            protocol.send_packet(packet)
            time.sleep(1)

Prints:

.. code-block:: bash

        (1, 2)


.. |build-status| image:: https://travis-ci.org/eoswald/serialstruct.svg?branch=master

.. |pypi| image:: https://img.shields.io/pypi/v/serialstruct.svg?style=flat-square&label=latest%20stable%20version
    :target: https://pypi.python.org/pypi/serialstruct
    :alt: Latest version released on PyPi