Hello colleague, On Wednesday, May 21, 2014 2:55:34 PM UTC+2, Tim Holy wrote: > > I agree that vectorizing is very nice in some circumstances, and it will > be > great if Julia can get to the point of not introducing so many > temporaries. > (Like Tobi, I am not convinced this is an easy problem to solve.) > > Unlike you and Tobi, i'm absolutely sure, that this is a hard problem. But the first sentence on julialang.org is:
Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical computing environments. Therefore i'm expecting high-level SIMD language constructs. But there are plenty of cases where loops are clearer even when > vectorization > is both possible and efficient. For example, surely you can't tell me that > > L = similar(A) > m,n = size(A) > L[2:m-1,2:n-1] = A[3:m,2:n-1] + A[1:m-2,2:n-1] + A[2:m-1,3:n] + > A[2:m-1,1:n-2] - 4A[2:m-1, 2:n-1] > > is easier to read and understand than > > L = similar(A) > for j=2:size(A,2)-1, i=2:size(A,1)-1 > L[i,j] = A[i+1,j] + A[i-1,j] + A[i,j+1] + A[i,j-1] - 4A[i,j] > end > > Not only does the loops-version have fewer keystrokes, it's a heck of a > lot > clearer that what you're doing is computing the 2d discrete laplacian. > > 1) ... you probably overlooked my sentence "you reorder more than you calculate. For problems like this explicit loops are often the better way" 2) Actually by inspection i can read in the first form: a linear combination of submatrices of A. 3) And both versions i expect to be encapsulated in a L = disc_laplace(A)