Home > manopt > autodiff > functions_AD > cmultiscale.m

cmultiscale

PURPOSE ^

Multiplies the 2D slices in a 3D array by individual scalars.

SYNOPSIS ^

function Ascale = cmultiscale(scale, A)

DESCRIPTION ^

 Multiplies the 2D slices in a 3D array by individual scalars.

 function Ascale = cmultiscale(scale, A)

 Basically the same as multiscale but is compatible with structs with
 fields real and imag, which means this can be used for automatic
 differentiation with complex arrays in older Matlab versions.

 See also: manoptADhelp multiscale

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Ascale = cmultiscale(scale, A)
0002 % Multiplies the 2D slices in a 3D array by individual scalars.
0003 %
0004 % function Ascale = cmultiscale(scale, A)
0005 %
0006 % Basically the same as multiscale but is compatible with structs with
0007 % fields real and imag, which means this can be used for automatic
0008 % differentiation with complex arrays in older Matlab versions.
0009 %
0010 % See also: manoptADhelp multiscale
0011 
0012 % This file is part of Manopt: www.manopt.org.
0013 % Original author: Xiaowen Jiang, Aug. 31, 2021.
0014 % Contributors: Nicolas Boumal
0015 % Change log:
0016 
0017     if isnumeric(A) && isnumeric(scale)
0018         
0019         Ascale = multiscale(scale, A);
0020         
0021     else
0022         
0023         A = tocstruct(A);
0024         scale = tocstruct(scale);
0025         
0026         assert(ndims(A.real) == 3, ...
0027            'cmultiscale is only well defined for 3D arrays.');
0028        
0029         [~, ~, N] = size(A.real);
0030         
0031         assert(numel(scale.real) == N, ...
0032            ['scale must be a vector whose length equals the third ' ...
0033             'dimension of A, that is, the number of 2D matrix slices ' ...
0034             'in the 3D array A. It can also be a struct with fields ' ... 
0035             'real and imag with size as stated above.']);
0036         
0037         scale.real = reshape(scale.real, 1, 1, N);
0038         scale.imag = reshape(scale.imag, 1, 1, N);
0039         Ascale = cdottimes(A, scale);
0040 
0041     end
0042 
0043 end
0044 
0045 
0046 % Test code
0047 % n = 3; m = 5; N = 17;
0048 % A = randn(n, m, N);
0049 % scale = randn(N, 1);
0050 % Z = multiscale(scale, A) - cmultiscale(scale, A);
0051 % norm(Z(:))
0052 % A = randn(n, m, N) + 1i*randn(n, m, N);
0053 % Z = multiscale(scale, A) - cmultiscale(scale, A);
0054 % norm(Z(:))
0055 % scale = randn(N, 1) + 1i*randn(N, 1);
0056 % Z = multiscale(scale, A) - cmultiscale(scale, A);
0057 % norm(Z(:))
0058 % B.real = real(A); B.imag = imag(A);
0059 % Z = cmultiscale(scale, B);
0060 % Zr = real(multiscale(scale, A)) - Z.real;
0061 % Zi = imag(multiscale(scale, A)) - Z.imag;
0062 % norm(Zr(:))
0063 % norm(Zi(:))
0064 % scalebis = tocstruct(scale);
0065 % Z = cmultiscale(scalebis, B);
0066 % Zr = real(multiscale(scale, A)) - Z.real;
0067 % Zi = imag(multiscale(scale, A)) - Z.imag;
0068 % norm(Zr(:))
0069 % norm(Zi(:))

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005