Daniel@0: function D = setDistanceDiag(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % D = setDistanceDiag(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % X = d-by-n data matrix Daniel@0: % W = d-by-1 PSD matrix Daniel@0: % Ifrom = k-by-1 vector of source points Daniel@0: % Ito = j-by-1 vector of destination points Daniel@0: % Daniel@0: % D = n-by-n matrix of squared euclidean distances from Ifrom to Ito Daniel@0: % D is sparse, and only the rows corresponding to Ifrom and Daniel@0: % columns corresponding to Ito are populated. Daniel@0: Daniel@0: [d,n] = size(X); Daniel@0: L = W.^0.5; Daniel@0: Daniel@0: Vfrom = bsxfun(@times, L, X(:,Ifrom)); Daniel@0: Daniel@0: if nargin == 4 Daniel@0: Vto = bsxfun(@times, L, X(:,Ito)); Daniel@0: else Daniel@0: Vto = bsxfun(@times, L, X); Daniel@0: Ito = 1:n; Daniel@0: end Daniel@0: Daniel@0: D = distToFrom(n, Vto, Vfrom, Ito, Ifrom); Daniel@0: end