Skip to main content
Tweeted twitter.com/StackMma/status/1417952554005241856
added 521 characters in body
Source Link

I am using AceGen to compile a subroutine for MatLabMATLAB. The subroutine involves several steps of linear algebra that yields a number of symmetric matrices. However, when using AceGen there seems to be some sort of optimization process that, when dealing with a symmetric matrix, only returns the upper triangularization of the matrix. How can I make sure that AceGen always uses the full symmetric matrices?

I have created a very simple example to illustrate my point. Consider the function "TestFunction" that takes in an arbitrary ${5\times 5}$ matrix (called input) and returns a few symmetric matrixmatrices (called outputoutput1, output2, and output3) where

$$ output = \frac{1}{2} \left( input + input^{T} \right) \,. $$$$ output1 = \frac{1}{2} \left( input + input^{T} \right) \,, $$ $$ output2 = input^{T}\, input \,,\text{ and} $$ $$ output3 = output2^{-1} \,. $$

The AceGen source code for "TestFunction" can be found herehere and is shown below

enter image description hereenter image description here

The compiled MatLabMATLAB code is available herehere.

The compiled MatLabMATLAB function is tested using the script "TestScript" which is available herehere and shown below.

enter image description hereenter image description here

The outputoutputs of "TestScript" isare shown below.

enter image description hereenter image description here

enter image description here

enter image description here

enter image description here

The output isoutputs are close to correct. However, instead of just the upper triangular matrixmatrices, I want the outputoutputs to be the full matrixmatrices, as shown by "Correct_output"the MATLAB outputs.

I have tried changing the optimization mode to "Mode"->"Plain" I have tried using

$$ \text{SMSFreeze}\left[output,\, \frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "Symmetric"->\text{True} \right] \,,\text{ and} $$$$ \text{SMSFreeze}\left[output1,\, \frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "Symmetric"->\text{True} \right] \,, $$

$$ \text{SMSFreeze}\left[ output,\,\frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "KeepStructure"->\text{True} \right] $$$$ \text{SMSFreeze}\left[ output1,\,\frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "KeepStructure"->\text{True} \right] \,,\text{ and} $$

$$ output1=\text{Table}\left[\frac{1}{2}\left( input [i,j] + input [j,i] \right),\{i,1,ndim\},\{j,1,ndim\} \right] $$

but nothing has worked.

Any help would be appreciated!

I am using AceGen to compile a subroutine for MatLab. The subroutine involves several steps of linear algebra that yields a number of symmetric matrices. However, when using AceGen there seems to be some sort of optimization process that, when dealing with a symmetric matrix, only returns the upper triangularization of the matrix. How can I make sure that AceGen always uses the full symmetric matrices?

I have created a very simple example to illustrate my point. Consider the function "TestFunction" that takes in an arbitrary ${5\times 5}$ matrix (called input) and returns a symmetric matrix (called output) where

$$ output = \frac{1}{2} \left( input + input^{T} \right) \,. $$

The AceGen source code for "TestFunction" can be found here and is shown below

enter image description here

The compiled MatLab code is available here.

The compiled MatLab function is tested using the script "TestScript" which is available here and shown below.

enter image description here

The output of "TestScript" is shown below.

enter image description here

The output is close to correct. However, instead of just the upper triangular matrix, I want the output to be the full matrix, as shown by "Correct_output".

I have tried changing the optimization mode to "Mode"->"Plain" I have tried using

$$ \text{SMSFreeze}\left[output,\, \frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "Symmetric"->\text{True} \right] \,,\text{ and} $$

$$ \text{SMSFreeze}\left[ output,\,\frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "KeepStructure"->\text{True} \right] $$

but nothing has worked.

Any help would be appreciated!

I am using AceGen to compile a subroutine for MATLAB. The subroutine involves several steps of linear algebra that yields a number of symmetric matrices. However, when using AceGen there seems to be some sort of optimization process that, when dealing with a symmetric matrix, only returns the upper triangularization of the matrix. How can I make sure that AceGen always uses the full symmetric matrices?

I have created a very simple example to illustrate my point. Consider the function "TestFunction" that takes in an arbitrary ${5\times 5}$ matrix (called input) and returns a few symmetric matrices (called output1, output2, and output3) where

$$ output1 = \frac{1}{2} \left( input + input^{T} \right) \,, $$ $$ output2 = input^{T}\, input \,,\text{ and} $$ $$ output3 = output2^{-1} \,. $$

The AceGen source code for "TestFunction" can be found here and is shown below

enter image description here

The compiled MATLAB code is available here.

The compiled MATLAB function is tested using the script "TestScript" which is available here and shown below.

enter image description here

The outputs of "TestScript" are shown below.

enter image description here

enter image description here

enter image description here

enter image description here

The outputs are close to correct. However, instead of just the upper triangular matrices, I want the outputs to be the full matrices, as shown by the MATLAB outputs.

I have tried changing the optimization mode to "Mode"->"Plain" I have tried using

$$ \text{SMSFreeze}\left[output1,\, \frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "Symmetric"->\text{True} \right] \,, $$

$$ \text{SMSFreeze}\left[ output1,\,\frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "KeepStructure"->\text{True} \right] \,,\text{ and} $$

$$ output1=\text{Table}\left[\frac{1}{2}\left( input [i,j] + input [j,i] \right),\{i,1,ndim\},\{j,1,ndim\} \right] $$

but nothing has worked.

Any help would be appreciated!

Source Link

AceGen: Keep full symmetric matrix

I am using AceGen to compile a subroutine for MatLab. The subroutine involves several steps of linear algebra that yields a number of symmetric matrices. However, when using AceGen there seems to be some sort of optimization process that, when dealing with a symmetric matrix, only returns the upper triangularization of the matrix. How can I make sure that AceGen always uses the full symmetric matrices?

I have created a very simple example to illustrate my point. Consider the function "TestFunction" that takes in an arbitrary ${5\times 5}$ matrix (called input) and returns a symmetric matrix (called output) where

$$ output = \frac{1}{2} \left( input + input^{T} \right) \,. $$

The AceGen source code for "TestFunction" can be found here and is shown below

enter image description here

The compiled MatLab code is available here.

The compiled MatLab function is tested using the script "TestScript" which is available here and shown below.

enter image description here

The output of "TestScript" is shown below.

enter image description here

The output is close to correct. However, instead of just the upper triangular matrix, I want the output to be the full matrix, as shown by "Correct_output".

I have tried changing the optimization mode to "Mode"->"Plain" I have tried using

$$ \text{SMSFreeze}\left[output,\, \frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "Symmetric"->\text{True} \right] \,,\text{ and} $$

$$ \text{SMSFreeze}\left[ output,\,\frac{1}{2} \left( input + \text{Transpose}\left[ input \right] \right) ,\, "KeepStructure"->\text{True} \right] $$

but nothing has worked.

Any help would be appreciated!