function M = tbuildproduct_fast(A,oo)
% M = tbuildproduct_fast(A, oo)
% Constructs the product of matrices in the cell A, corresponding to the sequence in prod.
% M = A{prod(end)}*A{prod(end-1)}...*A{prod(1)}
%
% Input:
%   A       cell array of matrices
%   oo      ordering in which to multiply them
%
% Output:
%   M       the product
%
% Info:
%   if prod(i)=0, A{prod(i)} is replaced by the identity
%
% E.g.: tbuildproduct_fast({2 4 5},[1 0 3])
%
% See also: tbuildproduct
% 
% Written by: Jungers, Taken from: JSR-Toolbox


n = size(A{1},1);
l = length(oo);

M = eye(n);

for t=1:l
    if oo(t)>0
        M = A{oo(t)}*M; % The order of the multiplication is of course important and is related with the lifting: A'XA or AXA'
    end                   % in conitope for instance
end
end