function [T,I] = combindices(F,I)
% COMBINDICES Indices for all combinations of factor parameters
%
% [T,I] = COMBINDICES(F) where F is the factor, T is a cell
% of vectors, each containing one list of arguments, I is a cell
% with a list of indices spanning each argument used to construct T.
%
% T = COMBINDICES(F,I) I is a cell with a list of indices spanning
% each argument used to construct T.

% Jerod Weinman
% jerod@acm.org
    
% $Id: combindices.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2008, 2009, 2011
 
%    This file is part of MatLibFactorGraph.
%
%    MatLibFactorGraph is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    MatLibFactorGraph is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with MatLibFactorGraph.  If not, see <http://www.gnu.org/licenses/>.

  L = card(F);
  
  % Linear indices spanning each variable of the factor
  
  if nargin<2
	I = cell(1,nargs(F));
  
	for a=1:nargs(F)
	  I{a} = 1:L(a);
	end;
  end;
  
  % Combinatorial subscripts for Cartesian product
  T = cellndgrid(I);
