Home > manopt > tools > multiprod.m

multiprod

PURPOSE ^

Matrix multiply 2-D slices of N-D arrays

SYNOPSIS ^

function C = multiprod(A, B, unused1, unused2) %#ok

DESCRIPTION ^

 Matrix multiply 2-D slices of N-D arrays

 function C = multiprod(A, B)

 If A, B are two 3-D arrays of compatible sizes, then C is a 3-D array
 such that

     C(:, :, i) = A(:, :, i) * B(:, :, i)

 for each i. Arrays have compatible sizes if the above is well defined.

 If A, B are two N-D arrays of compatible sizes, then C is an N-D array
 such that

     C(:, :, i, j, k, ...) = A(:, :, i, j, k, ...) * B(:, :, i, j, k, ...)

 for each i, j, k...

 This function is just a wrapper for pagemtimes, with a fallback call to
 multiprod_legacy in case pagemtimes is not available.
 If pagemtimes is available, it is better to call it directly. This is
 especially true if multiprod is called in conjunction with multitransp,
 as pagemtimes allows for both to be done in one function call.

 See also: multitransp multihconj multiscale multiskew multiskewh multitrace

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function C = multiprod(A, B, unused1, unused2) %#ok<INUSD>
0002 % Matrix multiply 2-D slices of N-D arrays
0003 %
0004 % function C = multiprod(A, B)
0005 %
0006 % If A, B are two 3-D arrays of compatible sizes, then C is a 3-D array
0007 % such that
0008 %
0009 %     C(:, :, i) = A(:, :, i) * B(:, :, i)
0010 %
0011 % for each i. Arrays have compatible sizes if the above is well defined.
0012 %
0013 % If A, B are two N-D arrays of compatible sizes, then C is an N-D array
0014 % such that
0015 %
0016 %     C(:, :, i, j, k, ...) = A(:, :, i, j, k, ...) * B(:, :, i, j, k, ...)
0017 %
0018 % for each i, j, k...
0019 %
0020 % This function is just a wrapper for pagemtimes, with a fallback call to
0021 % multiprod_legacy in case pagemtimes is not available.
0022 % If pagemtimes is available, it is better to call it directly. This is
0023 % especially true if multiprod is called in conjunction with multitransp,
0024 % as pagemtimes allows for both to be done in one function call.
0025 %
0026 % See also: multitransp multihconj multiscale multiskew multiskewh multitrace
0027 
0028 % This file is part of Manopt: www.manopt.org.
0029 % Original author: Nicolas Boumal, Aug. 12, 2021.
0030 % Contributors: Xiaowen Jiang
0031 % Change log:
0032 %
0033 %   Aug. 12, 2021 (NB):
0034 %       Matlab R2020b introduced a built-in function pagemtimes which does
0035 %       essentially everything we ever needed to do with multiprod in
0036 %       Manopt, and is much faster. It also has the advantage of being
0037 %       compatible with dlarray, necessary for automatic differentiation.
0038 %       Accordingly, multiprod became a wrapper for pagemtimes, and the old
0039 %       code for multiprod remains available as multiprod_legacy.
0040 
0041     assert(nargin == 2, ...
0042            'The new multiprod only takes two inputs. Check multiprod_legacy.');
0043 
0044     if exist('pagemtimes', 'builtin') % Added to Matlab R2020b
0045         C = pagemtimes(A, B);
0046     else
0047     %   warning('manopt:multi', ...
0048     %          ['Matlab R2020b introduced pagemtimes, faster than multiprod.\n' ...
0049     %           'Calling the old code multiprod_legacy instead.\n' ...
0050     %           'To disable this warning: warning(''off'', ''manopt:multi'')']);
0051         C = multiprod_legacy(A, B);
0052     end
0053 
0054 end

Generated on Sun 05-Sep-2021 17:57:00 by m2html © 2005