function Y = inner_block_transpose(X, p, q)

[m, n] = size(X);

if n == q
    Y = reshape(X, [p m/p q]);
    Y = permute(Y, [3 2 1]);
    Y = reshape(Y, [q*m/p p]);
else
    Y = reshape( X, [ p m/p q n/q ] );
    Y = permute( Y, [ 3 2 1 4 ] );
    Y = reshape( Y, [ q*m/p p*n/q ] );
end

end


