function y = Mmap(x,flag)

% compute the linear map and its transpose for fused lasso regularization
% for logistic regression.
%
% The linear map takes x to [x(1:end-1);diff(-x(1:end-1))]

if flag == 1 % compute linear map
  y = [x(1:end-1);diff(-x(1:end-1))];
elseif flag == 2 % compute transpose
  m = (size(x,1) + 1)/2;
  y = [x(1:m);0] + [x(m+1);diff(x(m+1:end));-x(end);0];
end