NUMcblas.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019
  1. /* NUMcblas.cpp
  2. -- LAPACK helper routines -- Univ. of Tennessee, Univ. of
  3. California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab,
  4. and Rice University October 31, 1999 -- translated by f2c (version
  5. 19990503)
  6. Adapted by David Weenink 20021201
  7. */
  8. /*
  9. djmw 20020813 GPL header
  10. djmw 20071201 Latest modification
  11. pb 20100120 dlamc3_: declare volatile double ret_val to prevent optimization!
  12. pb 2018 logicals -> bools
  13. */
  14. /* #include "blaswrap.h" */
  15. #include "melder.h"
  16. #include "NUMcblas.h"
  17. #include "NUMf2c.h"
  18. #include "NUM2.h"
  19. #define MAX(m,n) ((m) > (n) ? (m) : (n))
  20. #define MIN(m,n) ((m) < (n) ? (m) : (n))
  21. static int dlamc1_ (integer *beta, integer *t, bool *rnd, bool *ieee1);
  22. static int dlamc2_ (integer *beta, integer *t, bool *rnd, double *eps, integer *emin, double *rmin, integer *emax,
  23. double *rmax);
  24. static double dlamc3_ (double *, double *);
  25. static int dlamc4_ (integer *emin, double *start, integer *base);
  26. static int dlamc5_ (integer *beta, integer *p, integer *emin, bool *ieee, integer *emax, double *rmax);
  27. int NUMblas_daxpy (integer *n, double *da, double *dx, integer *incx, double *dy, integer *incy) {
  28. /* System generated locals */
  29. integer i__1;
  30. /* Local variables */
  31. static integer i__, m, ix, iy, mp1;
  32. --dy;
  33. --dx;
  34. /* Function Body */
  35. if (*n <= 0) {
  36. return 0;
  37. }
  38. if (*da == 0.) {
  39. return 0;
  40. }
  41. if (*incx == 1 && *incy == 1) {
  42. goto L20;
  43. }
  44. /* code for unequal increments or equal increments not equal to 1 */
  45. ix = 1;
  46. iy = 1;
  47. if (*incx < 0) {
  48. ix = (- (*n) + 1) * *incx + 1;
  49. }
  50. if (*incy < 0) {
  51. iy = (- (*n) + 1) * *incy + 1;
  52. }
  53. i__1 = *n;
  54. for (i__ = 1; i__ <= i__1; ++i__) {
  55. dy[iy] += *da * dx[ix];
  56. ix += *incx;
  57. iy += *incy;
  58. /* L10: */
  59. }
  60. return 0;
  61. /* code for both increments equal to 1 clean-up loop */
  62. L20:
  63. m = *n % 4;
  64. if (m == 0) {
  65. goto L40;
  66. }
  67. i__1 = m;
  68. for (i__ = 1; i__ <= i__1; ++i__) {
  69. dy[i__] += *da * dx[i__];
  70. /* L30: */
  71. }
  72. if (*n < 4) {
  73. return 0;
  74. }
  75. L40:
  76. mp1 = m + 1;
  77. i__1 = *n;
  78. for (i__ = mp1; i__ <= i__1; i__ += 4) {
  79. dy[i__] += *da * dx[i__];
  80. dy[i__ + 1] += *da * dx[i__ + 1];
  81. dy[i__ + 2] += *da * dx[i__ + 2];
  82. dy[i__ + 3] += *da * dx[i__ + 3];
  83. /* L50: */
  84. }
  85. return 0;
  86. } /* NUMblas_daxpy */
  87. int NUMblas_dcopy (integer *n, double *dx, integer *incx, double *dy, integer *incy) {
  88. /* System generated locals */
  89. integer i__1;
  90. /* Local variables */
  91. static integer i__, m, ix, iy, mp1;
  92. --dy;
  93. --dx;
  94. /* Function Body */
  95. if (*n <= 0) {
  96. return 0;
  97. }
  98. if (*incx == 1 && *incy == 1) {
  99. goto L20;
  100. }
  101. /* code for unequal increments or equal increments not equal to 1 */
  102. ix = 1;
  103. iy = 1;
  104. if (*incx < 0) {
  105. ix = (- (*n) + 1) * *incx + 1;
  106. }
  107. if (*incy < 0) {
  108. iy = (- (*n) + 1) * *incy + 1;
  109. }
  110. i__1 = *n;
  111. for (i__ = 1; i__ <= i__1; ++i__) {
  112. dy[iy] = dx[ix];
  113. ix += *incx;
  114. iy += *incy;
  115. /* L10: */
  116. }
  117. return 0;
  118. /* code for both increments equal to 1 clean-up loop */
  119. L20:
  120. m = *n % 7;
  121. if (m == 0) {
  122. goto L40;
  123. }
  124. i__1 = m;
  125. for (i__ = 1; i__ <= i__1; ++i__) {
  126. dy[i__] = dx[i__];
  127. /* L30: */
  128. }
  129. if (*n < 7) {
  130. return 0;
  131. }
  132. L40:
  133. mp1 = m + 1;
  134. i__1 = *n;
  135. for (i__ = mp1; i__ <= i__1; i__ += 7) {
  136. dy[i__] = dx[i__];
  137. dy[i__ + 1] = dx[i__ + 1];
  138. dy[i__ + 2] = dx[i__ + 2];
  139. dy[i__ + 3] = dx[i__ + 3];
  140. dy[i__ + 4] = dx[i__ + 4];
  141. dy[i__ + 5] = dx[i__ + 5];
  142. dy[i__ + 6] = dx[i__ + 6];
  143. /* L50: */
  144. }
  145. return 0;
  146. } /* NUMblas_dcopy */
  147. double NUMblas_ddot (integer *n, double *dx, integer *incx, double *dy, integer *incy) {
  148. /* System generated locals */
  149. integer i__1;
  150. double ret_val;
  151. /* Local variables */
  152. static integer i__, m;
  153. static double dtemp;
  154. static integer ix, iy, mp1;
  155. /* Parameter adjustments */
  156. --dy;
  157. --dx;
  158. /* Function Body */
  159. ret_val = 0.;
  160. dtemp = 0.;
  161. if (*n <= 0) {
  162. return ret_val;
  163. }
  164. if (*incx == 1 && *incy == 1) {
  165. goto L20;
  166. }
  167. /* code for unequal increments or equal increments not equal to 1 */
  168. ix = 1;
  169. iy = 1;
  170. if (*incx < 0) {
  171. ix = (- (*n) + 1) * *incx + 1;
  172. }
  173. if (*incy < 0) {
  174. iy = (- (*n) + 1) * *incy + 1;
  175. }
  176. i__1 = *n;
  177. for (i__ = 1; i__ <= i__1; ++i__) {
  178. dtemp += dx[ix] * dy[iy];
  179. ix += *incx;
  180. iy += *incy;
  181. /* L10: */
  182. }
  183. ret_val = dtemp;
  184. return ret_val;
  185. /* code for both increments equal to 1 clean-up loop */
  186. L20:
  187. m = *n % 5;
  188. if (m == 0) {
  189. goto L40;
  190. }
  191. i__1 = m;
  192. for (i__ = 1; i__ <= i__1; ++i__) {
  193. dtemp += dx[i__] * dy[i__];
  194. /* L30: */
  195. }
  196. if (*n < 5) {
  197. goto L60;
  198. }
  199. L40:
  200. mp1 = m + 1;
  201. i__1 = *n;
  202. for (i__ = mp1; i__ <= i__1; i__ += 5) {
  203. dtemp =
  204. dtemp + dx[i__] * dy[i__] + dx[i__ + 1] * dy[i__ + 1] + dx[i__ + 2] * dy[i__ + 2] + dx[i__ +
  205. 3] * dy[i__ + 3] + dx[i__ + 4] * dy[i__ + 4];
  206. /* L50: */
  207. }
  208. L60:
  209. ret_val = dtemp;
  210. return ret_val;
  211. } /* NUMblas_ddot */
  212. int NUMblas_dgemm (const char *transa, const char *transb, integer *m, integer *n, integer *k, double *alpha, double *a, integer *lda,
  213. double *b, integer *ldb, double *beta, double *c__, integer *ldc) {
  214. /* System generated locals */
  215. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2, i__3;
  216. /* Local variables */
  217. static integer info;
  218. static integer nota, notb;
  219. static double temp;
  220. static integer i__, j, l, ncola;
  221. static integer nrowa, nrowb;
  222. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  223. #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
  224. #define c___ref(a_1,a_2) c__[(a_2)*c_dim1 + a_1]
  225. /*
  226. Set NOTA and NOTB as true if A and B respectively are not transposed
  227. and set NROWA, NCOLA and NROWB as the number of rows and columns of A
  228. and the number of rows of B respectively. Parameter adjustments */
  229. a_dim1 = *lda;
  230. a_offset = 1 + a_dim1 * 1;
  231. a -= a_offset;
  232. b_dim1 = *ldb;
  233. b_offset = 1 + b_dim1 * 1;
  234. b -= b_offset;
  235. c_dim1 = *ldc;
  236. c_offset = 1 + c_dim1 * 1;
  237. c__ -= c_offset;
  238. /* Function Body */
  239. nota = lsame_ (transa, "N");
  240. notb = lsame_ (transb, "N");
  241. if (nota) {
  242. nrowa = *m;
  243. ncola = *k;
  244. } else {
  245. nrowa = *k;
  246. ncola = *m;
  247. }
  248. if (notb) {
  249. nrowb = *k;
  250. } else {
  251. nrowb = *n;
  252. }
  253. /* Test the input parameters. */
  254. info = 0;
  255. if (!nota && !lsame_ (transa, "C") && !lsame_ (transa, "T")) {
  256. info = 1;
  257. } else if (!notb && !lsame_ (transb, "C") && !lsame_ (transb, "T")) {
  258. info = 2;
  259. } else if (*m < 0) {
  260. info = 3;
  261. } else if (*n < 0) {
  262. info = 4;
  263. } else if (*k < 0) {
  264. info = 5;
  265. } else if (*lda < MAX (1, nrowa)) {
  266. info = 8;
  267. } else if (*ldb < MAX (1, nrowb)) {
  268. info = 10;
  269. } else if (*ldc < MAX (1, *m)) {
  270. info = 13;
  271. }
  272. if (info != 0) {
  273. xerbla_ ("DGEMM ", &info);
  274. return 0;
  275. }
  276. /* Quick return if possible. */
  277. if (*m == 0 || *n == 0 || ((*alpha == 0. || *k == 0) && *beta == 1.)) {
  278. return 0;
  279. }
  280. /* And if alpha.eq.zero. */
  281. if (*alpha == 0.) {
  282. if (*beta == 0.) {
  283. i__1 = *n;
  284. for (j = 1; j <= i__1; ++j) {
  285. i__2 = *m;
  286. for (i__ = 1; i__ <= i__2; ++i__) {
  287. c___ref (i__, j) = 0.;
  288. /* L10: */
  289. }
  290. /* L20: */
  291. }
  292. } else {
  293. i__1 = *n;
  294. for (j = 1; j <= i__1; ++j) {
  295. i__2 = *m;
  296. for (i__ = 1; i__ <= i__2; ++i__) {
  297. c___ref (i__, j) = *beta * c___ref (i__, j);
  298. /* L30: */
  299. }
  300. /* L40: */
  301. }
  302. }
  303. return 0;
  304. }
  305. /* Start the operations. */
  306. if (notb) {
  307. if (nota) {
  308. /* Form C := alpha*A*B + beta*C. */
  309. i__1 = *n;
  310. for (j = 1; j <= i__1; ++j) {
  311. if (*beta == 0.) {
  312. i__2 = *m;
  313. for (i__ = 1; i__ <= i__2; ++i__) {
  314. c___ref (i__, j) = 0.;
  315. /* L50: */
  316. }
  317. } else if (*beta != 1.) {
  318. i__2 = *m;
  319. for (i__ = 1; i__ <= i__2; ++i__) {
  320. c___ref (i__, j) = *beta * c___ref (i__, j);
  321. /* L60: */
  322. }
  323. }
  324. i__2 = *k;
  325. for (l = 1; l <= i__2; ++l) {
  326. if (b_ref (l, j) != 0.) {
  327. temp = *alpha * b_ref (l, j);
  328. i__3 = *m;
  329. for (i__ = 1; i__ <= i__3; ++i__) {
  330. c___ref (i__, j) = c___ref (i__, j) + temp * a_ref (i__, l);
  331. /* L70: */
  332. }
  333. }
  334. /* L80: */
  335. }
  336. /* L90: */
  337. }
  338. } else {
  339. /* Form C := alpha*A'*B + beta*C */
  340. i__1 = *n;
  341. for (j = 1; j <= i__1; ++j) {
  342. i__2 = *m;
  343. for (i__ = 1; i__ <= i__2; ++i__) {
  344. temp = 0.;
  345. i__3 = *k;
  346. for (l = 1; l <= i__3; ++l) {
  347. temp += a_ref (l, i__) * b_ref (l, j);
  348. /* L100: */
  349. }
  350. if (*beta == 0.) {
  351. c___ref (i__, j) = *alpha * temp;
  352. } else {
  353. c___ref (i__, j) = *alpha * temp + *beta * c___ref (i__, j);
  354. }
  355. /* L110: */
  356. }
  357. /* L120: */
  358. }
  359. }
  360. } else {
  361. if (nota) {
  362. /* Form C := alpha*A*B' + beta*C */
  363. i__1 = *n;
  364. for (j = 1; j <= i__1; ++j) {
  365. if (*beta == 0.) {
  366. i__2 = *m;
  367. for (i__ = 1; i__ <= i__2; ++i__) {
  368. c___ref (i__, j) = 0.;
  369. /* L130: */
  370. }
  371. } else if (*beta != 1.) {
  372. i__2 = *m;
  373. for (i__ = 1; i__ <= i__2; ++i__) {
  374. c___ref (i__, j) = *beta * c___ref (i__, j);
  375. /* L140: */
  376. }
  377. }
  378. i__2 = *k;
  379. for (l = 1; l <= i__2; ++l) {
  380. if (b_ref (j, l) != 0.) {
  381. temp = *alpha * b_ref (j, l);
  382. i__3 = *m;
  383. for (i__ = 1; i__ <= i__3; ++i__) {
  384. c___ref (i__, j) = c___ref (i__, j) + temp * a_ref (i__, l);
  385. /* L150: */
  386. }
  387. }
  388. /* L160: */
  389. }
  390. /* L170: */
  391. }
  392. } else {
  393. /* Form C := alpha*A'*B' + beta*C */
  394. i__1 = *n;
  395. for (j = 1; j <= i__1; ++j) {
  396. i__2 = *m;
  397. for (i__ = 1; i__ <= i__2; ++i__) {
  398. temp = 0.;
  399. i__3 = *k;
  400. for (l = 1; l <= i__3; ++l) {
  401. temp += a_ref (l, i__) * b_ref (j, l);
  402. /* L180: */
  403. }
  404. if (*beta == 0.) {
  405. c___ref (i__, j) = *alpha * temp;
  406. } else {
  407. c___ref (i__, j) = *alpha * temp + *beta * c___ref (i__, j);
  408. }
  409. /* L190: */
  410. }
  411. /* L200: */
  412. }
  413. }
  414. }
  415. return 0;
  416. /* End of DGEMM . */
  417. } /* NUMblas_dgemm */
  418. #undef c___ref
  419. #undef b_ref
  420. #undef a_ref
  421. int NUMblas_dger (integer *m, integer *n, double *alpha, double *x, integer *incx, double *y, integer *incy, double *a,
  422. integer *lda) {
  423. /* System generated locals */
  424. integer a_dim1, a_offset, i__1, i__2;
  425. /* Local variables */
  426. static integer info;
  427. static double temp;
  428. static integer i__, j, ix, jy, kx;
  429. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  430. /* Test the input parameters. Parameter adjustments */
  431. --x;
  432. --y;
  433. a_dim1 = *lda;
  434. a_offset = 1 + a_dim1 * 1;
  435. a -= a_offset;
  436. /* Function Body */
  437. info = 0;
  438. if (*m < 0) {
  439. info = 1;
  440. } else if (*n < 0) {
  441. info = 2;
  442. } else if (*incx == 0) {
  443. info = 5;
  444. } else if (*incy == 0) {
  445. info = 7;
  446. } else if (*lda < MAX (1, *m)) {
  447. info = 9;
  448. }
  449. if (info != 0) {
  450. xerbla_ ("DGER ", &info);
  451. return 0;
  452. }
  453. /* Quick return if possible. */
  454. if (*m == 0 || *n == 0 || *alpha == 0.) {
  455. return 0;
  456. }
  457. /* Start the operations. In this version the elements of A are accessed
  458. sequentially with one pass through A. */
  459. if (*incy > 0) {
  460. jy = 1;
  461. } else {
  462. jy = 1 - (*n - 1) * *incy;
  463. }
  464. if (*incx == 1) {
  465. i__1 = *n;
  466. for (j = 1; j <= i__1; ++j) {
  467. if (y[jy] != 0.) {
  468. temp = *alpha * y[jy];
  469. i__2 = *m;
  470. for (i__ = 1; i__ <= i__2; ++i__) {
  471. a_ref (i__, j) = a_ref (i__, j) + x[i__] * temp;
  472. /* L10: */
  473. }
  474. }
  475. jy += *incy;
  476. /* L20: */
  477. }
  478. } else {
  479. if (*incx > 0) {
  480. kx = 1;
  481. } else {
  482. kx = 1 - (*m - 1) * *incx;
  483. }
  484. i__1 = *n;
  485. for (j = 1; j <= i__1; ++j) {
  486. if (y[jy] != 0.) {
  487. temp = *alpha * y[jy];
  488. ix = kx;
  489. i__2 = *m;
  490. for (i__ = 1; i__ <= i__2; ++i__) {
  491. a_ref (i__, j) = a_ref (i__, j) + x[ix] * temp;
  492. ix += *incx;
  493. /* L30: */
  494. }
  495. }
  496. jy += *incy;
  497. /* L40: */
  498. }
  499. }
  500. return 0;
  501. } /* NUMblas_dger */
  502. #undef a_ref
  503. int NUMblas_dgemv (const char *trans, integer *m, integer *n, double *alpha, double *a, integer *lda, double *x, integer *incx,
  504. double *beta, double *y, integer *incy) {
  505. /* System generated locals */
  506. integer a_dim1, a_offset, i__1, i__2;
  507. /* Local variables */
  508. static integer info;
  509. static double temp;
  510. static integer lenx, leny, i__, j;
  511. static integer ix, iy, jx, jy, kx, ky;
  512. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  513. /* Parameter adjustments */
  514. a_dim1 = *lda;
  515. a_offset = 1 + a_dim1 * 1;
  516. a -= a_offset;
  517. --x;
  518. --y;
  519. /* Function Body */
  520. info = 0;
  521. if (!lsame_ (trans, "N") && !lsame_ (trans, "T") && !lsame_ (trans, "C")) {
  522. info = 1;
  523. } else if (*m < 0) {
  524. info = 2;
  525. } else if (*n < 0) {
  526. info = 3;
  527. } else if (*lda < MAX (1, *m)) {
  528. info = 6;
  529. } else if (*incx == 0) {
  530. info = 8;
  531. } else if (*incy == 0) {
  532. info = 11;
  533. }
  534. if (info != 0) {
  535. xerbla_ ("DGEMV ", &info);
  536. return 0;
  537. }
  538. /* Quick return if possible. */
  539. if (*m == 0 || *n == 0 || (*alpha == 0. && *beta == 1.)) {
  540. return 0;
  541. }
  542. /* Set LENX and LENY, the lengths of the vectors x and y, and set up the
  543. start points in X and Y. */
  544. if (lsame_ (trans, "N")) {
  545. lenx = *n;
  546. leny = *m;
  547. } else {
  548. lenx = *m;
  549. leny = *n;
  550. }
  551. if (*incx > 0) {
  552. kx = 1;
  553. } else {
  554. kx = 1 - (lenx - 1) * *incx;
  555. }
  556. if (*incy > 0) {
  557. ky = 1;
  558. } else {
  559. ky = 1 - (leny - 1) * *incy;
  560. }
  561. /* Start the operations. In this version the elements of A are accessed
  562. sequentially with one pass through A. First form y := beta*y. */
  563. if (*beta != 1.) {
  564. if (*incy == 1) {
  565. if (*beta == 0.) {
  566. i__1 = leny;
  567. for (i__ = 1; i__ <= i__1; ++i__) {
  568. y[i__] = 0.;
  569. /* L10: */
  570. }
  571. } else {
  572. i__1 = leny;
  573. for (i__ = 1; i__ <= i__1; ++i__) {
  574. y[i__] = *beta * y[i__];
  575. /* L20: */
  576. }
  577. }
  578. } else {
  579. iy = ky;
  580. if (*beta == 0.) {
  581. i__1 = leny;
  582. for (i__ = 1; i__ <= i__1; ++i__) {
  583. y[iy] = 0.;
  584. iy += *incy;
  585. /* L30: */
  586. }
  587. } else {
  588. i__1 = leny;
  589. for (i__ = 1; i__ <= i__1; ++i__) {
  590. y[iy] = *beta * y[iy];
  591. iy += *incy;
  592. /* L40: */
  593. }
  594. }
  595. }
  596. }
  597. if (*alpha == 0.) {
  598. return 0;
  599. }
  600. if (lsame_ (trans, "N")) {
  601. /* Form y := alpha*A*x + y. */
  602. jx = kx;
  603. if (*incy == 1) {
  604. i__1 = *n;
  605. for (j = 1; j <= i__1; ++j) {
  606. if (x[jx] != 0.) {
  607. temp = *alpha * x[jx];
  608. i__2 = *m;
  609. for (i__ = 1; i__ <= i__2; ++i__) {
  610. y[i__] += temp * a_ref (i__, j);
  611. /* L50: */
  612. }
  613. }
  614. jx += *incx;
  615. /* L60: */
  616. }
  617. } else {
  618. i__1 = *n;
  619. for (j = 1; j <= i__1; ++j) {
  620. if (x[jx] != 0.) {
  621. temp = *alpha * x[jx];
  622. iy = ky;
  623. i__2 = *m;
  624. for (i__ = 1; i__ <= i__2; ++i__) {
  625. y[iy] += temp * a_ref (i__, j);
  626. iy += *incy;
  627. /* L70: */
  628. }
  629. }
  630. jx += *incx;
  631. /* L80: */
  632. }
  633. }
  634. } else {
  635. /* Form y := alpha*A'*x + y. */
  636. jy = ky;
  637. if (*incx == 1) {
  638. i__1 = *n;
  639. for (j = 1; j <= i__1; ++j) {
  640. temp = 0.;
  641. i__2 = *m;
  642. for (i__ = 1; i__ <= i__2; ++i__) {
  643. temp += a_ref (i__, j) * x[i__];
  644. /* L90: */
  645. }
  646. y[jy] += *alpha * temp;
  647. jy += *incy;
  648. /* L100: */
  649. }
  650. } else {
  651. i__1 = *n;
  652. for (j = 1; j <= i__1; ++j) {
  653. temp = 0.;
  654. ix = kx;
  655. i__2 = *m;
  656. for (i__ = 1; i__ <= i__2; ++i__) {
  657. temp += a_ref (i__, j) * x[ix];
  658. ix += *incx;
  659. /* L110: */
  660. }
  661. y[jy] += *alpha * temp;
  662. jy += *incy;
  663. /* L120: */
  664. }
  665. }
  666. }
  667. return 0;
  668. } /* NUMblas_dgemv */
  669. #undef a_ref
  670. double NUMblas_dlamch (const char *cmach) {
  671. /* Initialized data */
  672. static bool first = true;
  673. /* System generated locals */
  674. integer i__1;
  675. double ret_val;
  676. /* Builtin functions */
  677. /* Local variables */
  678. static double base;
  679. static integer beta;
  680. static double emin, prec, emax;
  681. static integer imin, imax;
  682. static bool lrnd;
  683. static double rmin, rmax, t, rmach;
  684. static double smal, sfmin;
  685. static integer it;
  686. static double rnd, eps;
  687. if (first) {
  688. first = false;
  689. dlamc2_ (&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax);
  690. base = (double) beta;
  691. t = (double) it;
  692. if (lrnd) {
  693. rnd = 1.;
  694. i__1 = 1 - it;
  695. eps = pow_di (&base, &i__1) / 2;
  696. } else {
  697. rnd = 0.;
  698. i__1 = 1 - it;
  699. eps = pow_di (&base, &i__1);
  700. }
  701. prec = eps * base;
  702. emin = (double) imin;
  703. emax = (double) imax;
  704. sfmin = rmin;
  705. smal = 1. / rmax;
  706. if (smal >= sfmin) {
  707. /* Use smal plus a bit, to avoid the possibility of rounding
  708. causing overflow when computing 1/sfmin. */
  709. sfmin = smal * (eps + 1.);
  710. }
  711. }
  712. if (lsame_ (cmach, "E")) {
  713. rmach = eps;
  714. } else if (lsame_ (cmach, "S")) {
  715. rmach = sfmin;
  716. } else if (lsame_ (cmach, "B")) {
  717. rmach = base;
  718. } else if (lsame_ (cmach, "P")) {
  719. rmach = prec;
  720. } else if (lsame_ (cmach, "N")) {
  721. rmach = t;
  722. } else if (lsame_ (cmach, "R")) {
  723. rmach = rnd;
  724. } else if (lsame_ (cmach, "M")) {
  725. rmach = emin;
  726. } else if (lsame_ (cmach, "U")) {
  727. rmach = rmin;
  728. } else if (lsame_ (cmach, "L")) {
  729. rmach = emax;
  730. } else if (lsame_ (cmach, "O")) {
  731. rmach = rmax;
  732. }
  733. ret_val = rmach;
  734. return ret_val;
  735. } /* NUMblas_dlamch */
  736. static int dlamc1_ (integer *beta, integer *t, bool *rnd, bool *ieee1) {
  737. /* -- LAPACK auxiliary routine (version 3.0) -- Univ. of Tennessee, Univ.
  738. of California Berkeley, NAG Ltd., Courant Institute, Argonne National
  739. Lab, and Rice University October 31, 1992
  740. Purpose =======
  741. DLAMC1 determines the machine parameters given by BETA, T, RND, and
  742. IEEE1.
  743. Arguments =========
  744. BETA (output) INTEGER The base of the machine.
  745. T (output) INTEGER The number of ( BETA ) digits in the mantissa.
  746. RND (output) LOGICAL Specifies whether proper rounding ( RND = .TRUE.
  747. ) or chopping ( RND = .FALSE. ) occurs in addition. This may not
  748. be a reliable guide to the way in which the machine performs
  749. its arithmetic.
  750. IEEE1 (output) LOGICAL Specifies whether rounding appears to be done
  751. in the IEEE 'round to nearest' style.
  752. Further Details ===============
  753. The routine is based on the routine ENVRON by Malcolm and incorporates
  754. suggestions by Gentleman and Marovich. See
  755. Malcolm M. A. (1972) Algorithms to reveal properties of floating-point
  756. arithmetic. Comms. of the ACM, 15, 949-951.
  757. Gentleman W. M. and Marovich S. B. (1974) More on algorithms that
  758. reveal properties of floating point arithmetic units. Comms. of the
  759. ACM, 17, 276-277.
  760. ===================================================================== */
  761. /* Initialized data */
  762. static bool first = true;
  763. /* System generated locals */
  764. double d__1, d__2;
  765. /* Local variables */
  766. static bool lrnd;
  767. static double a, b, c, f;
  768. static integer lbeta;
  769. static double savec;
  770. static bool lieee1;
  771. static double t1, t2;
  772. static integer lt;
  773. static double one, qtr;
  774. if (first) {
  775. first = false;
  776. one = 1.;
  777. /* LBETA, LIEEE1, LT and LRND are the local values of BETA, IEEE1, T
  778. and RND.
  779. Throughout this routine we use the function DLAMC3 to ensure that
  780. relevant values are stored and not held in registers, or are not
  781. affected by optimizers. Compute a = 2.0**m with the smallest
  782. positive integer m such that fl( a + 1.0 ) = a. */
  783. a = 1.;
  784. c = 1.;
  785. /* + WHILE( C.EQ.ONE )LOOP */
  786. L10:
  787. if (c == one) {
  788. a *= 2;
  789. c = dlamc3_ (&a, &one);
  790. d__1 = -a;
  791. c = dlamc3_ (&c, &d__1);
  792. goto L10;
  793. }
  794. /* + END WHILE
  795. Now compute b = 2.0**m with the smallest positive integer m such
  796. that fl( a + b ) .gt. a. */
  797. b = 1.;
  798. c = dlamc3_ (&a, &b);
  799. /* + WHILE( C.EQ.A )LOOP */
  800. L20:
  801. if (c == a) {
  802. b *= 2;
  803. c = dlamc3_ (&a, &b);
  804. goto L20;
  805. }
  806. /* + END WHILE
  807. Now compute the base. a and c are neighbouring floating point
  808. numbers in the interval ( beta**t, beta**( t + 1 ) ) and so their
  809. difference is beta. Adding 0.25 to c is to ensure that it is
  810. truncated to beta and not ( beta - 1 ). */
  811. qtr = one / 4;
  812. savec = c;
  813. d__1 = -a;
  814. c = dlamc3_ (&c, &d__1);
  815. lbeta = (integer) (c + qtr);
  816. /* Now determine whether rounding or chopping occurs, by adding a bit
  817. less than beta/2 and a bit more than beta/2 to a. */
  818. b = (double) lbeta;
  819. d__1 = b / 2;
  820. d__2 = -b / 100;
  821. f = dlamc3_ (&d__1, &d__2);
  822. c = dlamc3_ (&f, &a);
  823. if (c == a) {
  824. lrnd = true;
  825. } else {
  826. lrnd = false;
  827. }
  828. d__1 = b / 2;
  829. d__2 = b / 100;
  830. f = dlamc3_ (&d__1, &d__2);
  831. c = dlamc3_ (&f, &a);
  832. if (lrnd && c == a) {
  833. lrnd = false;
  834. }
  835. /* Try and decide whether rounding is done in the IEEE 'round to
  836. nearest' style. B/2 is half a unit in the last place of the two
  837. numbers A and SAVEC. Furthermore, A is even, i.e. has last bit
  838. zero, and SAVEC is odd. Thus adding B/2 to A should not change A,
  839. but adding B/2 to SAVEC should change SAVEC. */
  840. d__1 = b / 2;
  841. t1 = dlamc3_ (&d__1, &a);
  842. d__1 = b / 2;
  843. t2 = dlamc3_ (&d__1, &savec);
  844. lieee1 = t1 == a && t2 > savec && lrnd;
  845. /* Now find the mantissa, t. It should be the integer part of log to
  846. the base beta of a, however it is safer to determine t by
  847. powering. So we find t as the smallest positive integer for which
  848. fl( beta**t + 1.0 ) = 1.0. */
  849. lt = 0;
  850. a = 1.;
  851. c = 1.;
  852. /* + WHILE( C.EQ.ONE )LOOP */
  853. L30:
  854. if (c == one) {
  855. ++lt;
  856. a *= lbeta;
  857. c = dlamc3_ (&a, &one);
  858. d__1 = -a;
  859. c = dlamc3_ (&c, &d__1);
  860. goto L30;
  861. }
  862. /* + END WHILE */
  863. }
  864. *beta = lbeta;
  865. *t = lt;
  866. *rnd = lrnd;
  867. *ieee1 = lieee1;
  868. return 0;
  869. } /* dlamc1_ */
  870. static int dlamc2_ (integer *beta, integer *t, bool *rnd, double *eps, integer *emin, double *rmin, integer *emax,
  871. double *rmax) {
  872. /* -- LAPACK auxiliary routine (version 3.0) -- Univ. of Tennessee, Univ.
  873. of California Berkeley, NAG Ltd., Courant Institute, Argonne National
  874. Lab, and Rice University October 31, 1992
  875. Purpose =======
  876. DLAMC2 determines the machine parameters specified in its argument
  877. list.
  878. Arguments =========
  879. BETA (output) INTEGER The base of the machine.
  880. T (output) INTEGER The number of ( BETA ) digits in the mantissa.
  881. RND (output) LOGICAL Specifies whether proper rounding ( RND = .TRUE.
  882. ) or chopping ( RND = .FALSE. ) occurs in addition. This may not
  883. be a reliable guide to the way in which the machine performs
  884. its arithmetic.
  885. EPS (output) DOUBLE PRECISION The smallest positive number such that
  886. fl( 1.0 - EPS ) .LT. 1.0, where fl denotes the computed value.
  887. EMIN (output) INTEGER The minimum exponent before (gradual) underflow
  888. occurs.
  889. RMIN (output) DOUBLE PRECISION The smallest normalized number for the
  890. machine, given by BASE**( EMIN - 1 ), where BASE is the floating point
  891. value of BETA.
  892. EMAX (output) INTEGER The maximum exponent before overflow occurs.
  893. RMAX (output) DOUBLE PRECISION The largest positive number for the
  894. machine, given by BASE**EMAX * ( 1 - EPS ), where BASE is the floating
  895. point value of BETA.
  896. Further Details ===============
  897. The computation of EPS is based on a routine PARANOIA by W. Kahan of
  898. the University of California at Berkeley.
  899. ===================================================================== */
  900. /* Table of constant values */
  901. /* Initialized data */
  902. static bool first = true;
  903. static bool iwarn = false;
  904. /* System generated locals */
  905. integer i__1;
  906. double d__1, d__2, d__3, d__4, d__5;
  907. /* Builtin functions */
  908. /* Local variables */
  909. static bool ieee;
  910. static double half;
  911. static bool lrnd;
  912. static double leps, zero, a, b, c;
  913. static integer i, lbeta;
  914. static double rbase;
  915. static integer lemin, lemax, gnmin;
  916. static double smal;
  917. static integer gpmin;
  918. static double third, lrmin, lrmax, sixth;
  919. static bool lieee1;
  920. static integer lt, ngnmin, ngpmin;
  921. static double one, two;
  922. if (first) {
  923. first = false;
  924. zero = 0.;
  925. one = 1.;
  926. two = 2.;
  927. /* LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of
  928. BETA, T, RND, EPS, EMIN and RMIN. Throughout this routine we use
  929. the function DLAMC3 to ensure that relevant values are stored and
  930. not held in registers, or are not affected by optimizers. DLAMC1
  931. returns the parameters LBETA, LT, LRND and LIEEE1. */
  932. dlamc1_ (&lbeta, &lt, &lrnd, &lieee1);
  933. /* Start to find EPS. */
  934. b = (double) lbeta;
  935. i__1 = -lt;
  936. a = pow_di (&b, &i__1);
  937. leps = a;
  938. /* Try some tricks to see whether or not this is the correct EPS. */
  939. b = two / 3;
  940. half = one / 2;
  941. d__1 = -half;
  942. sixth = dlamc3_ (&b, &d__1);
  943. third = dlamc3_ (&sixth, &sixth);
  944. d__1 = -half;
  945. b = dlamc3_ (&third, &d__1);
  946. b = dlamc3_ (&b, &sixth);
  947. b = fabs (b);
  948. if (b < leps) {
  949. b = leps;
  950. }
  951. leps = 1.;
  952. /* + WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */
  953. L10:
  954. if (leps > b && b > zero) {
  955. leps = b;
  956. d__1 = half * leps;
  957. /* Computing 5th power */
  958. d__3 = two, d__4 = d__3, d__3 *= d__3;
  959. /* Computing 2nd power */
  960. d__5 = leps;
  961. d__2 = d__4 * (d__3 * d__3) * (d__5 * d__5);
  962. c = dlamc3_ (&d__1, &d__2);
  963. d__1 = -c;
  964. c = dlamc3_ (&half, &d__1);
  965. b = dlamc3_ (&half, &c);
  966. d__1 = -b;
  967. c = dlamc3_ (&half, &d__1);
  968. b = dlamc3_ (&half, &c);
  969. goto L10;
  970. }
  971. /* + END WHILE */
  972. if (a < leps) {
  973. leps = a;
  974. }
  975. /* Computation of EPS complete. Now find EMIN. Let A = + or - 1, and
  976. + or - (1 + BASE**(-3)). Keep dividing A by BETA until (gradual)
  977. underflow occurs. This is detected when we cannot recover the
  978. previous A. */
  979. rbase = one / lbeta;
  980. smal = one;
  981. for (i = 1; i <= 3; ++i) {
  982. d__1 = smal * rbase;
  983. smal = dlamc3_ (&d__1, &zero);
  984. /* L20: */
  985. }
  986. a = dlamc3_ (&one, &smal);
  987. dlamc4_ (&ngpmin, &one, &lbeta);
  988. d__1 = -one;
  989. dlamc4_ (&ngnmin, &d__1, &lbeta);
  990. dlamc4_ (&gpmin, &a, &lbeta);
  991. d__1 = -a;
  992. dlamc4_ (&gnmin, &d__1, &lbeta);
  993. ieee = false;
  994. if (ngpmin == ngnmin && gpmin == gnmin) {
  995. if (ngpmin == gpmin) {
  996. lemin = ngpmin;
  997. /* ( Non twos-complement machines, no gradual underflow;
  998. e.g., VAX ) */
  999. } else if (gpmin - ngpmin == 3) {
  1000. lemin = ngpmin - 1 + lt;
  1001. ieee = true;
  1002. /* ( Non twos-complement machines, with gradual underflow;
  1003. e.g., IEEE standard followers ) */
  1004. } else {
  1005. lemin = MIN (ngpmin, gpmin);
  1006. /* ( A guess; no known machine ) */
  1007. iwarn = true;
  1008. }
  1009. } else if (ngpmin == gpmin && ngnmin == gnmin) {
  1010. if ( (i__1 = ngpmin - ngnmin, labs (i__1)) == 1) {
  1011. lemin = MAX (ngpmin, ngnmin);
  1012. /* ( Twos-complement machines, no gradual underflow; e.g.,
  1013. CYBER 205 ) */
  1014. } else {
  1015. lemin = MIN (ngpmin, ngnmin);
  1016. /* ( A guess; no known machine ) */
  1017. iwarn = true;
  1018. }
  1019. } else if ( (i__1 = ngpmin - ngnmin, labs (i__1)) == 1 && gpmin == gnmin) {
  1020. if (gpmin - MIN (ngpmin, ngnmin) == 3) {
  1021. lemin = MAX (ngpmin, ngnmin) - 1 + lt;
  1022. /* ( Twos-complement machines with gradual underflow; no
  1023. known machine ) */
  1024. } else {
  1025. lemin = MIN (ngpmin, ngnmin);
  1026. /* ( A guess; no known machine ) */
  1027. iwarn = true;
  1028. }
  1029. } else {
  1030. /* Computing MIN */
  1031. i__1 = MIN (ngpmin, ngnmin), i__1 = MIN (i__1, gpmin);
  1032. lemin = MIN (i__1, gnmin);
  1033. /* ( A guess; no known machine ) */
  1034. iwarn = true;
  1035. }
  1036. /* Comment out this if block if EMIN is ok */
  1037. if (iwarn) {
  1038. first = true;
  1039. Melder_warning (U"\n\n WARNING. The value EMIN may be incorrect:- " "EMIN = ", lemin,
  1040. U"\nIf, after inspection, the value EMIN looks acceptable"
  1041. "please comment out \n the IF block as marked within the"
  1042. "code of routine DLAMC2, \n otherwise supply EMIN" "explicitly.\n");
  1043. }
  1044. /* ** Assume IEEE arithmetic if we found denormalised numbers above,
  1045. or if arithmetic seems to round in the IEEE style, determined in
  1046. routine DLAMC1. A true IEEE machine should have both things true;
  1047. however, faulty machines may have one or the other. */
  1048. ieee = ieee || lieee1;
  1049. /* Compute RMIN by successive division by BETA. We could compute RMIN
  1050. as BASE**( EMIN - 1 ), but some machines underflow during this
  1051. computation. */
  1052. lrmin = 1.;
  1053. i__1 = 1 - lemin;
  1054. for (i = 1; i <= 1 - lemin; ++i) {
  1055. d__1 = lrmin * rbase;
  1056. lrmin = dlamc3_ (&d__1, &zero);
  1057. /* L30: */
  1058. }
  1059. /* Finally, call DLAMC5 to compute EMAX and RMAX. */
  1060. dlamc5_ (&lbeta, &lt, &lemin, &ieee, &lemax, &lrmax);
  1061. }
  1062. *beta = lbeta;
  1063. *t = lt;
  1064. *rnd = lrnd;
  1065. *eps = leps;
  1066. *emin = lemin;
  1067. *rmin = lrmin;
  1068. *emax = lemax;
  1069. *rmax = lrmax;
  1070. return 0;
  1071. } /* dlamc2_ */
  1072. static double dlamc3_ (double *a, double *b)
  1073. /* Purpose =======
  1074. dlamc3_ is intended to force A and B to be stored prior to doing the
  1075. addition of A and B , for use in situations where optimizers might hold
  1076. one of these in a register.
  1077. Arguments =========
  1078. A, B (input) DOUBLE PRECISION The values A and B.
  1079. ===================================================================== */
  1080. {
  1081. volatile double ret_val;
  1082. ret_val = *a + *b;
  1083. return ret_val;
  1084. } /* dlamc3_ */
  1085. static int dlamc4_ (integer *emin, double *start, integer *base) {
  1086. /* -- LAPACK auxiliary routine (version 2.0) -- Univ. of Tennessee, Univ.
  1087. of California Berkeley, NAG Ltd., Courant Institute, Argonne National
  1088. Lab, and Rice University October 31, 1992
  1089. Purpose =======
  1090. DLAMC4 is a service routine for DLAMC2.
  1091. Arguments =========
  1092. EMIN (output) EMIN The minimum exponent before (gradual) underflow,
  1093. computed by
  1094. setting A = START and dividing by BASE until the previous A can not be
  1095. recovered.
  1096. START (input) DOUBLE PRECISION The starting point for determining
  1097. EMIN.
  1098. BASE (input) INTEGER The base of the machine.
  1099. ===================================================================== */
  1100. /* System generated locals */
  1101. integer i__1;
  1102. double d__1;
  1103. /* Local variables */
  1104. static double zero, a;
  1105. static integer i;
  1106. static double rbase, b1, b2, c1, c2, d1, d2;
  1107. static double one;
  1108. a = *start;
  1109. one = 1.;
  1110. rbase = one / *base;
  1111. zero = 0.;
  1112. *emin = 1;
  1113. d__1 = a * rbase;
  1114. b1 = dlamc3_ (&d__1, &zero);
  1115. c1 = a;
  1116. c2 = a;
  1117. d1 = a;
  1118. d2 = a;
  1119. /* + WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. $ ( D1.EQ.A ).AND.( D2.EQ.A
  1120. ) )LOOP */
  1121. L10:
  1122. if (c1 == a && c2 == a && d1 == a && d2 == a) {
  1123. -- (*emin);
  1124. a = b1;
  1125. d__1 = a / *base;
  1126. b1 = dlamc3_ (&d__1, &zero);
  1127. d__1 = b1 * *base;
  1128. c1 = dlamc3_ (&d__1, &zero);
  1129. d1 = zero;
  1130. i__1 = *base;
  1131. for (i = 1; i <= *base; ++i) {
  1132. d1 += b1;
  1133. /* L20: */
  1134. }
  1135. d__1 = a * rbase;
  1136. b2 = dlamc3_ (&d__1, &zero);
  1137. d__1 = b2 / rbase;
  1138. c2 = dlamc3_ (&d__1, &zero);
  1139. d2 = zero;
  1140. i__1 = *base;
  1141. for (i = 1; i <= *base; ++i) {
  1142. d2 += b2;
  1143. /* L30: */
  1144. }
  1145. goto L10;
  1146. }
  1147. /* + END WHILE */
  1148. return 0;
  1149. } /* dlamc4_ */
  1150. static int dlamc5_ (integer *beta, integer *p, integer *emin, bool *ieee, integer *emax, double *rmax) {
  1151. /*
  1152. First compute LEXP and UEXP, two powers of 2 that bound abs(EMIN). We
  1153. then assume that EMAX + abs(EMIN) will sum approximately to the bound
  1154. that is closest to abs(EMIN). (EMAX is the exponent of the required
  1155. number RMAX). */
  1156. /* Table of constant values */
  1157. static double c_b5 = 0.;
  1158. /* System generated locals */
  1159. integer i__1;
  1160. double d__1;
  1161. /* Local variables */
  1162. static integer lexp;
  1163. static double oldy;
  1164. static integer uexp, i;
  1165. static double y, z;
  1166. static integer nbits;
  1167. static double recbas;
  1168. static integer exbits, expsum, try__;
  1169. lexp = 1;
  1170. exbits = 1;
  1171. L10:
  1172. try__ = lexp << 1;
  1173. if (try__ <= - (*emin)) {
  1174. lexp = try__;
  1175. ++exbits;
  1176. goto L10;
  1177. }
  1178. if (lexp == - (*emin)) {
  1179. uexp = lexp;
  1180. } else {
  1181. uexp = try__;
  1182. ++exbits;
  1183. }
  1184. /* Now -LEXP is less than or equal to EMIN, and -UEXP is greater than or
  1185. equal to EMIN. EXBITS is the number of bits needed to store the
  1186. exponent. */
  1187. if (uexp + *emin > -lexp - *emin) {
  1188. expsum = lexp << 1;
  1189. } else {
  1190. expsum = uexp << 1;
  1191. }
  1192. /* EXPSUM is the exponent range, approximately equal to EMAX - EMIN + 1 .
  1193. */
  1194. *emax = expsum + *emin - 1;
  1195. nbits = exbits + 1 + *p;
  1196. /* NBITS is the total number of bits needed to store a floating-point
  1197. number. */
  1198. if (nbits % 2 == 1 && *beta == 2) {
  1199. /* Either there are an odd number of bits used to store a
  1200. floating-point number, which is unlikely, or some bits are not
  1201. used in the representation of numbers, which is possible, (e.g.
  1202. Cray machines) or the mantissa has an implicit bit, (e.g. IEEE
  1203. machines, Dec Vax machines), which is perhaps the most likely. We
  1204. have to assume the last alternative. If this is true, then we need
  1205. to reduce EMAX by one because there should be some way of
  1206. representing zero in an implicit-bit system. On machines like
  1207. Cray, we are reducing EMAX by one unnecessarily. */
  1208. -- (*emax);
  1209. }
  1210. if (*ieee) {
  1211. /* Assume we are on an IEEE machine which reserves one exponent for
  1212. infinity and NaN. */
  1213. -- (*emax);
  1214. }
  1215. /* Now create RMAX, the largest machine number, which should be equal to
  1216. (1.0 - BETA**(-P)) * BETA**EMAX . First compute 1.0 - BETA**(-P),
  1217. being careful that the result is less than 1.0 . */
  1218. recbas = 1. / *beta;
  1219. z = *beta - 1.;
  1220. y = 0.;
  1221. i__1 = *p;
  1222. for (i = 1; i <= *p; ++i) {
  1223. z *= recbas;
  1224. if (y < 1.) {
  1225. oldy = y;
  1226. }
  1227. y = dlamc3_ (&y, &z);
  1228. /* L20: */
  1229. }
  1230. if (y >= 1.) {
  1231. y = oldy;
  1232. }
  1233. /* Now multiply by BETA**EMAX to get RMAX. */
  1234. i__1 = *emax;
  1235. for (i = 1; i <= *emax; ++i) {
  1236. d__1 = y * *beta;
  1237. y = dlamc3_ (&d__1, &c_b5);
  1238. /* L30: */
  1239. }
  1240. *rmax = y;
  1241. return 0;
  1242. } /* dlamc5_ */
  1243. double NUMblas_dnrm2 (integer *n, double *x, integer *incx) {
  1244. /* The following loop is equivalent to this call to the LAPACK auxiliary
  1245. routine: CALL DLASSQ( N, X, INCX, SCALE, SSQ ) */
  1246. /* System generated locals */
  1247. integer i__1, i__2;
  1248. double ret_val, d__1;
  1249. /* Local variables */
  1250. static double norm, scale, absxi;
  1251. static integer ix;
  1252. static double ssq;
  1253. --x;
  1254. /* Function Body */
  1255. if (*n < 1 || *incx < 1) {
  1256. norm = 0.;
  1257. } else if (*n == 1) {
  1258. norm = fabs (x[1]);
  1259. } else {
  1260. scale = 0.;
  1261. ssq = 1.;
  1262. i__1 = (*n - 1) * *incx + 1;
  1263. i__2 = *incx;
  1264. for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
  1265. if (x[ix] != 0.) {
  1266. absxi = (d__1 = x[ix], fabs (d__1));
  1267. if (scale < absxi) {
  1268. /* Computing 2nd power */
  1269. d__1 = scale / absxi;
  1270. ssq = ssq * (d__1 * d__1) + 1.;
  1271. scale = absxi;
  1272. } else {
  1273. /* Computing 2nd power */
  1274. d__1 = absxi / scale;
  1275. ssq += d__1 * d__1;
  1276. }
  1277. }
  1278. /* L10: */
  1279. }
  1280. norm = scale * sqrt (ssq);
  1281. }
  1282. ret_val = norm;
  1283. return ret_val;
  1284. } /* NUMblas_dnrm2 */
  1285. int NUMblas_drot (integer *n, double *dx, integer *incx, double *dy, integer *incy, double *c__, double *s) {
  1286. /* System generated locals */
  1287. integer i__1;
  1288. /* Local variables */
  1289. static integer i__;
  1290. static double dtemp;
  1291. static integer ix, iy;
  1292. /* applies a plane rotation. jack dongarra, linpack, 3/11/78. modified
  1293. 12/3/93, array(1) declarations changed to array(*) Parameter
  1294. adjustments */
  1295. --dy;
  1296. --dx;
  1297. /* Function Body */
  1298. if (*n <= 0) {
  1299. return 0;
  1300. }
  1301. if (*incx == 1 && *incy == 1) {
  1302. goto L20;
  1303. }
  1304. /* code for unequal increments or equal increments not equal to 1 */
  1305. ix = 1;
  1306. iy = 1;
  1307. if (*incx < 0) {
  1308. ix = (- (*n) + 1) * *incx + 1;
  1309. }
  1310. if (*incy < 0) {
  1311. iy = (- (*n) + 1) * *incy + 1;
  1312. }
  1313. i__1 = *n;
  1314. for (i__ = 1; i__ <= i__1; ++i__) {
  1315. dtemp = *c__ * dx[ix] + *s * dy[iy];
  1316. dy[iy] = *c__ * dy[iy] - *s * dx[ix];
  1317. dx[ix] = dtemp;
  1318. ix += *incx;
  1319. iy += *incy;
  1320. /* L10: */
  1321. }
  1322. return 0;
  1323. /* code for both increments equal to 1 */
  1324. L20:
  1325. i__1 = *n;
  1326. for (i__ = 1; i__ <= i__1; ++i__) {
  1327. dtemp = *c__ * dx[i__] + *s * dy[i__];
  1328. dy[i__] = *c__ * dy[i__] - *s * dx[i__];
  1329. dx[i__] = dtemp;
  1330. /* L30: */
  1331. }
  1332. return 0;
  1333. } /* NUMblas_drot */
  1334. int NUMblas_dscal (integer *n, double *da, double *dx, integer *incx) {
  1335. /* System generated locals */
  1336. integer i__1, i__2;
  1337. /* Local variables */
  1338. static integer i__, m, nincx, mp1;
  1339. /* Parameter adjustments */
  1340. --dx;
  1341. /* Function Body */
  1342. if (*n <= 0 || *incx <= 0) {
  1343. return 0;
  1344. }
  1345. if (*incx == 1) {
  1346. goto L20;
  1347. }
  1348. /* code for increment not equal to 1 */
  1349. nincx = *n * *incx;
  1350. i__1 = nincx;
  1351. i__2 = *incx;
  1352. for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  1353. dx[i__] = *da * dx[i__];
  1354. /* L10: */
  1355. }
  1356. return 0;
  1357. /* code for increment equal to 1 clean-up loop */
  1358. L20:
  1359. m = *n % 5;
  1360. if (m == 0) {
  1361. goto L40;
  1362. }
  1363. i__2 = m;
  1364. for (i__ = 1; i__ <= i__2; ++i__) {
  1365. dx[i__] = *da * dx[i__];
  1366. /* L30: */
  1367. }
  1368. if (*n < 5) {
  1369. return 0;
  1370. }
  1371. L40:
  1372. mp1 = m + 1;
  1373. i__2 = *n;
  1374. for (i__ = mp1; i__ <= i__2; i__ += 5) {
  1375. dx[i__] = *da * dx[i__];
  1376. dx[i__ + 1] = *da * dx[i__ + 1];
  1377. dx[i__ + 2] = *da * dx[i__ + 2];
  1378. dx[i__ + 3] = *da * dx[i__ + 3];
  1379. dx[i__ + 4] = *da * dx[i__ + 4];
  1380. /* L50: */
  1381. }
  1382. return 0;
  1383. } /* dscal_ */
  1384. int NUMblas_dswap (integer *n, double *dx, integer *incx, double *dy, integer *incy) {
  1385. /* System generated locals */
  1386. integer i__1;
  1387. /* Local variables */
  1388. static integer i__, m;
  1389. static double dtemp;
  1390. static integer ix, iy, mp1;
  1391. /* interchanges two vectors. uses unrolled loops for increments equal
  1392. one. jack dongarra, linpack, 3/11/78. modified 12/3/93, array(1)
  1393. declarations changed to array(*) Parameter adjustments */
  1394. --dy;
  1395. --dx;
  1396. /* Function Body */
  1397. if (*n <= 0) {
  1398. return 0;
  1399. }
  1400. if (*incx == 1 && *incy == 1) {
  1401. goto L20;
  1402. }
  1403. /* code for unequal increments or equal increments not equal to 1 */
  1404. ix = 1;
  1405. iy = 1;
  1406. if (*incx < 0) {
  1407. ix = (- (*n) + 1) * *incx + 1;
  1408. }
  1409. if (*incy < 0) {
  1410. iy = (- (*n) + 1) * *incy + 1;
  1411. }
  1412. i__1 = *n;
  1413. for (i__ = 1; i__ <= i__1; ++i__) {
  1414. dtemp = dx[ix];
  1415. dx[ix] = dy[iy];
  1416. dy[iy] = dtemp;
  1417. ix += *incx;
  1418. iy += *incy;
  1419. /* L10: */
  1420. }
  1421. return 0;
  1422. /* code for both increments equal to 1 clean-up loop */
  1423. L20:
  1424. m = *n % 3;
  1425. if (m == 0) {
  1426. goto L40;
  1427. }
  1428. i__1 = m;
  1429. for (i__ = 1; i__ <= i__1; ++i__) {
  1430. dtemp = dx[i__];
  1431. dx[i__] = dy[i__];
  1432. dy[i__] = dtemp;
  1433. /* L30: */
  1434. }
  1435. if (*n < 3) {
  1436. return 0;
  1437. }
  1438. L40:
  1439. mp1 = m + 1;
  1440. i__1 = *n;
  1441. for (i__ = mp1; i__ <= i__1; i__ += 3) {
  1442. dtemp = dx[i__];
  1443. dx[i__] = dy[i__];
  1444. dy[i__] = dtemp;
  1445. dtemp = dx[i__ + 1];
  1446. dx[i__ + 1] = dy[i__ + 1];
  1447. dy[i__ + 1] = dtemp;
  1448. dtemp = dx[i__ + 2];
  1449. dx[i__ + 2] = dy[i__ + 2];
  1450. dy[i__ + 2] = dtemp;
  1451. /* L50: */
  1452. }
  1453. return 0;
  1454. } /* NUMblas_dswap */
  1455. int NUMblas_dsymv (const char *uplo, integer *n, double *alpha, double *a, integer *lda, double *x, integer *incx, double *beta,
  1456. double *y, integer *incy) {
  1457. /* System generated locals */
  1458. integer a_dim1, a_offset, i__1, i__2;
  1459. /* Local variables */
  1460. static integer info;
  1461. static double temp1, temp2;
  1462. static integer i__, j;
  1463. static integer ix, iy, jx, jy, kx, ky;
  1464. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  1465. a_dim1 = *lda;
  1466. a_offset = 1 + a_dim1 * 1;
  1467. a -= a_offset;
  1468. --x;
  1469. --y;
  1470. /* Function Body */
  1471. info = 0;
  1472. if (!lsame_ (uplo, "U") && !lsame_ (uplo, "L")) {
  1473. info = 1;
  1474. } else if (*n < 0) {
  1475. info = 2;
  1476. } else if (*lda < MAX (1, *n)) {
  1477. info = 5;
  1478. } else if (*incx == 0) {
  1479. info = 7;
  1480. } else if (*incy == 0) {
  1481. info = 10;
  1482. }
  1483. if (info != 0) {
  1484. xerbla_ ("DSYMV ", &info);
  1485. return 0;
  1486. }
  1487. /* Quick return if possible. */
  1488. if (*n == 0 || (*alpha == 0. && *beta == 1.)) {
  1489. return 0;
  1490. }
  1491. /* Set up the start points in X and Y. */
  1492. if (*incx > 0) {
  1493. kx = 1;
  1494. } else {
  1495. kx = 1 - (*n - 1) * *incx;
  1496. }
  1497. if (*incy > 0) {
  1498. ky = 1;
  1499. } else {
  1500. ky = 1 - (*n - 1) * *incy;
  1501. }
  1502. /* Start the operations. In this version the elements of A are accessed
  1503. sequentially with one pass through the triangular part of A. First
  1504. form y := beta*y. */
  1505. if (*beta != 1.) {
  1506. if (*incy == 1) {
  1507. if (*beta == 0.) {
  1508. i__1 = *n;
  1509. for (i__ = 1; i__ <= i__1; ++i__) {
  1510. y[i__] = 0.;
  1511. /* L10: */
  1512. }
  1513. } else {
  1514. i__1 = *n;
  1515. for (i__ = 1; i__ <= i__1; ++i__) {
  1516. y[i__] = *beta * y[i__];
  1517. /* L20: */
  1518. }
  1519. }
  1520. } else {
  1521. iy = ky;
  1522. if (*beta == 0.) {
  1523. i__1 = *n;
  1524. for (i__ = 1; i__ <= i__1; ++i__) {
  1525. y[iy] = 0.;
  1526. iy += *incy;
  1527. /* L30: */
  1528. }
  1529. } else {
  1530. i__1 = *n;
  1531. for (i__ = 1; i__ <= i__1; ++i__) {
  1532. y[iy] = *beta * y[iy];
  1533. iy += *incy;
  1534. /* L40: */
  1535. }
  1536. }
  1537. }
  1538. }
  1539. if (*alpha == 0.) {
  1540. return 0;
  1541. }
  1542. if (lsame_ (uplo, "U")) {
  1543. /* Form y when A is stored in upper triangle. */
  1544. if (*incx == 1 && *incy == 1) {
  1545. i__1 = *n;
  1546. for (j = 1; j <= i__1; ++j) {
  1547. temp1 = *alpha * x[j];
  1548. temp2 = 0.;
  1549. i__2 = j - 1;
  1550. for (i__ = 1; i__ <= i__2; ++i__) {
  1551. y[i__] += temp1 * a_ref (i__, j);
  1552. temp2 += a_ref (i__, j) * x[i__];
  1553. /* L50: */
  1554. }
  1555. y[j] = y[j] + temp1 * a_ref (j, j) + *alpha * temp2;
  1556. /* L60: */
  1557. }
  1558. } else {
  1559. jx = kx;
  1560. jy = ky;
  1561. i__1 = *n;
  1562. for (j = 1; j <= i__1; ++j) {
  1563. temp1 = *alpha * x[jx];
  1564. temp2 = 0.;
  1565. ix = kx;
  1566. iy = ky;
  1567. i__2 = j - 1;
  1568. for (i__ = 1; i__ <= i__2; ++i__) {
  1569. y[iy] += temp1 * a_ref (i__, j);
  1570. temp2 += a_ref (i__, j) * x[ix];
  1571. ix += *incx;
  1572. iy += *incy;
  1573. /* L70: */
  1574. }
  1575. y[jy] = y[jy] + temp1 * a_ref (j, j) + *alpha * temp2;
  1576. jx += *incx;
  1577. jy += *incy;
  1578. /* L80: */
  1579. }
  1580. }
  1581. } else {
  1582. /* Form y when A is stored in lower triangle. */
  1583. if (*incx == 1 && *incy == 1) {
  1584. i__1 = *n;
  1585. for (j = 1; j <= i__1; ++j) {
  1586. temp1 = *alpha * x[j];
  1587. temp2 = 0.;
  1588. y[j] += temp1 * a_ref (j, j);
  1589. i__2 = *n;
  1590. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1591. y[i__] += temp1 * a_ref (i__, j);
  1592. temp2 += a_ref (i__, j) * x[i__];
  1593. /* L90: */
  1594. }
  1595. y[j] += *alpha * temp2;
  1596. /* L100: */
  1597. }
  1598. } else {
  1599. jx = kx;
  1600. jy = ky;
  1601. i__1 = *n;
  1602. for (j = 1; j <= i__1; ++j) {
  1603. temp1 = *alpha * x[jx];
  1604. temp2 = 0.;
  1605. y[jy] += temp1 * a_ref (j, j);
  1606. ix = jx;
  1607. iy = jy;
  1608. i__2 = *n;
  1609. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1610. ix += *incx;
  1611. iy += *incy;
  1612. y[iy] += temp1 * a_ref (i__, j);
  1613. temp2 += a_ref (i__, j) * x[ix];
  1614. /* L110: */
  1615. }
  1616. y[jy] += *alpha * temp2;
  1617. jx += *incx;
  1618. jy += *incy;
  1619. /* L120: */
  1620. }
  1621. }
  1622. }
  1623. return 0;
  1624. } /* NUMblas_dsymv */
  1625. #undef a_ref
  1626. int NUMblas_dsyr2 (const char *uplo, integer *n, double *alpha, double *x, integer *incx, double *y, integer *incy, double *a,
  1627. integer *lda) {
  1628. /* System generated locals */
  1629. integer a_dim1, a_offset, i__1, i__2;
  1630. /* Local variables */
  1631. static integer info;
  1632. static double temp1, temp2;
  1633. static integer i__, j;
  1634. static integer ix, iy, jx, jy, kx, ky;
  1635. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  1636. --x;
  1637. --y;
  1638. a_dim1 = *lda;
  1639. a_offset = 1 + a_dim1 * 1;
  1640. a -= a_offset;
  1641. /* Function Body */
  1642. info = 0;
  1643. if (!lsame_ (uplo, "U") && !lsame_ (uplo, "L")) {
  1644. info = 1;
  1645. } else if (*n < 0) {
  1646. info = 2;
  1647. } else if (*incx == 0) {
  1648. info = 5;
  1649. } else if (*incy == 0) {
  1650. info = 7;
  1651. } else if (*lda < MAX (1, *n)) {
  1652. info = 9;
  1653. }
  1654. if (info != 0) {
  1655. xerbla_ ("DSYR2 ", &info);
  1656. return 0;
  1657. }
  1658. /* Quick return if possible. */
  1659. if (*n == 0 || *alpha == 0.) {
  1660. return 0;
  1661. }
  1662. /* Set up the start points in X and Y if the increments are not both
  1663. unity. */
  1664. if (*incx != 1 || *incy != 1) {
  1665. if (*incx > 0) {
  1666. kx = 1;
  1667. } else {
  1668. kx = 1 - (*n - 1) * *incx;
  1669. }
  1670. if (*incy > 0) {
  1671. ky = 1;
  1672. } else {
  1673. ky = 1 - (*n - 1) * *incy;
  1674. }
  1675. jx = kx;
  1676. jy = ky;
  1677. }
  1678. /* Start the operations. In this version the elements of A are accessed
  1679. sequentially with one pass through the triangular part of A. */
  1680. if (lsame_ (uplo, "U")) {
  1681. /* Form A when A is stored in the upper triangle. */
  1682. if (*incx == 1 && *incy == 1) {
  1683. i__1 = *n;
  1684. for (j = 1; j <= i__1; ++j) {
  1685. if (x[j] != 0. || y[j] != 0.) {
  1686. temp1 = *alpha * y[j];
  1687. temp2 = *alpha * x[j];
  1688. i__2 = j;
  1689. for (i__ = 1; i__ <= i__2; ++i__) {
  1690. a_ref (i__, j) = a_ref (i__, j) + x[i__] * temp1 + y[i__] * temp2;
  1691. /* L10: */
  1692. }
  1693. }
  1694. /* L20: */
  1695. }
  1696. } else {
  1697. i__1 = *n;
  1698. for (j = 1; j <= i__1; ++j) {
  1699. if (x[jx] != 0. || y[jy] != 0.) {
  1700. temp1 = *alpha * y[jy];
  1701. temp2 = *alpha * x[jx];
  1702. ix = kx;
  1703. iy = ky;
  1704. i__2 = j;
  1705. for (i__ = 1; i__ <= i__2; ++i__) {
  1706. a_ref (i__, j) = a_ref (i__, j) + x[ix] * temp1 + y[iy] * temp2;
  1707. ix += *incx;
  1708. iy += *incy;
  1709. /* L30: */
  1710. }
  1711. }
  1712. jx += *incx;
  1713. jy += *incy;
  1714. /* L40: */
  1715. }
  1716. }
  1717. } else {
  1718. /* Form A when A is stored in the lower triangle. */
  1719. if (*incx == 1 && *incy == 1) {
  1720. i__1 = *n;
  1721. for (j = 1; j <= i__1; ++j) {
  1722. if (x[j] != 0. || y[j] != 0.) {
  1723. temp1 = *alpha * y[j];
  1724. temp2 = *alpha * x[j];
  1725. i__2 = *n;
  1726. for (i__ = j; i__ <= i__2; ++i__) {
  1727. a_ref (i__, j) = a_ref (i__, j) + x[i__] * temp1 + y[i__] * temp2;
  1728. /* L50: */
  1729. }
  1730. }
  1731. /* L60: */
  1732. }
  1733. } else {
  1734. i__1 = *n;
  1735. for (j = 1; j <= i__1; ++j) {
  1736. if (x[jx] != 0. || y[jy] != 0.) {
  1737. temp1 = *alpha * y[jy];
  1738. temp2 = *alpha * x[jx];
  1739. ix = jx;
  1740. iy = jy;
  1741. i__2 = *n;
  1742. for (i__ = j; i__ <= i__2; ++i__) {
  1743. a_ref (i__, j) = a_ref (i__, j) + x[ix] * temp1 + y[iy] * temp2;
  1744. ix += *incx;
  1745. iy += *incy;
  1746. /* L70: */
  1747. }
  1748. }
  1749. jx += *incx;
  1750. jy += *incy;
  1751. /* L80: */
  1752. }
  1753. }
  1754. }
  1755. return 0;
  1756. } /* NUMblas_dsyr2 */
  1757. #undef a_ref
  1758. int NUMblas_dsyr2k (const char *uplo, const char *trans, integer *n, integer *k, double *alpha, double *a, integer *lda, double *b,
  1759. integer *ldb, double *beta, double *c__, integer *ldc) {
  1760. /* System generated locals */
  1761. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2, i__3;
  1762. /* Local variables */
  1763. static integer info;
  1764. static double temp1, temp2;
  1765. static integer i__, j, l;
  1766. static integer nrowa;
  1767. static integer upper;
  1768. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  1769. #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
  1770. #define c___ref(a_1,a_2) c__[(a_2)*c_dim1 + a_1]
  1771. a_dim1 = *lda;
  1772. a_offset = 1 + a_dim1 * 1;
  1773. a -= a_offset;
  1774. b_dim1 = *ldb;
  1775. b_offset = 1 + b_dim1 * 1;
  1776. b -= b_offset;
  1777. c_dim1 = *ldc;
  1778. c_offset = 1 + c_dim1 * 1;
  1779. c__ -= c_offset;
  1780. /* Function Body */
  1781. if (lsame_ (trans, "N")) {
  1782. nrowa = *n;
  1783. } else {
  1784. nrowa = *k;
  1785. }
  1786. upper = lsame_ (uplo, "U");
  1787. info = 0;
  1788. if (!upper && !lsame_ (uplo, "L")) {
  1789. info = 1;
  1790. } else if (!lsame_ (trans, "N") && !lsame_ (trans, "T") && !lsame_ (trans, "C")) {
  1791. info = 2;
  1792. } else if (*n < 0) {
  1793. info = 3;
  1794. } else if (*k < 0) {
  1795. info = 4;
  1796. } else if (*lda < MAX (1, nrowa)) {
  1797. info = 7;
  1798. } else if (*ldb < MAX (1, nrowa)) {
  1799. info = 9;
  1800. } else if (*ldc < MAX (1, *n)) {
  1801. info = 12;
  1802. }
  1803. if (info != 0) {
  1804. xerbla_ ("DSYR2K", &info);
  1805. return 0;
  1806. }
  1807. /* Quick return if possible. */
  1808. if (*n == 0 || ((*alpha == 0. || *k == 0) && *beta == 1.)) {
  1809. return 0;
  1810. }
  1811. /* And when alpha.eq.zero. */
  1812. if (*alpha == 0.) {
  1813. if (upper) {
  1814. if (*beta == 0.) {
  1815. i__1 = *n;
  1816. for (j = 1; j <= i__1; ++j) {
  1817. i__2 = j;
  1818. for (i__ = 1; i__ <= i__2; ++i__) {
  1819. c___ref (i__, j) = 0.;
  1820. /* L10: */
  1821. }
  1822. /* L20: */
  1823. }
  1824. } else {
  1825. i__1 = *n;
  1826. for (j = 1; j <= i__1; ++j) {
  1827. i__2 = j;
  1828. for (i__ = 1; i__ <= i__2; ++i__) {
  1829. c___ref (i__, j) = *beta * c___ref (i__, j);
  1830. /* L30: */
  1831. }
  1832. /* L40: */
  1833. }
  1834. }
  1835. } else {
  1836. if (*beta == 0.) {
  1837. i__1 = *n;
  1838. for (j = 1; j <= i__1; ++j) {
  1839. i__2 = *n;
  1840. for (i__ = j; i__ <= i__2; ++i__) {
  1841. c___ref (i__, j) = 0.;
  1842. /* L50: */
  1843. }
  1844. /* L60: */
  1845. }
  1846. } else {
  1847. i__1 = *n;
  1848. for (j = 1; j <= i__1; ++j) {
  1849. i__2 = *n;
  1850. for (i__ = j; i__ <= i__2; ++i__) {
  1851. c___ref (i__, j) = *beta * c___ref (i__, j);
  1852. /* L70: */
  1853. }
  1854. /* L80: */
  1855. }
  1856. }
  1857. }
  1858. return 0;
  1859. }
  1860. /* Start the operations. */
  1861. if (lsame_ (trans, "N")) {
  1862. /* Form C := alpha*A*B' + alpha*B*A' + C. */
  1863. if (upper) {
  1864. i__1 = *n;
  1865. for (j = 1; j <= i__1; ++j) {
  1866. if (*beta == 0.) {
  1867. i__2 = j;
  1868. for (i__ = 1; i__ <= i__2; ++i__) {
  1869. c___ref (i__, j) = 0.;
  1870. /* L90: */
  1871. }
  1872. } else if (*beta != 1.) {
  1873. i__2 = j;
  1874. for (i__ = 1; i__ <= i__2; ++i__) {
  1875. c___ref (i__, j) = *beta * c___ref (i__, j);
  1876. /* L100: */
  1877. }
  1878. }
  1879. i__2 = *k;
  1880. for (l = 1; l <= i__2; ++l) {
  1881. if (a_ref (j, l) != 0. || b_ref (j, l) != 0.) {
  1882. temp1 = *alpha * b_ref (j, l);
  1883. temp2 = *alpha * a_ref (j, l);
  1884. i__3 = j;
  1885. for (i__ = 1; i__ <= i__3; ++i__) {
  1886. c___ref (i__, j) =
  1887. c___ref (i__, j) + a_ref (i__, l) * temp1 + b_ref (i__, l) * temp2;
  1888. /* L110: */
  1889. }
  1890. }
  1891. /* L120: */
  1892. }
  1893. /* L130: */
  1894. }
  1895. } else {
  1896. i__1 = *n;
  1897. for (j = 1; j <= i__1; ++j) {
  1898. if (*beta == 0.) {
  1899. i__2 = *n;
  1900. for (i__ = j; i__ <= i__2; ++i__) {
  1901. c___ref (i__, j) = 0.;
  1902. /* L140: */
  1903. }
  1904. } else if (*beta != 1.) {
  1905. i__2 = *n;
  1906. for (i__ = j; i__ <= i__2; ++i__) {
  1907. c___ref (i__, j) = *beta * c___ref (i__, j);
  1908. /* L150: */
  1909. }
  1910. }
  1911. i__2 = *k;
  1912. for (l = 1; l <= i__2; ++l) {
  1913. if (a_ref (j, l) != 0. || b_ref (j, l) != 0.) {
  1914. temp1 = *alpha * b_ref (j, l);
  1915. temp2 = *alpha * a_ref (j, l);
  1916. i__3 = *n;
  1917. for (i__ = j; i__ <= i__3; ++i__) {
  1918. c___ref (i__, j) =
  1919. c___ref (i__, j) + a_ref (i__, l) * temp1 + b_ref (i__, l) * temp2;
  1920. /* L160: */
  1921. }
  1922. }
  1923. /* L170: */
  1924. }
  1925. /* L180: */
  1926. }
  1927. }
  1928. } else {
  1929. /* Form C := alpha*A'*B + alpha*B'*A + C. */
  1930. if (upper) {
  1931. i__1 = *n;
  1932. for (j = 1; j <= i__1; ++j) {
  1933. i__2 = j;
  1934. for (i__ = 1; i__ <= i__2; ++i__) {
  1935. temp1 = 0.;
  1936. temp2 = 0.;
  1937. i__3 = *k;
  1938. for (l = 1; l <= i__3; ++l) {
  1939. temp1 += a_ref (l, i__) * b_ref (l, j);
  1940. temp2 += b_ref (l, i__) * a_ref (l, j);
  1941. /* L190: */
  1942. }
  1943. if (*beta == 0.) {
  1944. c___ref (i__, j) = *alpha * temp1 + *alpha * temp2;
  1945. } else {
  1946. c___ref (i__, j) = *beta * c___ref (i__, j) + *alpha * temp1 + *alpha * temp2;
  1947. }
  1948. /* L200: */
  1949. }
  1950. /* L210: */
  1951. }
  1952. } else {
  1953. i__1 = *n;
  1954. for (j = 1; j <= i__1; ++j) {
  1955. i__2 = *n;
  1956. for (i__ = j; i__ <= i__2; ++i__) {
  1957. temp1 = 0.;
  1958. temp2 = 0.;
  1959. i__3 = *k;
  1960. for (l = 1; l <= i__3; ++l) {
  1961. temp1 += a_ref (l, i__) * b_ref (l, j);
  1962. temp2 += b_ref (l, i__) * a_ref (l, j);
  1963. /* L220: */
  1964. }
  1965. if (*beta == 0.) {
  1966. c___ref (i__, j) = *alpha * temp1 + *alpha * temp2;
  1967. } else {
  1968. c___ref (i__, j) = *beta * c___ref (i__, j) + *alpha * temp1 + *alpha * temp2;
  1969. }
  1970. /* L230: */
  1971. }
  1972. /* L240: */
  1973. }
  1974. }
  1975. }
  1976. return 0;
  1977. } /* NUMblas_dsyr2k */
  1978. #undef c___ref
  1979. #undef b_ref
  1980. #undef a_ref
  1981. int NUMblas_dtrmm (const char *side, const char *uplo, const char *transa, const char *diag, integer *m, integer *n, double *alpha, double *a,
  1982. integer *lda, double *b, integer *ldb) {
  1983. /* System generated locals */
  1984. integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3;
  1985. /* Local variables */
  1986. static integer info;
  1987. static double temp;
  1988. static integer i__, j, k;
  1989. static integer lside;
  1990. static integer nrowa;
  1991. static integer upper;
  1992. static integer nounit;
  1993. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  1994. #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
  1995. /* Level 3 Blas routine. -- Written on 8-February-1989. Jack Dongarra,
  1996. Argonne National Laboratory. Iain Duff, AERE Harwell. Jeremy Du Croz,
  1997. Numerical Algorithms Group Ltd. Sven Hammarling, Numerical Algorithms
  1998. Group Ltd. Test the input parameters. Parameter adjustments */
  1999. a_dim1 = *lda;
  2000. a_offset = 1 + a_dim1 * 1;
  2001. a -= a_offset;
  2002. b_dim1 = *ldb;
  2003. b_offset = 1 + b_dim1 * 1;
  2004. b -= b_offset;
  2005. /* Function Body */
  2006. lside = lsame_ (side, "L");
  2007. if (lside) {
  2008. nrowa = *m;
  2009. } else {
  2010. nrowa = *n;
  2011. }
  2012. nounit = lsame_ (diag, "N");
  2013. upper = lsame_ (uplo, "U");
  2014. info = 0;
  2015. if (!lside && !lsame_ (side, "R")) {
  2016. info = 1;
  2017. } else if (!upper && !lsame_ (uplo, "L")) {
  2018. info = 2;
  2019. } else if (!lsame_ (transa, "N") && !lsame_ (transa, "T") && !lsame_ (transa, "C")) {
  2020. info = 3;
  2021. } else if (!lsame_ (diag, "U") && !lsame_ (diag, "N")) {
  2022. info = 4;
  2023. } else if (*m < 0) {
  2024. info = 5;
  2025. } else if (*n < 0) {
  2026. info = 6;
  2027. } else if (*lda < MAX (1, nrowa)) {
  2028. info = 9;
  2029. } else if (*ldb < MAX (1, *m)) {
  2030. info = 11;
  2031. }
  2032. if (info != 0) {
  2033. xerbla_ ("DTRMM ", &info);
  2034. return 0;
  2035. }
  2036. /* Quick return if possible. */
  2037. if (*n == 0) {
  2038. return 0;
  2039. }
  2040. /* And when alpha.eq.zero. */
  2041. if (*alpha == 0.) {
  2042. i__1 = *n;
  2043. for (j = 1; j <= i__1; ++j) {
  2044. i__2 = *m;
  2045. for (i__ = 1; i__ <= i__2; ++i__) {
  2046. b_ref (i__, j) = 0.;
  2047. /* L10: */
  2048. }
  2049. /* L20: */
  2050. }
  2051. return 0;
  2052. }
  2053. /* Start the operations. */
  2054. if (lside) {
  2055. if (lsame_ (transa, "N")) {
  2056. /* Form B := alpha*A*B. */
  2057. if (upper) {
  2058. i__1 = *n;
  2059. for (j = 1; j <= i__1; ++j) {
  2060. i__2 = *m;
  2061. for (k = 1; k <= i__2; ++k) {
  2062. if (b_ref (k, j) != 0.) {
  2063. temp = *alpha * b_ref (k, j);
  2064. i__3 = k - 1;
  2065. for (i__ = 1; i__ <= i__3; ++i__) {
  2066. b_ref (i__, j) = b_ref (i__, j) + temp * a_ref (i__, k);
  2067. /* L30: */
  2068. }
  2069. if (nounit) {
  2070. temp *= a_ref (k, k);
  2071. }
  2072. b_ref (k, j) = temp;
  2073. }
  2074. /* L40: */
  2075. }
  2076. /* L50: */
  2077. }
  2078. } else {
  2079. i__1 = *n;
  2080. for (j = 1; j <= i__1; ++j) {
  2081. for (k = *m; k >= 1; --k) {
  2082. if (b_ref (k, j) != 0.) {
  2083. temp = *alpha * b_ref (k, j);
  2084. b_ref (k, j) = temp;
  2085. if (nounit) {
  2086. b_ref (k, j) = b_ref (k, j) * a_ref (k, k);
  2087. }
  2088. i__2 = *m;
  2089. for (i__ = k + 1; i__ <= i__2; ++i__) {
  2090. b_ref (i__, j) = b_ref (i__, j) + temp * a_ref (i__, k);
  2091. /* L60: */
  2092. }
  2093. }
  2094. /* L70: */
  2095. }
  2096. /* L80: */
  2097. }
  2098. }
  2099. } else {
  2100. /* Form B := alpha*A'*B. */
  2101. if (upper) {
  2102. i__1 = *n;
  2103. for (j = 1; j <= i__1; ++j) {
  2104. for (i__ = *m; i__ >= 1; --i__) {
  2105. temp = b_ref (i__, j);
  2106. if (nounit) {
  2107. temp *= a_ref (i__, i__);
  2108. }
  2109. i__2 = i__ - 1;
  2110. for (k = 1; k <= i__2; ++k) {
  2111. temp += a_ref (k, i__) * b_ref (k, j);
  2112. /* L90: */
  2113. }
  2114. b_ref (i__, j) = *alpha * temp;
  2115. /* L100: */
  2116. }
  2117. /* L110: */
  2118. }
  2119. } else {
  2120. i__1 = *n;
  2121. for (j = 1; j <= i__1; ++j) {
  2122. i__2 = *m;
  2123. for (i__ = 1; i__ <= i__2; ++i__) {
  2124. temp = b_ref (i__, j);
  2125. if (nounit) {
  2126. temp *= a_ref (i__, i__);
  2127. }
  2128. i__3 = *m;
  2129. for (k = i__ + 1; k <= i__3; ++k) {
  2130. temp += a_ref (k, i__) * b_ref (k, j);
  2131. /* L120: */
  2132. }
  2133. b_ref (i__, j) = *alpha * temp;
  2134. /* L130: */
  2135. }
  2136. /* L140: */
  2137. }
  2138. }
  2139. }
  2140. } else {
  2141. if (lsame_ (transa, "N")) {
  2142. /* Form B := alpha*B*A. */
  2143. if (upper) {
  2144. for (j = *n; j >= 1; --j) {
  2145. temp = *alpha;
  2146. if (nounit) {
  2147. temp *= a_ref (j, j);
  2148. }
  2149. i__1 = *m;
  2150. for (i__ = 1; i__ <= i__1; ++i__) {
  2151. b_ref (i__, j) = temp * b_ref (i__, j);
  2152. /* L150: */
  2153. }
  2154. i__1 = j - 1;
  2155. for (k = 1; k <= i__1; ++k) {
  2156. if (a_ref (k, j) != 0.) {
  2157. temp = *alpha * a_ref (k, j);
  2158. i__2 = *m;
  2159. for (i__ = 1; i__ <= i__2; ++i__) {
  2160. b_ref (i__, j) = b_ref (i__, j) + temp * b_ref (i__, k);
  2161. /* L160: */
  2162. }
  2163. }
  2164. /* L170: */
  2165. }
  2166. /* L180: */
  2167. }
  2168. } else {
  2169. i__1 = *n;
  2170. for (j = 1; j <= i__1; ++j) {
  2171. temp = *alpha;
  2172. if (nounit) {
  2173. temp *= a_ref (j, j);
  2174. }
  2175. i__2 = *m;
  2176. for (i__ = 1; i__ <= i__2; ++i__) {
  2177. b_ref (i__, j) = temp * b_ref (i__, j);
  2178. /* L190: */
  2179. }
  2180. i__2 = *n;
  2181. for (k = j + 1; k <= i__2; ++k) {
  2182. if (a_ref (k, j) != 0.) {
  2183. temp = *alpha * a_ref (k, j);
  2184. i__3 = *m;
  2185. for (i__ = 1; i__ <= i__3; ++i__) {
  2186. b_ref (i__, j) = b_ref (i__, j) + temp * b_ref (i__, k);
  2187. /* L200: */
  2188. }
  2189. }
  2190. /* L210: */
  2191. }
  2192. /* L220: */
  2193. }
  2194. }
  2195. } else {
  2196. /* Form B := alpha*B*A'. */
  2197. if (upper) {
  2198. i__1 = *n;
  2199. for (k = 1; k <= i__1; ++k) {
  2200. i__2 = k - 1;
  2201. for (j = 1; j <= i__2; ++j) {
  2202. if (a_ref (j, k) != 0.) {
  2203. temp = *alpha * a_ref (j, k);
  2204. i__3 = *m;
  2205. for (i__ = 1; i__ <= i__3; ++i__) {
  2206. b_ref (i__, j) = b_ref (i__, j) + temp * b_ref (i__, k);
  2207. /* L230: */
  2208. }
  2209. }
  2210. /* L240: */
  2211. }
  2212. temp = *alpha;
  2213. if (nounit) {
  2214. temp *= a_ref (k, k);
  2215. }
  2216. if (temp != 1.) {
  2217. i__2 = *m;
  2218. for (i__ = 1; i__ <= i__2; ++i__) {
  2219. b_ref (i__, k) = temp * b_ref (i__, k);
  2220. /* L250: */
  2221. }
  2222. }
  2223. /* L260: */
  2224. }
  2225. } else {
  2226. for (k = *n; k >= 1; --k) {
  2227. i__1 = *n;
  2228. for (j = k + 1; j <= i__1; ++j) {
  2229. if (a_ref (j, k) != 0.) {
  2230. temp = *alpha * a_ref (j, k);
  2231. i__2 = *m;
  2232. for (i__ = 1; i__ <= i__2; ++i__) {
  2233. b_ref (i__, j) = b_ref (i__, j) + temp * b_ref (i__, k);
  2234. /* L270: */
  2235. }
  2236. }
  2237. /* L280: */
  2238. }
  2239. temp = *alpha;
  2240. if (nounit) {
  2241. temp *= a_ref (k, k);
  2242. }
  2243. if (temp != 1.) {
  2244. i__1 = *m;
  2245. for (i__ = 1; i__ <= i__1; ++i__) {
  2246. b_ref (i__, k) = temp * b_ref (i__, k);
  2247. /* L290: */
  2248. }
  2249. }
  2250. /* L300: */
  2251. }
  2252. }
  2253. }
  2254. }
  2255. return 0;
  2256. } /* NUMblas_dtrmm */
  2257. #undef b_ref
  2258. #undef a_ref
  2259. int NUMblas_dtrmv (const char *uplo, const char *trans, const char *diag, integer *n, double *a, integer *lda, double *x, integer *incx) {
  2260. /* System generated locals */
  2261. integer a_dim1, a_offset, i__1, i__2;
  2262. /* Local variables */
  2263. static integer info;
  2264. static double temp;
  2265. static integer i__, j;
  2266. static integer ix, jx, kx;
  2267. static integer nounit;
  2268. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  2269. /* -- Written on 22-October-1986. Jack Dongarra, Argonne National Lab.
  2270. Jeremy Du Croz, Nag Central Office. Sven Hammarling, Nag Central
  2271. Office. Richard Hanson, Sandia National Labs. Test the input
  2272. parameters. Parameter adjustments */
  2273. a_dim1 = *lda;
  2274. a_offset = 1 + a_dim1 * 1;
  2275. a -= a_offset;
  2276. --x;
  2277. /* Function Body */
  2278. info = 0;
  2279. if (!lsame_ (uplo, "U") && !lsame_ (uplo, "L")) {
  2280. info = 1;
  2281. } else if (!lsame_ (trans, "N") && !lsame_ (trans, "T") && !lsame_ (trans, "C")) {
  2282. info = 2;
  2283. } else if (!lsame_ (diag, "U") && !lsame_ (diag, "N")) {
  2284. info = 3;
  2285. } else if (*n < 0) {
  2286. info = 4;
  2287. } else if (*lda < MAX (1, *n)) {
  2288. info = 6;
  2289. } else if (*incx == 0) {
  2290. info = 8;
  2291. }
  2292. if (info != 0) {
  2293. xerbla_ ("DTRMV ", &info);
  2294. return 0;
  2295. }
  2296. /* Quick return if possible. */
  2297. if (*n == 0) {
  2298. return 0;
  2299. }
  2300. nounit = lsame_ (diag, "N");
  2301. /* Set up the start point in X if the increment is not unity. This will
  2302. be ( N - 1 )*INCX too small for descending loops. */
  2303. if (*incx <= 0) {
  2304. kx = 1 - (*n - 1) * *incx;
  2305. } else if (*incx != 1) {
  2306. kx = 1;
  2307. }
  2308. /* Start the operations. In this version the elements of A are accessed
  2309. sequentially with one pass through A. */
  2310. if (lsame_ (trans, "N")) {
  2311. /* Form x := A*x. */
  2312. if (lsame_ (uplo, "U")) {
  2313. if (*incx == 1) {
  2314. i__1 = *n;
  2315. for (j = 1; j <= i__1; ++j) {
  2316. if (x[j] != 0.) {
  2317. temp = x[j];
  2318. i__2 = j - 1;
  2319. for (i__ = 1; i__ <= i__2; ++i__) {
  2320. x[i__] += temp * a_ref (i__, j);
  2321. /* L10: */
  2322. }
  2323. if (nounit) {
  2324. x[j] *= a_ref (j, j);
  2325. }
  2326. }
  2327. /* L20: */
  2328. }
  2329. } else {
  2330. jx = kx;
  2331. i__1 = *n;
  2332. for (j = 1; j <= i__1; ++j) {
  2333. if (x[jx] != 0.) {
  2334. temp = x[jx];
  2335. ix = kx;
  2336. i__2 = j - 1;
  2337. for (i__ = 1; i__ <= i__2; ++i__) {
  2338. x[ix] += temp * a_ref (i__, j);
  2339. ix += *incx;
  2340. /* L30: */
  2341. }
  2342. if (nounit) {
  2343. x[jx] *= a_ref (j, j);
  2344. }
  2345. }
  2346. jx += *incx;
  2347. /* L40: */
  2348. }
  2349. }
  2350. } else {
  2351. if (*incx == 1) {
  2352. for (j = *n; j >= 1; --j) {
  2353. if (x[j] != 0.) {
  2354. temp = x[j];
  2355. i__1 = j + 1;
  2356. for (i__ = *n; i__ >= i__1; --i__) {
  2357. x[i__] += temp * a_ref (i__, j);
  2358. /* L50: */
  2359. }
  2360. if (nounit) {
  2361. x[j] *= a_ref (j, j);
  2362. }
  2363. }
  2364. /* L60: */
  2365. }
  2366. } else {
  2367. kx += (*n - 1) * *incx;
  2368. jx = kx;
  2369. for (j = *n; j >= 1; --j) {
  2370. if (x[jx] != 0.) {
  2371. temp = x[jx];
  2372. ix = kx;
  2373. i__1 = j + 1;
  2374. for (i__ = *n; i__ >= i__1; --i__) {
  2375. x[ix] += temp * a_ref (i__, j);
  2376. ix -= *incx;
  2377. /* L70: */
  2378. }
  2379. if (nounit) {
  2380. x[jx] *= a_ref (j, j);
  2381. }
  2382. }
  2383. jx -= *incx;
  2384. /* L80: */
  2385. }
  2386. }
  2387. }
  2388. } else {
  2389. /* Form x := A'*x. */
  2390. if (lsame_ (uplo, "U")) {
  2391. if (*incx == 1) {
  2392. for (j = *n; j >= 1; --j) {
  2393. temp = x[j];
  2394. if (nounit) {
  2395. temp *= a_ref (j, j);
  2396. }
  2397. for (i__ = j - 1; i__ >= 1; --i__) {
  2398. temp += a_ref (i__, j) * x[i__];
  2399. /* L90: */
  2400. }
  2401. x[j] = temp;
  2402. /* L100: */
  2403. }
  2404. } else {
  2405. jx = kx + (*n - 1) * *incx;
  2406. for (j = *n; j >= 1; --j) {
  2407. temp = x[jx];
  2408. ix = jx;
  2409. if (nounit) {
  2410. temp *= a_ref (j, j);
  2411. }
  2412. for (i__ = j - 1; i__ >= 1; --i__) {
  2413. ix -= *incx;
  2414. temp += a_ref (i__, j) * x[ix];
  2415. /* L110: */
  2416. }
  2417. x[jx] = temp;
  2418. jx -= *incx;
  2419. /* L120: */
  2420. }
  2421. }
  2422. } else {
  2423. if (*incx == 1) {
  2424. i__1 = *n;
  2425. for (j = 1; j <= i__1; ++j) {
  2426. temp = x[j];
  2427. if (nounit) {
  2428. temp *= a_ref (j, j);
  2429. }
  2430. i__2 = *n;
  2431. for (i__ = j + 1; i__ <= i__2; ++i__) {
  2432. temp += a_ref (i__, j) * x[i__];
  2433. /* L130: */
  2434. }
  2435. x[j] = temp;
  2436. /* L140: */
  2437. }
  2438. } else {
  2439. jx = kx;
  2440. i__1 = *n;
  2441. for (j = 1; j <= i__1; ++j) {
  2442. temp = x[jx];
  2443. ix = jx;
  2444. if (nounit) {
  2445. temp *= a_ref (j, j);
  2446. }
  2447. i__2 = *n;
  2448. for (i__ = j + 1; i__ <= i__2; ++i__) {
  2449. ix += *incx;
  2450. temp += a_ref (i__, j) * x[ix];
  2451. /* L150: */
  2452. }
  2453. x[jx] = temp;
  2454. jx += *incx;
  2455. /* L160: */
  2456. }
  2457. }
  2458. }
  2459. }
  2460. return 0;
  2461. } /* NUMblas_dtrmv */
  2462. #undef a_ref
  2463. int NUMblas_dtrsm (const char *side, const char *uplo, const char *transa, const char *diag, integer *m, integer *n,
  2464. double *alpha, double *a, integer *lda, double *b, integer *ldb) {
  2465. /* System generated locals */
  2466. integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3;
  2467. /* Local variables */
  2468. static integer info;
  2469. static double temp;
  2470. static integer i__, j, k;
  2471. static integer lside;
  2472. static integer nrowa;
  2473. static integer upper;
  2474. static integer nounit;
  2475. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  2476. #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
  2477. a_dim1 = *lda;
  2478. a_offset = 1 + a_dim1 * 1;
  2479. a -= a_offset;
  2480. b_dim1 = *ldb;
  2481. b_offset = 1 + b_dim1 * 1;
  2482. b -= b_offset;
  2483. /* Function Body */
  2484. lside = lsame_ (side, "L");
  2485. if (lside) {
  2486. nrowa = *m;
  2487. } else {
  2488. nrowa = *n;
  2489. }
  2490. nounit = lsame_ (diag, "N");
  2491. upper = lsame_ (uplo, "U");
  2492. info = 0;
  2493. if (!lside && !lsame_ (side, "R")) {
  2494. info = 1;
  2495. } else if (!upper && !lsame_ (uplo, "L")) {
  2496. info = 2;
  2497. } else if (!lsame_ (transa, "N") && !lsame_ (transa, "T") && !lsame_ (transa, "C")) {
  2498. info = 3;
  2499. } else if (!lsame_ (diag, "U") && !lsame_ (diag, "N")) {
  2500. info = 4;
  2501. } else if (*m < 0) {
  2502. info = 5;
  2503. } else if (*n < 0) {
  2504. info = 6;
  2505. } else if (*lda < MAX (1, nrowa)) {
  2506. info = 9;
  2507. } else if (*ldb < MAX (1, *m)) {
  2508. info = 11;
  2509. }
  2510. if (info != 0) {
  2511. xerbla_ ("DTRSM ", &info);
  2512. return 0;
  2513. }
  2514. /* Quick return if possible. */
  2515. if (*n == 0) {
  2516. return 0;
  2517. }
  2518. /* And when alpha.eq.zero. */
  2519. if (*alpha == 0.) {
  2520. i__1 = *n;
  2521. for (j = 1; j <= i__1; ++j) {
  2522. i__2 = *m;
  2523. for (i__ = 1; i__ <= i__2; ++i__) {
  2524. b_ref (i__, j) = 0.;
  2525. /* L10: */
  2526. }
  2527. /* L20: */
  2528. }
  2529. return 0;
  2530. }
  2531. /* Start the operations. */
  2532. if (lside) {
  2533. if (lsame_ (transa, "N")) {
  2534. /* Form B := alpha*inv( A )*B. */
  2535. if (upper) {
  2536. i__1 = *n;
  2537. for (j = 1; j <= i__1; ++j) {
  2538. if (*alpha != 1.) {
  2539. i__2 = *m;
  2540. for (i__ = 1; i__ <= i__2; ++i__) {
  2541. b_ref (i__, j) = *alpha * b_ref (i__, j);
  2542. /* L30: */
  2543. }
  2544. }
  2545. for (k = *m; k >= 1; --k) {
  2546. if (b_ref (k, j) != 0.) {
  2547. if (nounit) {
  2548. b_ref (k, j) = b_ref (k, j) / a_ref (k, k);
  2549. }
  2550. i__2 = k - 1;
  2551. for (i__ = 1; i__ <= i__2; ++i__) {
  2552. b_ref (i__, j) = b_ref (i__, j) - b_ref (k, j) * a_ref (i__, k);
  2553. /* L40: */
  2554. }
  2555. }
  2556. /* L50: */
  2557. }
  2558. /* L60: */
  2559. }
  2560. } else {
  2561. i__1 = *n;
  2562. for (j = 1; j <= i__1; ++j) {
  2563. if (*alpha != 1.) {
  2564. i__2 = *m;
  2565. for (i__ = 1; i__ <= i__2; ++i__) {
  2566. b_ref (i__, j) = *alpha * b_ref (i__, j);
  2567. /* L70: */
  2568. }
  2569. }
  2570. i__2 = *m;
  2571. for (k = 1; k <= i__2; ++k) {
  2572. if (b_ref (k, j) != 0.) {
  2573. if (nounit) {
  2574. b_ref (k, j) = b_ref (k, j) / a_ref (k, k);
  2575. }
  2576. i__3 = *m;
  2577. for (i__ = k + 1; i__ <= i__3; ++i__) {
  2578. b_ref (i__, j) = b_ref (i__, j) - b_ref (k, j) * a_ref (i__, k);
  2579. /* L80: */
  2580. }
  2581. }
  2582. /* L90: */
  2583. }
  2584. /* L100: */
  2585. }
  2586. }
  2587. } else {
  2588. /* Form B := alpha*inv( A' )*B. */
  2589. if (upper) {
  2590. i__1 = *n;
  2591. for (j = 1; j <= i__1; ++j) {
  2592. i__2 = *m;
  2593. for (i__ = 1; i__ <= i__2; ++i__) {
  2594. temp = *alpha * b_ref (i__, j);
  2595. i__3 = i__ - 1;
  2596. for (k = 1; k <= i__3; ++k) {
  2597. temp -= a_ref (k, i__) * b_ref (k, j);
  2598. /* L110: */
  2599. }
  2600. if (nounit) {
  2601. temp /= a_ref (i__, i__);
  2602. }
  2603. b_ref (i__, j) = temp;
  2604. /* L120: */
  2605. }
  2606. /* L130: */
  2607. }
  2608. } else {
  2609. i__1 = *n;
  2610. for (j = 1; j <= i__1; ++j) {
  2611. for (i__ = *m; i__ >= 1; --i__) {
  2612. temp = *alpha * b_ref (i__, j);
  2613. i__2 = *m;
  2614. for (k = i__ + 1; k <= i__2; ++k) {
  2615. temp -= a_ref (k, i__) * b_ref (k, j);
  2616. /* L140: */
  2617. }
  2618. if (nounit) {
  2619. temp /= a_ref (i__, i__);
  2620. }
  2621. b_ref (i__, j) = temp;
  2622. /* L150: */
  2623. }
  2624. /* L160: */
  2625. }
  2626. }
  2627. }
  2628. } else {
  2629. if (lsame_ (transa, "N")) {
  2630. /* Form B := alpha*B*inv( A ). */
  2631. if (upper) {
  2632. i__1 = *n;
  2633. for (j = 1; j <= i__1; ++j) {
  2634. if (*alpha != 1.) {
  2635. i__2 = *m;
  2636. for (i__ = 1; i__ <= i__2; ++i__) {
  2637. b_ref (i__, j) = *alpha * b_ref (i__, j);
  2638. /* L170: */
  2639. }
  2640. }
  2641. i__2 = j - 1;
  2642. for (k = 1; k <= i__2; ++k) {
  2643. if (a_ref (k, j) != 0.) {
  2644. i__3 = *m;
  2645. for (i__ = 1; i__ <= i__3; ++i__) {
  2646. b_ref (i__, j) = b_ref (i__, j) - a_ref (k, j) * b_ref (i__, k);
  2647. /* L180: */
  2648. }
  2649. }
  2650. /* L190: */
  2651. }
  2652. if (nounit) {
  2653. temp = 1. / a_ref (j, j);
  2654. i__2 = *m;
  2655. for (i__ = 1; i__ <= i__2; ++i__) {
  2656. b_ref (i__, j) = temp * b_ref (i__, j);
  2657. /* L200: */
  2658. }
  2659. }
  2660. /* L210: */
  2661. }
  2662. } else {
  2663. for (j = *n; j >= 1; --j) {
  2664. if (*alpha != 1.) {
  2665. i__1 = *m;
  2666. for (i__ = 1; i__ <= i__1; ++i__) {
  2667. b_ref (i__, j) = *alpha * b_ref (i__, j);
  2668. /* L220: */
  2669. }
  2670. }
  2671. i__1 = *n;
  2672. for (k = j + 1; k <= i__1; ++k) {
  2673. if (a_ref (k, j) != 0.) {
  2674. i__2 = *m;
  2675. for (i__ = 1; i__ <= i__2; ++i__) {
  2676. b_ref (i__, j) = b_ref (i__, j) - a_ref (k, j) * b_ref (i__, k);
  2677. /* L230: */
  2678. }
  2679. }
  2680. /* L240: */
  2681. }
  2682. if (nounit) {
  2683. temp = 1. / a_ref (j, j);
  2684. i__1 = *m;
  2685. for (i__ = 1; i__ <= i__1; ++i__) {
  2686. b_ref (i__, j) = temp * b_ref (i__, j);
  2687. /* L250: */
  2688. }
  2689. }
  2690. /* L260: */
  2691. }
  2692. }
  2693. } else {
  2694. /* Form B := alpha*B*inv( A' ). */
  2695. if (upper) {
  2696. for (k = *n; k >= 1; --k) {
  2697. if (nounit) {
  2698. temp = 1. / a_ref (k, k);
  2699. i__1 = *m;
  2700. for (i__ = 1; i__ <= i__1; ++i__) {
  2701. b_ref (i__, k) = temp * b_ref (i__, k);
  2702. /* L270: */
  2703. }
  2704. }
  2705. i__1 = k - 1;
  2706. for (j = 1; j <= i__1; ++j) {
  2707. if (a_ref (j, k) != 0.) {
  2708. temp = a_ref (j, k);
  2709. i__2 = *m;
  2710. for (i__ = 1; i__ <= i__2; ++i__) {
  2711. b_ref (i__, j) = b_ref (i__, j) - temp * b_ref (i__, k);
  2712. /* L280: */
  2713. }
  2714. }
  2715. /* L290: */
  2716. }
  2717. if (*alpha != 1.) {
  2718. i__1 = *m;
  2719. for (i__ = 1; i__ <= i__1; ++i__) {
  2720. b_ref (i__, k) = *alpha * b_ref (i__, k);
  2721. /* L300: */
  2722. }
  2723. }
  2724. /* L310: */
  2725. }
  2726. } else {
  2727. i__1 = *n;
  2728. for (k = 1; k <= i__1; ++k) {
  2729. if (nounit) {
  2730. temp = 1. / a_ref (k, k);
  2731. i__2 = *m;
  2732. for (i__ = 1; i__ <= i__2; ++i__) {
  2733. b_ref (i__, k) = temp * b_ref (i__, k);
  2734. /* L320: */
  2735. }
  2736. }
  2737. i__2 = *n;
  2738. for (j = k + 1; j <= i__2; ++j) {
  2739. if (a_ref (j, k) != 0.) {
  2740. temp = a_ref (j, k);
  2741. i__3 = *m;
  2742. for (i__ = 1; i__ <= i__3; ++i__) {
  2743. b_ref (i__, j) = b_ref (i__, j) - temp * b_ref (i__, k);
  2744. /* L330: */
  2745. }
  2746. }
  2747. /* L340: */
  2748. }
  2749. if (*alpha != 1.) {
  2750. i__2 = *m;
  2751. for (i__ = 1; i__ <= i__2; ++i__) {
  2752. b_ref (i__, k) = *alpha * b_ref (i__, k);
  2753. /* L350: */
  2754. }
  2755. }
  2756. /* L360: */
  2757. }
  2758. }
  2759. }
  2760. }
  2761. return 0;
  2762. } /* NUMblas_dtrsm */
  2763. #undef b_ref
  2764. #undef a_ref
  2765. integer NUMblas_idamax (integer *n, double *dx, integer *incx) {
  2766. /* System generated locals */
  2767. integer ret_val, i__1;
  2768. double d__1;
  2769. /* Local variables */
  2770. static double dmax__;
  2771. static integer i__, ix;
  2772. /* finds the index of element having max. absolute value. jack
  2773. dongarra, linpack, 3/11/78. modified 3/93 to return if incx .le. 0.
  2774. modified 12/3/93, array(1) declarations changed to array(*) Parameter
  2775. adjustments */
  2776. --dx;
  2777. /* Function Body */
  2778. ret_val = 0;
  2779. if (*n < 1 || *incx <= 0) {
  2780. return ret_val;
  2781. }
  2782. ret_val = 1;
  2783. if (*n == 1) {
  2784. return ret_val;
  2785. }
  2786. if (*incx == 1) {
  2787. goto L20;
  2788. }
  2789. /* code for increment not equal to 1 */
  2790. ix = 1;
  2791. dmax__ = fabs (dx[1]);
  2792. ix += *incx;
  2793. i__1 = *n;
  2794. for (i__ = 2; i__ <= i__1; ++i__) {
  2795. if ( (d__1 = dx[ix], fabs (d__1)) <= dmax__) {
  2796. goto L5;
  2797. }
  2798. ret_val = i__;
  2799. dmax__ = (d__1 = dx[ix], fabs (d__1));
  2800. L5:
  2801. ix += *incx;
  2802. /* L10: */
  2803. }
  2804. return ret_val;
  2805. /* code for increment equal to 1 */
  2806. L20:
  2807. dmax__ = fabs (dx[1]);
  2808. i__1 = *n;
  2809. for (i__ = 2; i__ <= i__1; ++i__) {
  2810. if ( (d__1 = dx[i__], fabs (d__1)) <= dmax__) {
  2811. goto L30;
  2812. }
  2813. ret_val = i__;
  2814. dmax__ = (d__1 = dx[i__], fabs (d__1));
  2815. L30:
  2816. ;
  2817. }
  2818. return ret_val;
  2819. } /* NUMblas_idamax */
  2820. #undef MAX
  2821. #undef MIN
  2822. /* End of file NUMcblas.cpp */