On Friday, January 31, 2014 4:11:28 PM UTC-6, Jon Norberg wrote:
>
> Thank you very much Douglas! I learned a lot there. I didn't get it to 
> work straight away (running julia studio so its using julia 0.2). But these 
> changes made it work:
>
> function subinds(k, N)
>
>     step = iceil(N/k)
>
>     rng = 1:step
>
>     res = [rng + j * step for j in 0:k-2]
>
>     push!(res, ((k - 1) * step + 1):N)
>
>     res
>
> end
>
>
> function edist(a::AbstractMatrix, nblocks::Int, threshold)
>
>     N = size(a,2)
>
>     si = subinds(nblocks,N)
>
>     i = Int[]
>
>     j = Int[]
>
>     x = eltype(a)[]
>
>     for ii in si, jj in si
>
>         #r = pairwise(Euclidean(), view(a,:,ii), view(a,:,jj))
>
>         r = pairwise(Euclidean(), a[:,si[2]], a[:,si[2]])
>
>
But that isn't equivalent to view(a,:,ii), view(a,:,jj).  At least you need 
to replace si[2] in the first expression by ii and in the second expression 
by jj to get all pairs of columns.

I'm not sure what the situation was in 0.2 but now indexing into an array 
copies the block whereas using sub(a, :, ii) doesn't create a copy.  The 
current situation is that later operations on the result of sub(a,:,ii) can 
be slow compared to the use of view, especially for contiguous views, which 
these are. 

>         ioffset = ii[1] - 1
>
>         joffset = jj[1] - 1
>
>         for ir in 1:size(r,1), jr in 1:size(r,2)
>
>             if (ie = ioffset + ir) != (je = joffset + jr) && (rij = r[ir,jr]) 
> < threshold
>
>                 push!(i,ie)
>
>                 push!(j,je)
>
>                 push!(x,rij)
>
>             end
>
>         end
>
>     end
>
>     sparse(i,j,x)
>
> end
>
>

Reply via email to