Home > manopt > autodiff > functions_AD > cprod.m

# cprod

## PURPOSE

Computes the product of A and B

## SYNOPSIS

function prodAB = cprod(A,B)

## DESCRIPTION

``` Computes the product of A and B

function prodAB = cprod(A,B)

Returns the product of A and B. This function can be seen as A*B but is
compatible with dlarrays and structs with fields real and imag.

## CROSS-REFERENCE INFORMATION

This function calls: This function is called by:
• complex_example_AD A basic example that shows how to define the cost funtion for
• complextest_AD1 Test AD for a complex optimization problem on a product manifold (struct)
• complextest_AD2 Test AD for a complex optimization problem on a power manifold (cell)
• complextest_AD3 Test AD for a complex optimization problem on a manifold which is stored

## SOURCE CODE

```0001 function prodAB = cprod(A,B)
0002 % Computes the product of A and B
0003 %
0004 % function prodAB = cprod(A,B)
0005 %
0006 % Returns the product of A and B. This function can be seen as A*B but is
0007 % compatible with dlarrays and structs with fields real and imag.
0008 %
0010
0011 % This file is part of Manopt: www.manopt.org.
0012 % Original author: Xiaowen Jiang, July. 31, 2021.
0013 % Contributors: Nicolas Boumal
0014 % Change log:
0015
0016     if isnumeric(A) && iscstruct(B)
0017         realA = real(A);
0018         imagA = imag(A);
0019         prodAB.real = realA*B.real - imagA*B.imag;
0020         prodAB.imag = realA*B.imag + imagA*B.real;
0021
0022     elseif iscstruct(A) && isnumeric(B)
0023         realB = real(B);
0024         imagB = imag(B);
0025         prodAB.real = A.real*realB - A.imag*imagB;
0026         prodAB.imag = A.real*imagB + A.imag*realB;
0027
0028     elseif isnumeric(A) && isnumeric(B)
0029         prodAB = A*B;
0030
0031     elseif iscstruct(A) && iscstruct(B)
0032         prodAB.real = A.real*B.real - A.imag*B.imag;
0033         prodAB.imag = A.real*B.imag + A.imag*B.real;
0034
0035     else
0036         ME = MException('cprod:inputError', ...
0037                         'Input does not have the expected format.');
0038         throw(ME);
0039
0040     end
0041
0042 end```

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