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