For Array types, you can exploit the column-major order to do loop over any single dimension using at most 3 nested loops. See e.g.:
https://github.com/stevengj/Hadamard.jl/blob/master/src/Hadamard.jl#L148-L162 On Wednesday, December 18, 2013 12:58:25 AM UTC-5, Spencer Russell wrote: > > I'm trying to adapt this to use to unwrap along arbitrary dimensions in an > array and having a bit of trouble wrapping my head around how to manage it. > > I can compute the phase difference between adjacent slices using slicedim, > and computing the new phase value isn't hard, but i need to assign the > result back to the array, basically treating slicedim as a view (which > doesn't work). How should I do this? > > Here's what I have so far (with the failing assignment into the slicedim): > > function unwrap!(m::Array, dim::Integer=ndims(m)) > if size(m, dim) < 2 > return m > end > for i = 2:size(m, dim) > d = slicedim(m, dim, i) - slicedim(m, dim, i-1) > slicedim(m, dim, i) -= floor((d+pi) / (2pi)) * 2pi > end > return m > end > > > > On Tue, Dec 17, 2013 at 10:50 PM, Spencer Russell <[email protected]<javascript:> > > wrote: > >> Ah, thanks for the tip on the in-place/out-of-place idiom, and good point >> on the faster unwrap. >> >> -s >> >> >> On Tue, Dec 17, 2013 at 8:58 PM, Steven G. Johnson >> <[email protected]<javascript:> >> > wrote: >> >>> >>> >>> On Tuesday, December 17, 2013 8:55:51 PM UTC-5, Steven G. Johnson wrote: >>> >>>> Also, note that you should be able to use truncated division rather >>>> than loops to add/subtract the correct multiple of 2pi, as in my snippet. >>>> >>> >>> (The problem with loops is that I can easily imagine data for which the >>> nested-loops version is O(n^2) or worse rather than O(n), simply by having >>> the phase grow linearly or faster with n.) >>> >> >> >
