jeez, you are right! sorry i'm doing my first steps here - forget about the 
compile step. it IS much faster than 2x. after changing ismaxfun to output 
something similar to slicefun, it's 10x faster. but maybe my reshaping is 
not the smartest idea either. anyway, that's pretty good!

julia> function ismaxfun(x::Array{Float64,6})
       z = maximum(x,6)
       ismax = x .== z
       id = reshape(find(ismax),size(x)[1:5])
       end

A = rand(10,10,10,10,10,50)

julia> @time k = slicefun(A)
elapsed time: 0.912256696 seconds (213759264 bytes allocated)

julia> @time k = ismaxfun(A)
elapsed time: 0.089194917 seconds (3484324 bytes allocated)




On Wednesday, 30 April 2014 15:47:30 UTC+1, Tim Holy wrote:
>
> I time it at 50x faster: 
>
> julia> @time slicefun(A); 
> elapsed time: 1.135524683 seconds (181765472 bytes allocated) 
>
> julia> @time ismaxfun(A); 
> elapsed time: 0.020300699 seconds (931120 bytes allocated) 
>
>
> Did you run it a second time? (You don't want to include the JIT timing.) 
>
> --Tim 
>
> On Wednesday, April 30, 2014 07:38:07 AM Florian Oswald wrote: 
> > I see. thanks! 
> > you are (of course) right with the timing: 
> > 
> > julia> function slicefun(x::Array{Float64,6}) 
> >        z = mapslices(findmax,x,6) 
> >        end 
> > julia> function ismaxfun(x::Array{Float64,6}) 
> >        z = maximum(x,6) 
> >        ismax = x .== z 
> >        end 
> > 
> > times as follows. more than twice as fast! 
> > 
> > julia> @time k = ismaxfun(A) 
> > elapsed time: 0.53359244 seconds (14418060 bytes allocated) 
> > julia> @time k = slicefun(A) 
> > elapsed time: 1.396534023 seconds (226762376 bytes allocated) 
> > 
> > On Wednesday, 30 April 2014 15:25:25 UTC+1, Tim Holy wrote: 
> > > There is 
> > > 
> > >     maximum(A, 3) 
> > > 
> > > but I gather you also want the index? If so, mapslices is your best 
> > > one-liner 
> > > as of now. But if you're performance-sensitive, you might also look 
> into 
> > > 
> > > this: 
> > >     M = maximum(A, dims) 
> > >     ismax = A .== M 
> > > 
> > > and then find the `true` elements of ismax. I'll bet that's quite a 
> lot 
> > > faster 
> > > than using mapslices, even though it requires two traversals of the 
> array. 
> > > As 
> > > a bonus, you'll also learn about ties. 
> > > 
> > > --Tim 
> > > 
> > > On Wednesday, April 30, 2014 04:04:47 AM Florian Oswald wrote: 
> > > > I looked at the issue open at 
> > > > 
> > > > https://github.com/JuliaLang/julia/issues/3893 
> > > > 
> > > > but couldn't figure out what's the best thing to do. I gather that 
> there 
> > > > will be a 
> > > > 
> > > > findmax(A,dims) 
> > > > 
> > > > in some future version of julia? that's certainly what im looking 
> for 
> > > 
> > > here. 
> > > 
> > > > in the meantime, is this the best I can do? 
> > > > 
> > > > A = randn(3,3,3) 
> > > > mapslices(findmax,A,3) 
> > > > 
> > > > cheers 
>

Reply via email to