Skip to content

ENH: ufunc helper for variance #13263

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

Closed
wants to merge 2 commits into from
Closed

ENH: ufunc helper for variance #13263

wants to merge 2 commits into from

Conversation

0x0L
Copy link

@0x0L 0x0L commented Apr 4, 2019

Hello

This is a PR associated with #13199. Might also fix #9631

It implements a two-pass mean variance algorithm with an error correction term (see discussion in #13199).

It's more of a hack than a perfect solution: instead of allocating one array for the demeaned input, we allocate two arrays (one if we drop the bias correction term) with only a single dimension already reduced. This should never be worse than before but could be as bad.

@mattip mattip changed the title ufunc helper for variance ENH: ufunc helper for variance Apr 7, 2019
@0x0L
Copy link
Author

0x0L commented Apr 19, 2019

I'm not sure I understand why the test fails on windows. On a windows machine dtype 'g' gives me a float64 whereas on a Linux machine I get float128

@charris
Copy link
Member

charris commented Apr 19, 2019

On a windows machine dtype 'g' gives me a float64 whereas on a Linux machine I get float128

Not sure what the question is, but for MSVC, long double is the same as double, it has always been that way. In general, long double can be IBM double double, IEEE extended precision, IEEE quad precision, or just double. Its type varies across platforms.

@0x0L
Copy link
Author

0x0L commented Apr 19, 2019

@charris thx for your reply

The real issue is that the test fails (only on windows) with the following error:
AssertionError: res <class 'numpy.float64'>, tgt <class 'numpy.float64'>
which I find a bit confusing :)

@matthew-brett
Copy link
Contributor

I don't know if it's related, but we've had terrible troubles with something similar here: nipy/nibabel#665

@effigies
Copy link
Contributor

Tagging in #12096. I guess it's good to see that it's not just us...

@0x0L
Copy link
Author

0x0L commented Jun 9, 2019

@eric-wieser
Any idea why some tests fail on windows ?

EDIT @matthew-brett @effigies
Probably related to #10151

@0x0L
Copy link
Author

0x0L commented Sep 12, 2019

@eric-wieser
I think I addressed your remarks. However I still haven't found why the tests failed on windows.

@seberg
Copy link
Member

seberg commented Sep 12, 2019

Looking at the test failures, this is due to np.dtype(np.longdouble) == np.dtype(np.double) on windows, but the types still being the same. This makes sense because of how the type resolution works, it is to some degree completely fine. We could fix it, by writing a custom type resolver, it would do exactly the same as the SimpleUniformTypeResolver, but ensure that the second output is non-complex.

EDIT: To be honest, I tend towards just adapting the test or mark (that one part) as known-fail on windows. These type of "inconsistencies" exist for many other ufuncs just the same if you use long double on windows.

Base automatically changed from master to main March 4, 2021 02:04
@Micky774
Copy link
Contributor

Micky774 commented Feb 22, 2022

Hey there, I was just wondering what the status of this feature was -- is this still being worked on? It would be a welcome change, since we're looking to use it as a significant improvement for a downstream task in scikit-learn :)

@0x0L
Copy link
Author

0x0L commented Feb 22, 2022

Not really. I'm not too happy with the code and it's failing of few tests on windows.

@InessaPawson InessaPawson added the triage review Issue/PR to be discussed at the next triage meeting label Jul 23, 2022
@InessaPawson InessaPawson added triaged Issue/PR that was discussed in a triage meeting and removed triage review Issue/PR to be discussed at the next triage meeting labels Aug 1, 2022
@InessaPawson
Copy link
Member

@0x0L I'll close the PR since you are not planning on continuing the work. Thank you for giving it a go!

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

Successfully merging this pull request may close these issues.

variance nonzero for constant array
9 participants