JuliaMath / NaNMath.jl

Julia math built-ins which return NaN and accumulator functions which ignore NaN
Other
52 stars 26 forks source link

Add more nan functions #2

Closed ufechner7 closed 8 years ago

ufechner7 commented 8 years ago

As discussed in https://github.com/JuliaLang/julia/pull/12563#issuecomment-130918285 , it would be useful to have a Julia equivalent of the following numpy functions:

nanargmax nanargmin nanmax nanmin nansum nanmean nanstd nanvar

These functions calculate the maximum etc of an array of values, ignoring any NaN's (instead of promoting them, what Julia will do shortly, probably in the 0.4 release).

Please comment, if this is the right package to add these functions!

mlubin commented 8 years ago

Yes, this package would be a reasonable home for those functions. The nan prefix isn't needed, I'd prefer NaNMath.argmax, NaNMath.argmin, etc. in order to be consistent with the current functions. (I don't want to call nanlog and nanasin.)

tkelman commented 8 years ago

I guess the current use cases of NaNMath would just have to be careful about which replacements they make from this package. Ignore-nans vs return-nan-instead-of-throwing are slightly different use cases, so it's mainly the package naming that made this seem worth suggesting.

mlubin commented 8 years ago

Are there any cases where ignore-nans and return-nan-instead-of-throwing are in conflict/ambiguous?

tkelman commented 8 years ago

Not that I can think of so far.

ufechner7 commented 8 years ago

Thanks for the feedback! If nobody objects, I would start to implement the following functions, ignoring NaN values in the argument:

maximum minimum mean sum std var

Does someone know the equivalent of the numpy functions argmax and argmin in Julia?

ufechner7 commented 8 years ago

I created a pull request to implement the function sum: https://github.com/mlubin/NaNMath.jl/pull/3 Depending on the feedback, I will continue to add the other functions, too.

tkelman commented 8 years ago

Does someone know the equivalent of the numpy functions argmax and argmin in Julia?

indmax and indmin, I believe

ufechner7 commented 8 years ago

I created another pull request with the rest of the functions: https://github.com/mlubin/NaNMath.jl/pull/5 I did not implement indmax and indmin yet, because currently Base.indmax and Base.indmin ignore NaN values already. This might change in the future.

ufechner7 commented 8 years ago

This is done in release 0.1.0 .