Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float64 faster than Float32 #17

Open
franz101 opened this issue Mar 9, 2024 · 2 comments
Open

Float64 faster than Float32 #17

franz101 opened this issue Mar 9, 2024 · 2 comments

Comments

@franz101
Copy link

franz101 commented Mar 9, 2024

First of all very cool library, I was looking for something like this for a while. Curious why Float64 is faster. I assume under the hood type conversion?

import polars as pl
import numpy as np

df = pl.DataFrame(
    {
        "arr": np.random.rand(100_000, 512),
        "arr2": np.random.rand(100_000, 512),
    },
    schema={
        "arr": pl.Array(inner=pl.Float64, width=512),
        "arr2": pl.Array(inner=pl.Float64, width=512),
    },
)
%%timeit
df.select(pld.col('arr').dist_arr.euclidean(pl.col("arr2")).alias('dist'))

109 ms ± 5.68 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

df = pl.DataFrame(
    {
        "arr": np.random.rand(100_000, 512),
        "arr2": np.random.rand(100_000, 512),
    },
    schema={
        "arr": pl.Array(inner=pl.Float32, width=512),
        "arr2": pl.Array(inner=pl.Float32, width=512),
    },
)

631 ms ± 11.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

@ion-elgreco
Copy link
Owner

Its always converting to f64 first, this is obviously not optimal :)

You could add a branch that works on f32

@krds00
Copy link

krds00 commented Oct 4, 2024

@ion-elgreco
does it make sense to cast the type from float64 to float32 before processing the data? For example, the calculation of moving averages and shifts. Or should it be done only before saving to disk to save space?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants