-
Notifications
You must be signed in to change notification settings - Fork 437
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
ENH: Add support for ArraySequence in length
function
#1076
ENH: Add support for ArraySequence in length
function
#1076
Conversation
length
functionlength
function
@arokem @Garyfallidis: I guess we should support older NiBabel's versions, right? We could add a check whether |
Yes. We'll want to support older versions of nibabel for now. I think that we should support backwards for at least a year after these new features are in a nibabel release. Possibly even longer -- @Garyfallidis : what are your thoughts on duration of back-compatibility in this case? Your method seems reasonable to me, but you can also directly query the nibabel version string with |
That all said, it's a good thing to start integrating this! Users living on the cutting edge should be able to start reaping the benefits of all your hard work! |
Thanks @arokem, I will definitively have a look at the |
I added a check for Nibabel's verison but currently Travis only installs Nibabel 2.0.2 and not the master. @arokem do you know an easy way to add new Travis bots that will use Nibabel's master instead? Maybe one for Python 2 and another one for Python 3. |
I think that the best way would be to have a nibabel release, before merging this work into dipy. @matthew-brett : any plans for upcoming nibabel release? |
I plan to do a release in the next few weeks. |
@arokem but we still need additional Travis bots to test that Dipy is working properly with an older Nibabel right? |
Yes, we already have a bot devoted to testing old versions of our dependencies: https://github.com/nipy/dipy/blob/master/.travis.yml#L32, which specifies the oldest version we support of these different libraries. |
Current coverage is 85.87% (diff: 100%)@@ master #1076 diff @@
==========================================
Files 214 214
Lines 25862 25882 +20
Methods 0 0
Messages 0 0
Branches 2642 2642
==========================================
+ Hits 22206 22226 +20
Misses 3003 3003
Partials 653 653
|
Hi all, Because the new nibabel release will be solving a critical issue with the memory management of the streamlines generated or loaded I don't think that we can do anything else than changing our minimum requirements to nibabel to 2.1 immediately after nibabel gets released. Remember that in what we currently have someone who has generated 5GBytes of streamlines as lists of numpy arrays which is currently the only option will be actually using 10+GBytes of memory. This memory will stay around even if the user deletes the streamlines making the program extremely hungry for resources. We need to inform our users about that and ask them to update nibabel. The new Streamline API is designed in a way to completely replace our current representation of streamlines without changing user experience. If we continue supporting older versions that will mean that we will still carry the critical memory issue for long time as the memory will not be freed properly upon loading the data with nibabel. I don't think this is in our hands any more we have to change our minimum requirements asap. People these days generate bigger and bigger tractograms. We need to be careful with memory management. In summary, I think it will be a bad idea to continue supporting older versions of nibabel than 2.1 (next release). We need also to make sure that the new Streamlines API will replace all existing usages of streamlines as lists of arrays. A true call for action! Finally, I suggest for this PR to add a couple of travis bots to use the master version of nibabel until nibabel get's released. That will help us move faster with the necessary API changes inside DIPY. |
What you propose seems problematic to me for a few reasons (in increasing
I understand the importance of moving forward with this, and I would How about the following plan: it's been a while since we made a release, so On Thu, Jun 16, 2016 at 7:53 PM, Eleftherios Garyfallidis <
|
I restarted the build but Travis still doesn't take the latest Nibabel 2.1 release. @matthew-brett any idea why? See https://travis-ci.org/nipy/dipy/jobs/138160759#L211 |
Hey @matthew-brett and @arokem something does not allow Travis to use latest released version of nibabel which is 2.1. Do you know why this is happening? |
Should I used this https://github.com/matthew-brett/travis-wheel-builder to update Travis wheels or it has nothing to do with that? |
Yes, that is what you'd need to do - the build script is only looking for the wheels in http://travis-wheels.scikit-image.org/ - so you need to build, upload wheels for new versions. |
@matthew-brett I'm not sure of the procedure. I forked your repo, made some modification (TO_BUILD="nibabel") and push the changes on my fork (that has Travis enable) but Travis is failing to deploy: Should I make a PR to your repo? |
cadf229
to
70c2235
Compare
The decrease in coverage is due to the benchmark not being executed. There is also missing coverage for other benchmarks in Dipy. See PR #1141. |
70c2235
to
34e1814
Compare
Looks like that's fine now, with the merge of #1141. You rebased? |
@arokem yep. |
Sorry - this has languished here for a while. Looks ready to go from my point of view. @MarcCote : anything more need to be done here before I merge? |
It's all good. |
I guess we can get rid of the checks for nibabel < 2.1, if we go ahead with #1157 as is. |
That would be really nice. Indeed :). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can remove all this stuff now :-)
|
||
import nibabel | ||
|
||
NIBABEL_LESS_2_1 = LooseVersion(nibabel.__version__) < '2.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is no longer necessary
from dipy.tracking.streamline import (set_number_of_points, | ||
length, | ||
compress_streamlines) | ||
from dipy.tracking.tests.test_streamline import (set_number_of_points_python, | ||
length_python, | ||
compress_streamlines_python) | ||
|
||
if not NIBABEL_LESS_2_1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
assert_array_equal([length_python(s) for s in DATA["streamlines"]], | ||
length(DATA["streamlines"])) | ||
|
||
if not NIBABEL_LESS_2_1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
from libc.math cimport sqrt | ||
|
||
from dipy.tracking import NIBABEL_LESS_2_1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is as well
True | ||
>>> length([]) | ||
0.0 | ||
>>> length(np.array([[1, 2, 3]])) | ||
0.0 | ||
|
||
''' | ||
if not NIBABEL_LESS_2_1 and isinstance(streamlines, Streamlines): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this
@@ -11,9 +11,10 @@ | |||
from numpy.testing import (assert_array_equal, assert_array_almost_equal, | |||
assert_raises, run_module_suite) | |||
|
|||
from dipy.tracking import NIBABEL_LESS_2_1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this
@@ -24,6 +25,9 @@ | |||
orient_by_rois, | |||
values_from_volume) | |||
|
|||
if not NIBABEL_LESS_2_1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this
|
||
for i, s in enumerate(streamlines_64bit): | ||
length_streamline_python = length_python(s) | ||
assert_array_almost_equal(length_streamlines_cython[i], | ||
length_streamline_python) | ||
|
||
# ArraySequence | ||
if not NIBABEL_LESS_2_1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And all of this
Awesome. Thanks for doing this. I will let Travis do its thing, but if all goes well, and if no one objects, I'll merge this on Monday. |
from dipy.data import get_data | ||
from nibabel import trackvis as tv | ||
|
||
from dipy.tracking import NIBABEL_LESS_2_1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops - missed this one!
DATA['streamlines'] = generate_streamlines(nb_streamlines, | ||
min_nb_points, max_nb_points, | ||
rng=rng) | ||
if not NIBABEL_LESS_2_1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one too!
930c73d
to
7a78481
Compare
Yep, I missed two. I also rebased just to be sure. |
@MarcCote -- the following bot failure might be related to this PR: http://nipy.bic.berkeley.edu/builders/dipy-bdist64-27/builds/113/steps/shell_12/logs/stdio Do you understand what's going on there? |
@arokem oops, I didn't see your last comment. It probably has to do with the fact that we are now using |
@arokem @matthew-brett cdef void c_arclengths_from_arraysequence(Streamline points,
np.npy_intp[:] offsets, np.npy_intp[:] lengths,
double[:] arclengths) nogil:
... doesn't seem to work on my linux machine (64bits) :/. Now, I'm getting the same kind of error as the Windows machine. ERROR: dipy.tracking.tests.test_streamline.test_length
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/marc/.local/env/p2/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/data/research/src/dipy/dipy/tracking/tests/test_streamline.py", line 374, in test_length
length_streamline_arrseq = length(Streamlines([streamline]))
File "dipy/tracking/streamlinespeed.pyx", line 109, in dipy.tracking.streamlinespeed.length (dipy/tracking/streamlinespeed.c:2607)
streamlines._offsets,
ValueError: Buffer dtype mismatch, expected 'int' but got 'long' It seems Here' the definition of a |
I think Cython's |
On my machine intp is int64 but Cython's np.npy_intp seems to be int32 :-/.
|
Hmm, yes, it works correctly for me, but only for Cython >= 0.25.1 . This is not relevant here, I think, but it's also safer to use
|
Ok, I've reinstalled Cython 0.21 (the version I currently have), did a |
…for_length ENH: Add support for ArraySequence in `length` function
This small PR is the first of a series of PRs aiming to support Nibabel's
ArraySequence
objects.Specifically, this PR improves
dipy.tracking.streamlinespeed.length
to supportArraySequence
objects. This gives pretty good speedup even over the current Cython version (all speedups are in respect to the Python implementation):Edit: of course this needs the master branch of Nibabel or eventually v2.1.