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

Pre-allocated interpolation #126

Open
jianghaizhu opened this issue Oct 17, 2016 · 5 comments
Open

Pre-allocated interpolation #126

jianghaizhu opened this issue Oct 17, 2016 · 5 comments

Comments

@jianghaizhu
Copy link

jianghaizhu commented Oct 17, 2016

I am using AffineTransform to transform a large number of volumes and the interpolation process allocated a huge amount of memory. I know there is a interpolate! function. However interpolate! would destroy the input matrix. Also it looks like it can only be used with BSpline(Quadratic(InPlace())). Is there a way to output the interpolation to a pre-allocated matrix but also keep the input matrix? Thanks!

@sglyon
Copy link
Member

sglyon commented Oct 17, 2016

Would it work to call copy on your input matrix before passing it to interpolate!?

@jianghaizhu
Copy link
Author

Yes, I can make a copy of the input matrix before interpolate!, which would allocate the same amount of memory as interpolate. However, since I have tens of thousands of volumes whose size are fixed, I can pre-allocate a volume with the right size and use copy!() to copy the input matrix to the pre-allocated volume before interpolate! to limit the memory allocation, which is an improvement. But that is still tens of thousands additional copies of large 3d matrices, e.g. 250x250x250.

@timholy
Copy link
Member

timholy commented Oct 17, 2016

Can you get away with Linear? The reason I ask is that Linear does not require prefiltering; if you don't need to do prefiltering, then it does not destroy the input.

If you do need Quadratic, and can use InPlace, then you can copy to a reusable buffer as you say. I don't think there's an alternative to copying if you want to use the current infrastructure: interpolate! uses the input to store the interpolation coefficients, and those are not equal to the input data for anything higher than Linear.

@jianghaizhu
Copy link
Author

jianghaizhu commented Oct 17, 2016

Thanks! I did find out that when using Linear the output was not destroyed and was puzzled. Now I know why. Yes, right now I can go with Linear, but eventually I need to move to Quadratic and even Cubic. I didn't find an InPlace for Cubic though. Will this be implemented? Also when using BSpline(Quadratic(InPlace())), the GT has to be OnCell()?

@timholy
Copy link
Member

timholy commented Oct 17, 2016

Somebody probably needs to work out the mathematics. If you're interested in tackling that, there was once some PDF documentation on InPlace but it seems to have been removed. Perhaps you could try checking out older versions of this package to find it.

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

No branches or pull requests

3 participants