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

Fix round #494

Merged
merged 6 commits into from Dec 14, 2014
Merged

Fix round #494

merged 6 commits into from Dec 14, 2014

Conversation

omarocegueda
Copy link
Contributor

This is a follow-up to #493.

Apparently, round is not defined in c++98:
http://stackoverflow.com/questions/485525/round-for-float-in-c

which causes this error:
http://nipy.bic.berkeley.edu/builders/dipy-py2.7-win32/builds/124/steps/shell_5/logs/stdio

Using floor(x+0.5) may not be consistent with numpy, we also need to consider rounding to nearest even:
http://mathematica.stackexchange.com/questions/2116/why-round-to-even-integers

This solution uses the same procedure as for "dpy_log2", by borrowing code from numpy:
https://github.com/numpy/numpy/blob/master/numpy/core/src/npymath/npy_math.c.src

The code now builds in buildbot dipy-py2.7-win32:
http://nipy.bic.berkeley.edu/builders/dipy-py2.7-win32/builds/127/steps/shell_5/logs/stdio

@omarocegueda
Copy link
Contributor Author

And tests passed in dipy-py2.7-win32 too =D
http://nipy.bic.berkeley.edu/builders/dipy-py2.7-win32/builds/127/steps/shell_6/logs/stdio

#endif

/* From numpy npy_math.c.src */
#ifndef HAVE_RINT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, out of curiosity when do we expect npy_math to not have npy_rint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't know, I may have been too "paranoid", like the codility.com guys say: "Assume nothing, trust no one" ;-) . Maybe it's not necessary, I'll check as soon as the buildbots get back online =)

@omarocegueda
Copy link
Contributor Author

I was reading a bit more the numpy code and I think the npy_* versions are always available. If the native version is available, they simply decorate them with prefix 'npy_':

https://github.com/numpy/numpy/blob/a435de365a603f29bf243882644f1e26edda6e9a/numpy/core/src/npymath/npy_math.c.src#L433
here is where they call the native function:
https://github.com/numpy/numpy/blob/a435de365a603f29bf243882644f1e26edda6e9a/numpy/core/src/npymath/npy_math.c.src#L450

and if the native function is not available, then they define different versions of their own implementation with different types of arguments and return values:

https://github.com/numpy/numpy/blob/a435de365a603f29bf243882644f1e26edda6e9a/numpy/core/src/npymath/npy_math.c.src#L362

here is where they call the (generic) version for each return/parameter type:
https://github.com/numpy/numpy/blob/a435de365a603f29bf243882644f1e26edda6e9a/numpy/core/src/npymath/npy_math.c.src#L375

so, in theory, it should be possible to simply call the npy_* version without adding any extra code in dpy_math.h (just including "numpy/npy_math.h" should be enough). Unfortunately the win32 buildbots are still offline... I'll try this as soon as they are back online.

@matthew-brett
Copy link
Contributor

Not sure what is happening with the buildbots, but I suspect there was a
power failure, and only some of them came back up.

There's a 'storm' at the moment in Berkeley apparently. Thomas Kluyver
works in the next-door office, is at home because of the storm, but if he
goes in, he will reboot the machines. That might not be today though -
sorry to say.

@omarocegueda
Copy link
Contributor Author

Hi!, I hope you guys are fine after the big storm!. The buildbots are working now, and we effectively can just include "numpy/npy_math.h" from "dpy_math.h" and use all the "npy_*" functions without adding any extra code. After that, the tests pass in win32:
http://nipy.bic.berkeley.edu/builders/dipy-bdist32-27/builds/160/steps/shell_8/logs/stdio
and I had no issues locally, I'm just waiting to see what Travis says...

@Garyfallidis
Copy link
Contributor

Nice! Thx!

Garyfallidis added a commit that referenced this pull request Dec 14, 2014
@Garyfallidis Garyfallidis merged commit eac86f2 into dipy:master Dec 14, 2014
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

Successfully merging this pull request may close these issues.

None yet

4 participants