3
$\begingroup$

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!

$\endgroup$
10
  • $\begingroup$ Can you paste your code as a code instead of an image? $\endgroup$ Jul 2 at 6:03
  • $\begingroup$ There are links to the code labelled as 'here' in the question. These are in red and underlined. I tried pasting the code but I could not get the formatting right. So I just uploaded the code files to a shared folder accessible via the 'here' links $\endgroup$ Jul 2 at 6:06
  • 1
    $\begingroup$ Indeed, using your generated code only the upper triangular matrix is shown. I have noticed you are using version 7.006 of AceGen. I would suggest to use newer version (I'm using 7.101 but there is 7.208 already available). $\endgroup$ Jul 2 at 8:03
  • 1
    $\begingroup$ I have 7.208 already and have no Matlab at the moment so i cannot reproduce the problem, at least with Mathlink code returns full matrix. Can you try exporting within double SMSDo loop each element individually? Maybe that will work. $\endgroup$ Jul 2 at 10:43
  • 1
    $\begingroup$ @BHudobivnik For some reason exporting in a double SMSDo loop didn't work properly, probably an implementation error. However changing SMSExport[OutputMatrix1, output1\$\$]; to SMSExport[OutputMatrix1, Table[output1\$\$[i, j], {i, 1, ndim}, {j, 1, ndim}]]; has worked and now the full matrix is being exported as I want :D $\endgroup$ Jul 15 at 7:56
2
$\begingroup$

Export the components of the output matrices individually by changing the export section from

SMSExport[OutputMatrix1,output1$$];
SMSExport[OutputMatrix2,output2$$];
SMSExport[OutputMatrix3,output3$$];

to

SMSExport[OutputMatrix1, Table[output1$$[i, j], {i, 1, ndim}, {j, 1, ndim}]];
SMSExport[OutputMatrix2, Table[output2$$[i, j], {i, 1, ndim}, {j, 1, ndim}]];
SMSExport[OutputMatrix3, Table[output3$$[i, j], {i, 1, ndim}, {j, 1, ndim}]];
$\endgroup$
2
$\begingroup$

There was a bug in Matlab export that has been recently removed. Yust, update your AceGen.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.