Skip to main content

Python bindings for the Hsdlib library

Project description

HsdPy

License: MIT Python version PyPI version

HsdPy library allows users to use Hsdlib in Python.

Installation

pip install hsdpy

Examples

Below is a simple usage example of HsdPy:

import hsdpy

# HsdPy uses NumPy for array handling
import numpy as np

# Create two NumPy arrays of float32 type
a = np.array([1.0, 2.0, 3.0], dtype=np.float32)
b = np.array([4.0, 5.0, 6.0], dtype=np.float32)

# Calculate the euclidean distance between the two arrays
dist_euc = hsdpy.dist_sqeuclidean_f32(a, b) ** 0.5

# Calculate Manhattan distance
dist_man = hsdpy.dist_manhattan_f32(a, b)

# Let's see the results
print(f"Euclidean distance: {dist_euc}")  # 5.196
print(f"Manhattan distance: {dist_man}")  # 9.0

# See the SIMD backend in use
print(f"Backend: {hsdpy.get_backend()}")

Check out hsdpy_example.py for more detailed examples.

API Summary

Function Description Input Types (np.ndarray) Return Type
dist_sqeuclidean_f32(a, b) Computes squared Euclidean distance between vectors. np.float32 float
dist_manhattan_f32(a, b) Computes Manhattan distance between vectors. np.float32 float
dist_hamming_u8(a, b) Computes Hamming distance between binary vectors. np.uint8 int
sim_dot_f32(a, b) Computes dot product between vectors. np.float32 float
sim_cosine_f32(a, b) Computes cosine similarity between vectors. np.float32 float
sim_jaccard_u16(a, b) Computes Jaccard similarity between integer vectors. np.uint16 float
get_backend() Returns information about the backend in use. None str
get_library_info() Returns information about the loaded library. None dict

Notes

  • HsdPy provides the HsdError exception class for error handling. It is a custom exception class wraps the Hsdlib error codes to make them more Pythonic.
  • All distance and similarity functions expect one-dimensional NumPy arrays as input.
  • Functions will raise NotImplementedError if the corresponding Hsdlib function is not implemented for the given data type.

License

HsdPy is licensed under the MIT 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hsdpy-0.1.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file hsdpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hsdpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for hsdpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e2a077111bd283c5681e13813468e79b966194d72e36e94f870926b6aa877cd
MD5 92e272604800e3962bb08d9c336186aa
BLAKE2b-256 ade8f14a9ccc5dcd2537c5e5817745daf9327ff2b73c1a06d683e975a432a84e

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