Thanks, I will have a look at this.

Is there some interest to have this in base?

Davide

On Wednesday, March 11, 2015 at 1:38:34 PM UTC, Mauro wrote:
>
> Have a look at the permute! function in julia: 
> @less permute!([1,2], [1,2]) 
>
> Modifying it to 
>
> function permute!!{T<:Integer}(a, i, p::AbstractVector{T}) 
>     count = 0 
>     start = 0 
>     while count < length(a) 
>         ptr = start = findnext(p, start+1) 
>         temp = a[i,start] 
>         next = p[start] 
>         count += 1 
>         while next != start 
>             a[i,ptr] = a[i,next] 
>             p[ptr] = 0 
>             ptr = next 
>             next = p[next] 
>             count += 1 
>         end 
>         a[i,ptr] = temp 
>         p[ptr] = 0 
>     end 
>     a 
> end 
>
> should work (untested).  Note that permuting a column should be faster 
> though as julia matrices are column-major. 
>
> On Wed, 2015-03-11 at 13:49, Davide Lasagna <lasagn...@gmail.com 
> <javascript:>> wrote: 
> > Hi, 
> > 
> > 
> > permute!(v, p) permutes the elements of v according to the permutation 
> > vector p. 
> > 
> > Is there any equivalent built in function for permuting rows of a 
> matrix? 
> > Given the memory layout of julia matrices it should not be too difficult 
> to 
> > have a similar function for matrices as well. 
> > 
> > Thanks, 
> > 
> > Davide 
>
>

Reply via email to