You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: permute.m
    path of file: ./repos/MATLABAutoDiff/@myAD
    
    the code of the file until where you have to start completion: function x=permute(x,order)
  % by SeHyoun Ahn, July 2016

  if ~issparse(x.values)
    aux=size(x.values);
    p=permute(reshape(1:prod(aux),aux),order);
    x.derivatives=x.derivatives(p(:),:);

    
function x=permute(x,order)
  % by SeHyoun Ahn, July 2016

  if ~issparse(x.values)
    aux=size(x.values);
    p=permute(reshape(1:prod(aux),aux),order);
    x.derivatives=x.derivatives(p(:),:);
    x.values=permute(x.values,order);
  else
    if (size(order) == [1,2])
      if (order == [2,1])
        x = x';
      elseif (order == [1,2])
      else
        error('ORDER contains an invalid permutation; try using transpose instead.');
      end