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