ashvardanian / SimSIMD

Up to 200x Faster Dot Products & Similarity Metrics — for Python, Rust, C, JS, and Swift, supporting f64, f32, f16 real & complex, i8, and bit vectors using SIMD for both AVX2, AVX-512, NEON, SVE, & SVE2 📐
https://ashvardanian.com/posts/simsimd-faster-scipy/
Apache License 2.0
988 stars 59 forks source link

Bug: README example rejected by mypy (incompatible type "ndarray[...]"; expected "memoryview") #171

Closed pquentin closed 2 months ago

pquentin commented 2 months ago

Describe the bug

With SimSIMD 5.1.1, mypy reject the example from the README. SimSIMD 5.1.0 works fine.

Steps to reproduce

Install numpy, SimSIMD and mypy:

pip install numpy simsimd mypy

Write to this file (straight from the README):

import simsimd
import numpy as np

vec1 = np.random.randn(1536).astype(np.float32)
vec2 = np.random.randn(1536).astype(np.float32)
dist = simsimd.cosine(vec1, vec2)

Run mypy on that file:

t.py:6: error: Argument 1 to "cosine" has incompatible type "ndarray[Any, dtype[floating[_32Bit]]]"; expected "memoryview"  [arg-type]
t.py:6: error: Argument 2 to "cosine" has incompatible type "ndarray[Any, dtype[floating[_32Bit]]]"; expected "memoryview"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Expected behavior

No error.

SimSIMD version

5.1.1

Operating System

Ubuntu, Fedora, macOS

Hardware architecture

x86

Which interface are you using?

Python bindings

Contact Details

No response

Are you open to being tagged as a contributor?

Is there an existing issue for this?

Code of Conduct

ashvardanian commented 2 months ago

Hey, @pquentin! Seems like when the .pyi file isn’t properly evaluated and we have to keep NumPy arrays as part of the union. Patching now 🤗