You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_potrs.c 28 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*****************************************************************************
  2. Copyright (c) 2011-2016, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written
  16. permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **********************************************************************************/
  28. #include "openblas_utest.h"
  29. #if defined(ARCH_LOONGARCH64)
  30. #pragma GCC optimize("no-gcse")
  31. #endif
  32. /*
  33. void BLASFUNC(cpotrf)(char*, BLASINT*, complex float*, BLASINT*, BLASINT*);
  34. void BLASFUNC(zpotrs_(char*, BLASINT*, BLASINT*, complex double*,
  35. BLASINT*, complex double*, BLASINT*, BLASINT*);
  36. */
  37. //https://github.com/xianyi/OpenBLAS/issues/695
  38. CTEST(potrf, bug_695){
  39. openblas_complex_float A1[100] =
  40. {
  41. openblas_make_complex_float(5.8525753, +0.0),
  42. openblas_make_complex_float(-0.79540455, -0.7066077),
  43. openblas_make_complex_float(0.98274714, -1.3824869),
  44. openblas_make_complex_float(2.619998, -1.8532984),
  45. openblas_make_complex_float(-1.8306153, +1.2336911),
  46. openblas_make_complex_float(0.32275113, -0.015575029),
  47. openblas_make_complex_float(2.1968813, -1.0640624),
  48. openblas_make_complex_float(0.27894387, -0.97911835),
  49. openblas_make_complex_float(3.0476584, -0.18548489),
  50. openblas_make_complex_float(0.3842994, -0.7050991),
  51. openblas_make_complex_float(-0.79540455, +0.7066077),
  52. openblas_make_complex_float(8.313246, +0.0),
  53. openblas_make_complex_float(-1.8076122, +0.8882447),
  54. openblas_make_complex_float(0.47806996, -0.48494184),
  55. openblas_make_complex_float(0.5096429, +0.5395974),
  56. openblas_make_complex_float(-0.7285097, +0.10360408),
  57. openblas_make_complex_float(-1.1760061, +2.7146957),
  58. openblas_make_complex_float(-0.4271084, -0.042899966),
  59. openblas_make_complex_float(-1.7228563, -2.8335886),
  60. openblas_make_complex_float(1.8942566, -0.6389735),
  61. openblas_make_complex_float(0.98274714, +1.3824869),
  62. openblas_make_complex_float(-1.8076122, -0.8882447),
  63. openblas_make_complex_float(9.367975, +0.0),
  64. openblas_make_complex_float(-0.1838578, -0.6468568),
  65. openblas_make_complex_float(-1.8338387, -0.7064959),
  66. openblas_make_complex_float(0.041852742, +0.6556877),
  67. openblas_make_complex_float(2.5673025, -1.9732997),
  68. openblas_make_complex_float(-1.1148382, +0.15693812),
  69. openblas_make_complex_float(2.4704504, +1.0389464),
  70. openblas_make_complex_float(1.0858271, +1.298006),
  71. openblas_make_complex_float(2.619998, +1.8532984),
  72. openblas_make_complex_float(0.47806996, +0.48494184),
  73. openblas_make_complex_float(-0.1838578, +0.6468568),
  74. openblas_make_complex_float(3.1117508, +0.0),
  75. openblas_make_complex_float(-1.956626, -0.22825956),
  76. openblas_make_complex_float(0.07081801, +0.31801307),
  77. openblas_make_complex_float(0.3698375, +0.5400855),
  78. openblas_make_complex_float(0.80686307, -1.5315914),
  79. openblas_make_complex_float(1.5649154, +1.6229297),
  80. openblas_make_complex_float(-0.112077385, -1.2014246),
  81. openblas_make_complex_float(-1.8306153, -1.2336911),
  82. openblas_make_complex_float(0.5096429, -0.5395974),
  83. openblas_make_complex_float(-1.8338387, +0.7064959),
  84. openblas_make_complex_float(-1.956626, +0.22825956),
  85. openblas_make_complex_float(3.6439795, +0.0),
  86. openblas_make_complex_float(-0.2594722, -0.48786148),
  87. openblas_make_complex_float(-0.47636223, +0.27821827),
  88. openblas_make_complex_float(-0.61608654, +2.01858),
  89. openblas_make_complex_float(-2.7767487, -1.7693765),
  90. openblas_make_complex_float(0.048102796, +0.9741874),
  91. openblas_make_complex_float(0.32275113, +0.015575029),
  92. openblas_make_complex_float(-0.7285097, -0.10360408),
  93. openblas_make_complex_float(0.041852742, -0.6556877),
  94. openblas_make_complex_float(0.07081801, -0.31801307),
  95. openblas_make_complex_float(-0.2594722, +0.48786148),
  96. openblas_make_complex_float(3.624376, +0.0),
  97. openblas_make_complex_float(-1.6697118, -0.4017511),
  98. openblas_make_complex_float(-1.4397877, +0.7550918),
  99. openblas_make_complex_float(-0.31456697, +1.0403451),
  100. openblas_make_complex_float(-0.31978557, -0.13701046),
  101. openblas_make_complex_float(2.1968813, +1.0640624),
  102. openblas_make_complex_float(-1.1760061, -2.7146957),
  103. openblas_make_complex_float(2.5673025, +1.9732997),
  104. openblas_make_complex_float(0.3698375, -0.5400855),
  105. openblas_make_complex_float(-0.47636223, -0.27821827),
  106. openblas_make_complex_float(-1.6697118, +0.4017511),
  107. openblas_make_complex_float(6.8273163, +0.0),
  108. openblas_make_complex_float(-0.10051322, -0.24303961),
  109. openblas_make_complex_float(1.4415971, -0.29750675),
  110. openblas_make_complex_float(1.221786, +0.85654986),
  111. openblas_make_complex_float(0.27894387, +0.97911835),
  112. openblas_make_complex_float(-0.4271084, +0.042899966),
  113. openblas_make_complex_float(-1.1148382, -0.15693812),
  114. openblas_make_complex_float(0.80686307, +1.5315914),
  115. openblas_make_complex_float(-0.61608654, -2.01858),
  116. openblas_make_complex_float(-1.4397877, -0.7550918),
  117. openblas_make_complex_float(-0.10051322, +0.24303961),
  118. openblas_make_complex_float(3.4057708, +0.0),
  119. openblas_make_complex_float(-0.5856801, +1.0203559),
  120. openblas_make_complex_float(0.7103452, -0.8422135),
  121. openblas_make_complex_float(3.0476584, +0.18548489),
  122. openblas_make_complex_float(-1.7228563, +2.8335886),
  123. openblas_make_complex_float(2.4704504, -1.0389464),
  124. openblas_make_complex_float(1.5649154, -1.6229297),
  125. openblas_make_complex_float(-2.7767487, +1.7693765),
  126. openblas_make_complex_float(-0.31456697, -1.0403451),
  127. openblas_make_complex_float(1.4415971, +0.29750675),
  128. openblas_make_complex_float(-0.5856801, -1.0203559),
  129. openblas_make_complex_float(7.005772, +0.0),
  130. openblas_make_complex_float(-0.9617417, +1.2486815),
  131. openblas_make_complex_float(0.3842994, +0.7050991),
  132. openblas_make_complex_float(1.8942566, +0.6389735),
  133. openblas_make_complex_float(1.0858271, -1.298006),
  134. openblas_make_complex_float(-0.112077385, +1.2014246),
  135. openblas_make_complex_float(0.048102796, -0.9741874),
  136. openblas_make_complex_float(-0.31978557, +0.13701046),
  137. openblas_make_complex_float(1.221786, -0.85654986),
  138. openblas_make_complex_float(0.7103452, +0.8422135),
  139. openblas_make_complex_float(-0.9617417, -1.2486815),
  140. openblas_make_complex_float(3.4629636, +0.0)
  141. };
  142. char up = 'U';
  143. blasint n=10;
  144. blasint info[1];
  145. #ifdef BUILD_COMPLEX
  146. BLASFUNC(cpotrf)(&up, &n, (float*)(A1), &n, info);
  147. //printf("%g+%g*I\n", creal(A1[91]), cimag(A1[91]));
  148. #endif
  149. openblas_complex_double A2[100] =
  150. {
  151. openblas_make_complex_double(3.0607147216796875, +0.0),
  152. openblas_make_complex_double(-0.5905849933624268, -0.29020825028419495),
  153. openblas_make_complex_double(0.321084201335907, +0.45168760418891907),
  154. openblas_make_complex_double(0.8387917876243591, -0.644718587398529),
  155. openblas_make_complex_double(-0.3642411530017853, +0.051274992525577545),
  156. openblas_make_complex_double(0.8071482181549072, +0.33944568037986755),
  157. openblas_make_complex_double(0.013674172572791576, +0.21422699093818665),
  158. openblas_make_complex_double(0.35476258397102356, +0.42408594489097595),
  159. openblas_make_complex_double(-0.5991537570953369, -0.23082709312438965),
  160. openblas_make_complex_double(-0.0600702166557312, -0.2113417387008667),
  161. openblas_make_complex_double(-0.7954045534133911, +0.7066076993942261),
  162. openblas_make_complex_double(2.807175397872925, +0.0),
  163. openblas_make_complex_double(-0.1691000759601593, +0.313548743724823),
  164. openblas_make_complex_double(-0.30911174416542053, +0.7447023987770081),
  165. openblas_make_complex_double(-0.22347848117351532, +0.03316075727343559),
  166. openblas_make_complex_double(-0.4088296890258789, -1.0214389562606812),
  167. openblas_make_complex_double(-0.2344931811094284, +0.08056317269802094),
  168. openblas_make_complex_double(0.793269693851471, -0.17507623136043549),
  169. openblas_make_complex_double(0.03163455054163933, +0.20559945702552795),
  170. openblas_make_complex_double(0.13581633567810059, -0.2110036462545395),
  171. openblas_make_complex_double(0.9827471375465393, +1.3824869394302368),
  172. openblas_make_complex_double(-1.8076121807098389, -0.8882446885108948),
  173. openblas_make_complex_double(2.3277781009674072, +0.0),
  174. openblas_make_complex_double(0.830405056476593, -0.19296252727508545),
  175. openblas_make_complex_double(0.1394239068031311, -0.5260677933692932),
  176. openblas_make_complex_double(1.239942193031311, -0.09915469586849213),
  177. openblas_make_complex_double(0.06731037050485611, -0.059320636093616486),
  178. openblas_make_complex_double(0.11507681757211685, -0.1984301060438156),
  179. openblas_make_complex_double(-0.6843825578689575, +0.4647614359855652),
  180. openblas_make_complex_double(1.213119387626648, -0.7757048010826111),
  181. openblas_make_complex_double(2.619997978210449, +1.8532984256744385),
  182. openblas_make_complex_double(0.4780699610710144, +0.48494184017181396),
  183. openblas_make_complex_double(-0.18385779857635498, +0.6468567848205566),
  184. openblas_make_complex_double(2.0811400413513184, +0.0),
  185. openblas_make_complex_double(-0.035075582563877106, +0.09732913225889206),
  186. openblas_make_complex_double(0.27337002754211426, -0.9032229781150818),
  187. openblas_make_complex_double(-0.8374675512313843, +0.0479498989880085),
  188. openblas_make_complex_double(0.6916252374649048, +0.45711082220077515),
  189. openblas_make_complex_double(0.1883818507194519, +0.06482727080583572),
  190. openblas_make_complex_double(-0.32384994626045227, +0.05857187137007713),
  191. openblas_make_complex_double(-1.8306152820587158, -1.2336910963058472),
  192. openblas_make_complex_double(0.5096428990364075, -0.5395973920822144),
  193. openblas_make_complex_double(-1.833838701248169, +0.7064958810806274),
  194. openblas_make_complex_double(-1.956626057624817, +0.22825956344604492),
  195. openblas_make_complex_double(1.706615924835205, +0.0),
  196. openblas_make_complex_double(-0.2895336151123047, +0.17579378187656403),
  197. openblas_make_complex_double(-0.923172116279602, -0.4530014097690582),
  198. openblas_make_complex_double(0.5040621757507324, -0.37026339769363403),
  199. openblas_make_complex_double(-0.2824432849884033, -1.0374568700790405),
  200. openblas_make_complex_double(0.1399831622838974, +0.4977008104324341),
  201. openblas_make_complex_double(0.32275113463401794, +0.015575028955936432),
  202. openblas_make_complex_double(-0.7285097241401672, -0.10360407829284668),
  203. openblas_make_complex_double(0.041852742433547974, -0.655687689781189),
  204. openblas_make_complex_double(0.07081800699234009, -0.318013072013855),
  205. openblas_make_complex_double(-0.25947219133377075, +0.4878614842891693),
  206. openblas_make_complex_double(1.5735365152359009, +0.0),
  207. openblas_make_complex_double(-0.2647853195667267, -0.26654252409935),
  208. openblas_make_complex_double(-0.6190430521965027, -0.24699924886226654),
  209. openblas_make_complex_double(-0.6288471221923828, +0.48154571652412415),
  210. openblas_make_complex_double(0.02446540631353855, -0.2611822783946991),
  211. openblas_make_complex_double(2.1968812942504883, +1.0640623569488525),
  212. openblas_make_complex_double(-1.1760060787200928, -2.714695692062378),
  213. openblas_make_complex_double(2.5673024654388428, +1.9732997417449951),
  214. openblas_make_complex_double(0.3698374927043915, -0.54008549451828),
  215. openblas_make_complex_double(-0.4763622283935547, -0.27821826934814453),
  216. openblas_make_complex_double(-1.6697118282318115, +0.4017511010169983),
  217. openblas_make_complex_double(1.2674795389175415, +0.0),
  218. openblas_make_complex_double(0.3079095482826233, -0.07258892804384232),
  219. openblas_make_complex_double(-0.5929520130157471, -0.038360968232154846),
  220. openblas_make_complex_double(0.04388086497783661, -0.025549031794071198),
  221. openblas_make_complex_double(0.27894386649131775, +0.9791183471679688),
  222. openblas_make_complex_double(-0.42710840702056885, +0.0428999662399292),
  223. openblas_make_complex_double(-1.1148382425308228, -0.1569381207227707),
  224. openblas_make_complex_double(0.8068630695343018, +1.5315914154052734),
  225. openblas_make_complex_double(-0.6160865426063538, -2.0185799598693848),
  226. openblas_make_complex_double(-1.439787745475769, -0.7550917863845825),
  227. openblas_make_complex_double(-0.10051321983337402, +0.24303960800170898),
  228. openblas_make_complex_double(0.9066106081008911, +0.0),
  229. openblas_make_complex_double(0.05315789580345154, -0.06136537343263626),
  230. openblas_make_complex_double(-0.21304509043693542, +0.6494344472885132),
  231. openblas_make_complex_double(3.0476584434509277, +0.1854848861694336),
  232. openblas_make_complex_double(-1.7228562831878662, +2.8335886001586914),
  233. openblas_make_complex_double(2.4704504013061523, -1.0389463901519775),
  234. openblas_make_complex_double(1.564915418624878, -1.6229296922683716),
  235. openblas_make_complex_double(-2.7767486572265625, +1.769376516342163),
  236. openblas_make_complex_double(-0.314566969871521, -1.0403450727462769),
  237. openblas_make_complex_double(1.4415971040725708, +0.29750674962997437),
  238. openblas_make_complex_double(-0.5856801271438599, -1.0203559398651123),
  239. openblas_make_complex_double(0.5668219923973083, +0.0),
  240. openblas_make_complex_double(0.033351436257362366, -0.07832501083612442),
  241. openblas_make_complex_double(0.3842993974685669, +0.7050991058349609),
  242. openblas_make_complex_double(1.894256591796875, +0.6389734745025635),
  243. openblas_make_complex_double(1.085827112197876, -1.2980060577392578),
  244. openblas_make_complex_double(-0.11207738518714905, +1.2014245986938477),
  245. openblas_make_complex_double(0.04810279607772827, -0.9741873741149902),
  246. openblas_make_complex_double(-0.31978556513786316, +0.13701045513153076),
  247. openblas_make_complex_double(1.2217860221862793, -0.856549859046936),
  248. openblas_make_complex_double(0.7103452086448669, +0.84221351146698),
  249. openblas_make_complex_double(-0.9617416858673096, -1.2486815452575684),
  250. openblas_make_complex_double(0.0756804421544075, +0.0)
  251. };
  252. openblas_complex_double B[20] =
  253. {
  254. openblas_make_complex_double(-0.21782716937787788, -0.9222220085490986),
  255. openblas_make_complex_double(-0.7620356655676837, +0.15533508334193666),
  256. openblas_make_complex_double(-0.905011814118756, +0.2847570854574069),
  257. openblas_make_complex_double(-0.3451346708401685, +1.076948486041297),
  258. openblas_make_complex_double(0.25336108035924787, +0.975317836492159),
  259. openblas_make_complex_double(0.11192755545114, -0.1603741874112385),
  260. openblas_make_complex_double(-0.20604111555491242, +0.10570814584017311),
  261. openblas_make_complex_double(-1.0568488936791578, -0.06025820467086475),
  262. openblas_make_complex_double(-0.6650468984506477, -0.5000967284800251),
  263. openblas_make_complex_double(-1.0509472322215125, +0.5022165705328413),
  264. openblas_make_complex_double(-0.727775859267237, +0.50638268521728),
  265. openblas_make_complex_double(0.39947219167701153, -0.4576746001199889),
  266. openblas_make_complex_double(-0.7122162951294634, -0.630289556702497),
  267. openblas_make_complex_double(0.9870834574024372, -0.2825689605519449),
  268. openblas_make_complex_double(0.0628393808469436, -0.1253397353973715),
  269. openblas_make_complex_double(0.8439562576196216, +1.0850814110398734),
  270. openblas_make_complex_double(0.562377322638969, -0.2578030745663871),
  271. openblas_make_complex_double(0.12696236014017806, -0.09853584666755086),
  272. openblas_make_complex_double(-0.023682508769195098, +0.18093440285319276),
  273. openblas_make_complex_double(-0.7264975746431271, +0.31670415674097235)
  274. };
  275. char lo = 'L';
  276. blasint nrhs = 2;
  277. #ifdef BUILD_COMPLEX16
  278. BLASFUNC(zpotrs)(&lo, &n, &nrhs, (double*)(A2), &n, (double*)(B), &n, info);
  279. #endif
  280. // note that this is exactly equal to A1
  281. openblas_complex_float A3[100] =
  282. {
  283. openblas_make_complex_float(5.8525753, +0.0),
  284. openblas_make_complex_float(-0.79540455, -0.7066077),
  285. openblas_make_complex_float(0.98274714, -1.3824869),
  286. openblas_make_complex_float(2.619998, -1.8532984),
  287. openblas_make_complex_float(-1.8306153, +1.2336911),
  288. openblas_make_complex_float(0.32275113, -0.015575029),
  289. openblas_make_complex_float(2.1968813, -1.0640624),
  290. openblas_make_complex_float(0.27894387, -0.97911835),
  291. openblas_make_complex_float(3.0476584, -0.18548489),
  292. openblas_make_complex_float(0.3842994, -0.7050991),
  293. openblas_make_complex_float(-0.79540455, +0.7066077),
  294. openblas_make_complex_float(8.313246, +0.0),
  295. openblas_make_complex_float(-1.8076122, +0.8882447),
  296. openblas_make_complex_float(0.47806996, -0.48494184),
  297. openblas_make_complex_float(0.5096429, +0.5395974),
  298. openblas_make_complex_float(-0.7285097, +0.10360408),
  299. openblas_make_complex_float(-1.1760061, +2.7146957),
  300. openblas_make_complex_float(-0.4271084, -0.042899966),
  301. openblas_make_complex_float(-1.7228563, -2.8335886),
  302. openblas_make_complex_float(1.8942566, -0.6389735),
  303. openblas_make_complex_float(0.98274714, +1.3824869),
  304. openblas_make_complex_float(-1.8076122, -0.8882447),
  305. openblas_make_complex_float(9.367975, +0.0),
  306. openblas_make_complex_float(-0.1838578, -0.6468568),
  307. openblas_make_complex_float(-1.8338387, -0.7064959),
  308. openblas_make_complex_float(0.041852742, +0.6556877),
  309. openblas_make_complex_float(2.5673025, -1.9732997),
  310. openblas_make_complex_float(-1.1148382, +0.15693812),
  311. openblas_make_complex_float(2.4704504, +1.0389464),
  312. openblas_make_complex_float(1.0858271, +1.298006),
  313. openblas_make_complex_float(2.619998, +1.8532984),
  314. openblas_make_complex_float(0.47806996, +0.48494184),
  315. openblas_make_complex_float(-0.1838578, +0.6468568),
  316. openblas_make_complex_float(3.1117508, +0.0),
  317. openblas_make_complex_float(-1.956626, -0.22825956),
  318. openblas_make_complex_float(0.07081801, +0.31801307),
  319. openblas_make_complex_float(0.3698375, +0.5400855),
  320. openblas_make_complex_float(0.80686307, -1.5315914),
  321. openblas_make_complex_float(1.5649154, +1.6229297),
  322. openblas_make_complex_float(-0.112077385, -1.2014246),
  323. openblas_make_complex_float(-1.8306153, -1.2336911),
  324. openblas_make_complex_float(0.5096429, -0.5395974),
  325. openblas_make_complex_float(-1.8338387, +0.7064959),
  326. openblas_make_complex_float(-1.956626, +0.22825956),
  327. openblas_make_complex_float(3.6439795, +0.0),
  328. openblas_make_complex_float(-0.2594722, -0.48786148),
  329. openblas_make_complex_float(-0.47636223, +0.27821827),
  330. openblas_make_complex_float(-0.61608654, +2.01858),
  331. openblas_make_complex_float(-2.7767487, -1.7693765),
  332. openblas_make_complex_float(0.048102796, +0.9741874),
  333. openblas_make_complex_float(0.32275113, +0.015575029),
  334. openblas_make_complex_float(-0.7285097, -0.10360408),
  335. openblas_make_complex_float(0.041852742, -0.6556877),
  336. openblas_make_complex_float(0.07081801, -0.31801307),
  337. openblas_make_complex_float(-0.2594722, +0.48786148),
  338. openblas_make_complex_float(3.624376, +0.0),
  339. openblas_make_complex_float(-1.6697118, -0.4017511),
  340. openblas_make_complex_float(-1.4397877, +0.7550918),
  341. openblas_make_complex_float(-0.31456697, +1.0403451),
  342. openblas_make_complex_float(-0.31978557, -0.13701046),
  343. openblas_make_complex_float(2.1968813, +1.0640624),
  344. openblas_make_complex_float(-1.1760061, -2.7146957),
  345. openblas_make_complex_float(2.5673025, +1.9732997),
  346. openblas_make_complex_float(0.3698375, -0.5400855),
  347. openblas_make_complex_float(-0.47636223, -0.27821827),
  348. openblas_make_complex_float(-1.6697118, +0.4017511),
  349. openblas_make_complex_float(6.8273163, +0.0),
  350. openblas_make_complex_float(-0.10051322, -0.24303961),
  351. openblas_make_complex_float(1.4415971, -0.29750675),
  352. openblas_make_complex_float(1.221786, +0.85654986),
  353. openblas_make_complex_float(0.27894387, +0.97911835),
  354. openblas_make_complex_float(-0.4271084, +0.042899966),
  355. openblas_make_complex_float(-1.1148382, -0.15693812),
  356. openblas_make_complex_float(0.80686307, +1.5315914),
  357. openblas_make_complex_float(-0.61608654, -2.01858),
  358. openblas_make_complex_float(-1.4397877, -0.7550918),
  359. openblas_make_complex_float(-0.10051322, +0.24303961),
  360. openblas_make_complex_float(3.4057708, +0.0),
  361. openblas_make_complex_float(-0.5856801, +1.0203559),
  362. openblas_make_complex_float(0.7103452, -0.8422135),
  363. openblas_make_complex_float(3.0476584, +0.18548489),
  364. openblas_make_complex_float(-1.7228563, +2.8335886),
  365. openblas_make_complex_float(2.4704504, -1.0389464),
  366. openblas_make_complex_float(1.5649154, -1.6229297),
  367. openblas_make_complex_float(-2.7767487, +1.7693765),
  368. openblas_make_complex_float(-0.31456697, -1.0403451),
  369. openblas_make_complex_float(1.4415971, +0.29750675),
  370. openblas_make_complex_float(-0.5856801, -1.0203559),
  371. openblas_make_complex_float(7.005772, +0.0),
  372. openblas_make_complex_float(-0.9617417, +1.2486815),
  373. openblas_make_complex_float(0.3842994, +0.7050991),
  374. openblas_make_complex_float(1.8942566, +0.6389735),
  375. openblas_make_complex_float(1.0858271, -1.298006),
  376. openblas_make_complex_float(-0.112077385, +1.2014246),
  377. openblas_make_complex_float(0.048102796, -0.9741874),
  378. openblas_make_complex_float(-0.31978557, +0.13701046),
  379. openblas_make_complex_float(1.221786, -0.85654986),
  380. openblas_make_complex_float(0.7103452, +0.8422135),
  381. openblas_make_complex_float(-0.9617417, -1.2486815),
  382. openblas_make_complex_float(3.4629636, +0.0)
  383. };
  384. #ifdef BUILD_COMPLEX
  385. BLASFUNC(cpotrf)(&up, &n, (float*)(A3), &n, info);
  386. // printf("%g+%g*I\n", creal(A3[91]), cimag(A3[91]));
  387. if(isnan(CREAL(A3[91])) || isnan(CIMAG(A3[91]))) {
  388. CTEST_ERR("%s:%d got NaN", __FILE__, __LINE__);
  389. }
  390. #endif
  391. }
  392. // Check potrf factorizes a small problem correctly
  393. CTEST(potrf, smoketest_trivial){
  394. float A1s[4] = {2, 0.3, 0.3, 3};
  395. double A1d[4] = {2, 0.3, 0.3, 3};
  396. openblas_complex_float A1c[4] = {
  397. openblas_make_complex_float(2,0),
  398. openblas_make_complex_float(0.3,0.1),
  399. openblas_make_complex_float(0.3,-0.1),
  400. openblas_make_complex_float(3,0)
  401. };
  402. openblas_complex_double A1z[4] = {
  403. openblas_make_complex_double(2,0),
  404. openblas_make_complex_double(0.3,0.1),
  405. openblas_make_complex_double(0.3,-0.1),
  406. openblas_make_complex_double(3,0)
  407. };
  408. float zeros = 0, ones = 1;
  409. double zerod = 0, oned = 1;
  410. openblas_complex_float zeroc = openblas_make_complex_float(0, 0),
  411. onec = openblas_make_complex_float(1, 0);
  412. openblas_complex_double zeroz = openblas_make_complex_double(0, 0),
  413. onez = openblas_make_complex_float(1, 0);
  414. char uplo, trans1, trans2;
  415. blasint nv = 4;
  416. blasint n = 2;
  417. blasint inc = 1;
  418. blasint info = 0;
  419. int i, j, cycle;
  420. float As[4], Bs[4];
  421. double Ad[4], Bd[4];
  422. openblas_complex_float Ac[4], Bc[4];
  423. openblas_complex_double Az[4], Bz[4];
  424. for (cycle = 0; cycle < 2; ++cycle) {
  425. if (cycle == 0) {
  426. uplo = 'L';
  427. }
  428. else {
  429. uplo = 'U';
  430. }
  431. #ifdef BUILD_SINGLE
  432. BLASFUNC(scopy)(&nv, A1s, &inc, As, &inc);
  433. #endif
  434. #ifdef BUILD_DOUBLE
  435. BLASFUNC(dcopy)(&nv, A1d, &inc, Ad, &inc);
  436. #endif
  437. #ifdef BUILD_COMPLEX
  438. BLASFUNC(ccopy)(&nv, (float *)A1c, &inc, (float *)Ac, &inc);
  439. #endif
  440. #ifdef BUILD_COMPLEX16
  441. BLASFUNC(zcopy)(&nv, (double *)A1z, &inc, (double *)Az, &inc);
  442. #endif
  443. #ifdef BUILD_SINGLE
  444. BLASFUNC(spotrf)(&uplo, &n, As, &n, &info);
  445. if (info != 0) {
  446. CTEST_ERR("%s:%d info != 0", __FILE__, __LINE__);
  447. }
  448. #endif
  449. #ifdef BUILD_DOUBLE
  450. BLASFUNC(dpotrf)(&uplo, &n, Ad, &n, &info);
  451. if (info != 0) {
  452. CTEST_ERR("%s:%d info != 0", __FILE__, __LINE__);
  453. }
  454. #endif
  455. #ifdef BUILD_COMPLEX
  456. BLASFUNC(cpotrf)(&uplo, &n, (float *)Ac, &n, &info);
  457. if (info != 0) {
  458. CTEST_ERR("%s:%d info != 0", __FILE__, __LINE__);
  459. }
  460. #endif
  461. #ifdef BUILD_COMPLEX16
  462. BLASFUNC(zpotrf)(&uplo, &n, (double *)Az, &n, &info);
  463. if (info != 0) {
  464. CTEST_ERR("%s:%d info != 0", __FILE__, __LINE__);
  465. }
  466. #endif
  467. /* Fill the other triangle */
  468. if (uplo == 'L') {
  469. for (i = 0; i < n; ++i) {
  470. for (j = i+1; j < n; ++j) {
  471. As[i+n*j] = 0;
  472. Ad[i+n*j] = 0;
  473. Ac[i+n*j] = zeroc;
  474. Az[i+n*j] = zeroz;
  475. }
  476. }
  477. }
  478. else {
  479. for (i = 0; i < n; ++i) {
  480. for (j = 0; j < i; ++j) {
  481. As[i+n*j] = 0;
  482. Ad[i+n*j] = 0;
  483. Ac[i+n*j] = zeroc;
  484. Az[i+n*j] = zeroz;
  485. }
  486. }
  487. }
  488. /* B = A A^H or A^H A */
  489. if (uplo == 'L') {
  490. trans1 = 'N';
  491. trans2 = 'C';
  492. }
  493. else {
  494. trans1 = 'C';
  495. trans2 = 'N';
  496. }
  497. #ifdef BUILD_SINGLE
  498. BLASFUNC(sgemm)(&trans1, &trans2, &n, &n, &n, &ones, As, &n, As, &n, &zeros, Bs, &n);
  499. #endif
  500. #ifdef BUILD_DOUBLE
  501. BLASFUNC(dgemm)(&trans1, &trans2, &n, &n, &n, &oned, Ad, &n, Ad, &n, &zerod, Bd, &n);
  502. #endif
  503. #ifdef BUILD_COMPLEX
  504. BLASFUNC(cgemm)(&trans1, &trans2, &n, &n, &n, (float *)&onec,
  505. (float *)Ac, &n, (float *)Ac, &n, (float *)&zeroc, (float *)Bc, &n);
  506. #endif
  507. #ifdef BUILD_COMPLEX16
  508. BLASFUNC(zgemm)(&trans1, &trans2, &n, &n, &n, (double *)&onez,
  509. (double *)Az, &n, (double *)Az, &n, (double *)&zeroz, (double *)Bz, &n);
  510. #endif
  511. /* Check result is close to original */
  512. for (i = 0; i < n; ++i) {
  513. for (j = 0; j < n; ++j) {
  514. double err;
  515. #ifdef BUILD_SINGLE
  516. err = fabs(A1s[i+n*j] - Bs[i+n*j]);
  517. if (err > 1e-5) {
  518. CTEST_ERR("%s:%d %c s(%d,%d) difference: %g", __FILE__, __LINE__, uplo, i, j, err);
  519. }
  520. #endif
  521. #ifdef BUILD_DOUBLE
  522. err = fabs(A1d[i+n*j] - Bd[i+n*j]);
  523. if (err > 1e-12) {
  524. CTEST_ERR("%s:%d %c d(%d,%d) difference: %g", __FILE__, __LINE__, uplo, i, j, err);
  525. }
  526. #endif
  527. #ifdef BUILD_COMPLEX
  528. #ifdef OPENBLAS_COMPLEX_C99
  529. err = cabsf(A1c[i+n*j] - Bc[i+n*j]);
  530. #else
  531. err = hypot(A1c[i+n*j].real - Bc[i+n*j].real,
  532. A1c[i+n*j].imag - Bc[i+n*j].imag);
  533. #endif
  534. if (err > 1e-5) {
  535. CTEST_ERR("%s:%d %c c(%d,%d) difference: %g", __FILE__, __LINE__, uplo, i, j, err);
  536. }
  537. #endif
  538. #ifdef BUILD_COMPLEX16
  539. #ifdef OPENBLAS_COMPLEX_C99
  540. err = cabs(A1z[i+n*j] - Bz[i+n*j]);
  541. #else
  542. err = hypot(A1z[i+n*j].real - Bz[i+n*j].real,
  543. A1z[i+n*j].imag - Bz[i+n*j].imag);
  544. #endif
  545. if (err > 1e-12) {
  546. CTEST_ERR("%s:%d %c z(%d,%d) difference: %g", __FILE__, __LINE__, uplo, i, j, err);
  547. }
  548. #endif
  549. }
  550. }
  551. }
  552. }