Giter Site home page Giter Site logo

bwoodsend / hirola Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 0.0 241 KB

NumPy vectorized hash table for fast set and dict operations.

Home Page: https://hirola.readthedocs.io/

License: MIT License

Python 83.73% C 14.11% Dockerfile 2.16%
dict hashtable numpy python set

hirola's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hirola's Issues

Performance

  • Hirola version: 0.2.1
  • Python version: 3.9.6
  • Operating System: Linux 5.13.12-arch1-1

Description

Hi,

this library looks really cool and to be a perfect fit for my purposes, I wonder why it didn't have any stars so far.

I was hoping to use it as a more lightweight replacement for pandas.Categorical, however I noticed that it is seems to be comparably slow for some reason. I was wondering whether some of the strategies employed in pandas could be adapted to speed up this library as well?

What I Did

Performance comparison between pandas.Categorical(...).codes and hirola.HashTable.get:

from timeit import timeit
import hirola
import numpy as np
import pandas as pd
import string


def generate_strings(count, min_len, max_len):
    words = np.random.choice(
        list(string.ascii_letters),
        (count, max_len)
    ).view((str, max_len)).reshape(-1)
    lengths = np.random.choice(np.arange(min_len, max_len + 1), count)
    return np.array([
        word[:length]
        for word, length in zip(words, lengths)
    ])


# Generate some strings to chose from
all_strings = generate_strings(1000, 5, 15)
known = np.random.choice(all_strings, 500, replace=False)
sought = np.random.choice(all_strings, 500, replace=False)
sought = np.random.choice(sought, 10000)

tab = hirola.HashTable(len(known), known.dtype)
tab.add(known)

print("hirola", timeit(lambda: tab.get(sought), number=100))
print("pandas", timeit(
    lambda: pd.Categorical(sought, categories=known).codes,
    number=100,
))

# Check that both methods actually yield the same results:
np.testing.assert_equal(
    tab.get(sought),
    pd.Categorical(sought, categories=known).codes)

Output:

hirola 2.799455799000498
pandas 0.12548323099872505

I didn't investigate the reason (vectorization, hash/search algorithm/...?)

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.