pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
27.23k stars 1.67k forks source link

Add `log` and `exp` support for rust #16286

Closed savente93 closed 4 weeks ago

savente93 commented 1 month ago

Description

In python the log etc. functions are provided by supporting numpy. However I am writing a library on top of polars in Rust, and am really feeling the lack of a logarithm. A lot of information theoretical and statstic processes are quire reliant on logarithms or exponents. Given that logarithms have dedicated CPU instructions (source: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24592.pdf page 319) I think it would be best to see if polars can support this directly instead of building it on top of it.

Having the base be an argument is nice to have, but not necessary as arbitrary bases can be calculated from another one quite easily.

I would expect it to work just like other arithmetic functions:

df!("x" => [2,4,6,16,32,64,128,512,1024,2048])?.select(&[col("x").log().alias("log_x")])

should give back the following data frame:

df!("log_x" => [1,2,3,4,5,6,7,8,9,10])?
savente93 commented 4 weeks ago

My appologies, I since found that it is actually already in the code base. I'd tried to search for it, but did not find it before, presumably because it was hidden behind a feature flag, and this can be difficult to navigate. mea culpa