|
|
Log in / Subscribe / Register

What makes the NaN check expensive?

What makes the NaN check expensive?

Posted Jan 5, 2020 20:12 UTC (Sun) by epa (subscriber, #39769)
In reply to: What makes the NaN check expensive? by jansson
Parent article: Some median Python NaNsense

Moreover, if you are sorting the list then you are already doing an O(N log N) operation, so a linear scan to find any NaN values would be a tiny fraction of the total work on large lists, and for small lists it would be fast enough anyway not to matter. As others said you would not be using vanilla Python if you needed high-performance numeric operations. So I don’t understand the objections based on performance. Perhaps if you have vast numbers of short lists and need the median of each... but even then you’d surely use a different tool.


to post comments

What makes the NaN check expensive?

Posted Jan 7, 2020 18:43 UTC (Tue) by NYKevin (subscriber, #129325) [Link] (1 responses)

You don't sort to get median, you do quickselect (or another algorithm), which is O(N) (in the average case).

(Granted, a linear scan for NaN is also O(N), and probably has a better cache hit rate to boot. So I agree with you that performance really shouldn't be a problem here.)

What makes the NaN check expensive?

Posted Jan 7, 2020 22:06 UTC (Tue) by nivedita76 (guest, #121790) [Link]

You /should/, but the python implementation that's broken actually does a full sort.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds