function all_partitions = form_integer_partition(N,nPart)
% example form_integer_partition(4,2)
% generates multi-indices
% [1 3
%  2 2
%  3 1]
if nPart == 2
    all_partitions = zeros(N-1,2);
    for i = 1:N-1
        all_partitions(i,1) = i;
        all_partitions(i,2) = N-i;
    end
else
    all_partitions = [];
    for i=1:N-2
        curr_partition = form_integer_partition(N-i,nPart-1);
        size_curr = size(curr_partition,1);
        next_vec = i*ones(size_curr,1);
        curr_partition = [curr_partition,next_vec];
        all_partitions = [all_partitions;curr_partition];
    end
end
end