2011-09-02 15:26:46 +02:00
function [D, err] = A_times_B_kronecker_C ( A,B,C,fake)
%@info:
2011-09-02 16:30:50 +02:00
%! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C},@var{fake})
2011-09-02 15:26:46 +02:00
%! @anchor{kronecker/A_times_B_kronecker_C}
%! @sp 1
%! Computes A*kron(B,C).
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item A
%! mA*nA matrix of doubles.
%! @item B
%! mB*nB matrix of doubles.
%! @item C
%! mC*nC matrix of doubles.
%! @item fake
%! Anything you want, just a fake parameter (because the mex version admits a last argument specifying the number of threads to be used in parallel mode).
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
2011-09-02 16:30:50 +02:00
%! @item D
%! mA*(nC*nB) or mA*(nB*nB) matrix of doubles.
%! @item err
%! Integer scalar equal to zero (if all goes well).
2011-09-02 15:26:46 +02:00
%! @end table
%! @sp 2
2011-09-02 16:30:50 +02:00
%! @strong{Remarks}
%! @sp 1
%! [1] This routine is called by Dynare if and only the mex version is not compiled (also used for testing purposes).
%! @sp 1
%! [2] This routine can be called with three or four arguments. In the first case A*kron(B,B) is computed.
%! @sp 2
2011-09-02 15:26:46 +02:00
%! @strong{This function is called by:}
2011-09-02 16:30:50 +02:00
%! @sp 1
%! @ref{kronecker/sparse_hessian_times_B_kronecker_C}, @ref{dr1}, @ref{simult_}
2011-09-02 15:26:46 +02:00
%! @sp 2
%! @strong{This function calls:}
%!
%! @end deftypefn
%@eod:
2013-06-12 16:42:09 +02:00
% Copyright (C) 1996-2012 Dynare Team
2008-08-01 14:40:33 +02:00
%
% This file is part of Dynare.
%
% Dynare 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.
%
% Dynare 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 Dynare. If not, see <http://www.gnu.org/licenses/>.
2009-12-16 18:17:34 +01:00
2012-10-31 17:03:49 +01:00
% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
2008-04-25 14:47:30 +02:00
% Chek number of inputs and outputs.
2011-09-02 16:30:50 +02:00
if nargin > 4 || nargin < 3
error ( ' A_times_B_kronecker_C takes 3 or 4 input arguments and provides 2 output arguments.' )
2008-04-25 14:47:30 +02:00
end
2010-11-26 17:39:50 +01:00
2008-04-25 14:47:30 +02:00
% Get & check dimensions. Initialization of the output matrix.
[ mA , nA ] = size ( A ) ;
[ mB , nB ] = size ( B ) ;
2010-11-15 13:06:39 +01:00
if nargin == 4
2008-04-25 14:47:30 +02:00
[ mC , nC ] = size ( C ) ;
2008-05-16 10:18:37 +02:00
if mB * mC ~= nA
2008-04-25 14:47:30 +02:00
error ( ' Input dimension error!' )
end
D = zeros ( mA , nB * nC ) ;
loop = ( mB * nB * mC * nC > 1e7 ) ;
else
if mB * mB ~= nA
error ( ' Input dimension error!' )
end
2008-05-16 10:18:37 +02:00
D = zeros ( mA , nB * nB ) ;
2008-04-25 14:47:30 +02:00
loop = ( mB * nB * mB * nB > 1e7 ) ;
end
% Computational part.
if loop
2010-11-15 13:06:39 +01:00
if nargin == 4
2011-09-02 16:30:50 +02:00
k1 = 1 ;
2008-04-25 14:47:30 +02:00
for i1 = 1 : nB
for i2 = 1 : nC
D ( : , k1 ) = A * kron ( B ( : , i1 ) , C ( : , i2 ) ) ;
2011-09-02 16:30:50 +02:00
k1 = k1 + 1 ;
2008-04-25 14:47:30 +02:00
end
end
else
k1 = 1 ;
for i1 = 1 : nB
for i2 = 1 : nB
D ( : , k1 ) = A * kron ( B ( : , i1 ) , B ( : , i2 ) ) ;
2011-09-02 16:30:50 +02:00
k1 = k1 + 1 ;
2008-04-25 14:47:30 +02:00
end
end
end
else
2010-11-15 13:06:39 +01:00
if nargin == 4
2008-04-25 14:47:30 +02:00
D = A * kron ( B , C ) ;
else
D = A * kron ( B , B ) ;
end
2010-09-21 10:40:18 +02:00
end
err = 0 ;