<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Peder <div class=""><br class=""></div><div class="">We have a fix for the hdf5 complex reader here if you want to give it a try <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4044" class="">https://gitlab.com/petsc/petsc/-/merge_requests/4044</a><br class=""><div><br class=""></div><div>Sorry it took so long and thank you for reporting the bug</div><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 29, 2021, at 2:55 PM, Peder Jørgensgaard Olesen via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div id="x_divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class="">Thank you for your advice, Jose.</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">I tried<span class="Apple-converted-space"> </span><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;" class="">using a single column of the data matrix as a </span>basis for left singular vector space, and a row for the right one - and lo and behold, all singular vectors become real.</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Somehow it did not occur to me that I was I was looking at was simply a complex phase on U and V which would cancel upon computing UΣV*. In other words, rather than an incorrect result it was a slightly inconvenient representation of a correct result.</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Best regards</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Peder</div></div><hr tabindex="-1" style="display: inline-block; width: 861.40625px;" class=""><div id="x_divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">Fra:</b><span class="Apple-converted-space"> </span>Jose E. Roman <<a href="mailto:jroman@dsic.upv.es" class="">jroman@dsic.upv.es</a>><br class=""><b class="">Sendt:</b><span class="Apple-converted-space"> </span>29. april 2021 13:00:03<br class=""><b class="">Til:</b><span class="Apple-converted-space"> </span>Peder Jørgensgaard Olesen<br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a><br class=""><b class="">Emne:</b><span class="Apple-converted-space"> </span>Re: [petsc-users] SLEPc: non-real singular vectors from SVD of real matrix</font><div class=""> </div></div></div><font size="2" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="font-size: 10pt;" class=""><div class="PlainText">In complex scalars there is no way of knowing if the user-provided matrix is real or not. If there was an option of MatSetOption() we could use it.<br class=""><br class="">If you set a real initial vector with SVDSetInitialSpaces(), then most probably the computed singular vectors will be real. But still rounding errors could introduce a nonzero imaginary part.<br class=""><br class="">In any case, you could normalize the computed singular vectors, as is done for instance in FixSign() in this example<a href="https://slepc.upv.es/documentation/current/src/nep/tutorials/ex20.c.html" class="">https://slepc.upv.es/documentation/current/src/nep/tutorials/ex20.c.html</a><br class=""><br class="">Jose<br class=""><br class=""><br class="">> El 29 abr 2021, a las 12:42, Peder Jørgensgaard Olesen via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a>> escribió:<br class="">><span class="Apple-converted-space"> </span><br class="">> Hello<br class="">><span class="Apple-converted-space"> </span><br class="">> I've noticed that doing a singular value decomposition of a real matrix appears to result in non-real singular vectors. This should not be the case - singular vectors of a real matrix must be real-valued.<br class="">><span class="Apple-converted-space"> </span><br class="">> In the example attached I read a matrix from a binary file (also attached), perform the SVD, and write singular vectors to an HDF5 file which I subsequently inspect using h5dump, revealing non-zero imaginary parts of vector elements as highlighted below:<br class="">> [pjool@svol mwes]$ h5dump -d U0_sample_svd -c "5,2" sample_svecs.h5<span class="Apple-converted-space"> </span><br class="">> HDF5 "sample_svecs.h5" {<br class="">> DATASET "U0_sample_svd" {<br class="">> DATATYPE H5T_IEEE_F64LE<br class="">> DATASPACE SIMPLE { ( 882, 2 ) / ( 882, 2 ) }<br class="">> SUBSET {<br class="">> START ( 0, 0 );<br class="">> STRIDE ( 1, 1 );<br class="">> COUNT ( 5, 2 );<br class="">> BLOCK ( 1, 1 );<br class="">> DATA {<br class="">> (0,0): 0.0226108, 0.0299595,<br class="">> (1,0): 0.035414, 0.0469237,<br class="">> (2,0): 0.0276317, 0.0366122,<br class="">> (3,0): 0.0145344, 0.0192581,<br class="">> (4,0): 0.0110376, 0.0146249<br class="">> }<br class="">> }<br class="">> ATTRIBUTE "complex" {<br class="">> DATATYPE H5T_STD_I32LE<br class="">> DATASPACE SCALAR<br class="">> DATA {<br class="">> (0): 1<br class="">> }<br class="">> }<br class="">> }<br class="">> }<br class="">> I also extract the imaginary part of the input matrix and print its norm to ensure that the matrix is indeed real.<br class="">><span class="Apple-converted-space"> </span><br class="">> I'm running v3.14, but I don't believe that alone should cause the issue, since it what I'm trying to do appears like a rather common and basic task.<br class="">><span class="Apple-converted-space"> </span><br class="">> What might be the reason behind this behavior, and what can be done to resolve it?<br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">> Med venlig hilsen / Best Regards<br class="">><span class="Apple-converted-space"> </span><br class="">> Peder Jørgensgaard Olesen<br class="">> PhD Student, Turbulence Research Lab<br class="">> Dept. of Mechanical Engineering<br class="">> Technical University of Denmark<br class="">> Niels Koppels Allé<br class="">> Bygning 403, Rum 105<br class="">> DK-2800 Kgs. Lyngby<br class="">> <read_bin.c><sample_data></div></span></font></div></blockquote></div><br class=""></div></body></html>