fn_hess.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. // Copyright 2015 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2015 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. #include <armadillo>
  16. #include <complex>
  17. #include "catch.hpp"
  18. using namespace arma;
  19. using namespace std;
  20. TEST_CASE("fn_hess_non_square")
  21. {
  22. mat A(5, 6, fill::ones);
  23. mat U, H;
  24. REQUIRE_THROWS( hess(U, H, A) );
  25. }
  26. /***************** tests for real matrix ****************/
  27. TEST_CASE("fn_hess_empty")
  28. {
  29. mat A(1, 1);
  30. A.reset();
  31. mat U, H, H1, H2;
  32. hess(U, H, A);
  33. H1 = hess(A);
  34. hess(H2, A);
  35. REQUIRE( U.is_empty() == true );
  36. REQUIRE( H.is_empty() == true );
  37. REQUIRE( H1.is_empty() == true );
  38. REQUIRE( H2.is_empty() == true );
  39. }
  40. TEST_CASE("fn_hess_1")
  41. {
  42. mat A(1, 1);
  43. A(0, 0) = 0.061198;
  44. mat U, H, H1, H2;
  45. hess(U, H, A);
  46. H1 = hess(A);
  47. hess(H2, A);
  48. REQUIRE( U(0, 0) == Approx(1.0) );
  49. REQUIRE( H(0, 0) == Approx(0.061198) );
  50. REQUIRE( H1(0, 0) == Approx(0.061198) );
  51. REQUIRE( H2(0, 0) == Approx(0.061198) );
  52. }
  53. TEST_CASE("fn_hess_2")
  54. {
  55. mat A =
  56. "\
  57. 0.061198 0.201990;\
  58. 0.437242 0.058956;\
  59. ";
  60. mat U, H, H1, H2;
  61. hess(U, H, A);
  62. H1 = hess(A);
  63. hess(H2, A);
  64. REQUIRE( U(0, 0) == Approx(1.0) );
  65. REQUIRE( U(0, 1) == Approx(0.0) );
  66. REQUIRE( U(1, 0) == Approx(0.0) );
  67. REQUIRE( U(1, 1) == Approx(1.0) );
  68. REQUIRE( H(0, 0) == Approx(0.061198) );
  69. REQUIRE( H(0, 1) == Approx(0.201990) );
  70. REQUIRE( H(1, 0) == Approx(0.437242) );
  71. REQUIRE( H(1, 1) == Approx(0.058956) );
  72. REQUIRE( H1(0, 0) == Approx(0.061198) );
  73. REQUIRE( H1(0, 1) == Approx(0.201990) );
  74. REQUIRE( H1(1, 0) == Approx(0.437242) );
  75. REQUIRE( H1(1, 1) == Approx(0.058956) );
  76. REQUIRE( H2(0, 0) == Approx(0.061198) );
  77. REQUIRE( H2(0, 1) == Approx(0.201990) );
  78. REQUIRE( H2(1, 0) == Approx(0.437242) );
  79. REQUIRE( H2(1, 1) == Approx(0.058956) );
  80. }
  81. TEST_CASE("fn_hess_3")
  82. {
  83. mat A =
  84. "\
  85. 0.061198 0.201990 0.019678;\
  86. 0.437242 0.058956 -0.149362;\
  87. -0.492474 -0.031309 0.314156;\
  88. ";
  89. mat U, H, H1, H2;
  90. hess(U, H, A);
  91. H1 = hess(A);
  92. hess(H2, A);
  93. REQUIRE( U(0, 0) == Approx(1.0) );
  94. REQUIRE( U(0, 1) == Approx(0.0) );
  95. REQUIRE( U(0, 2) == Approx(0.0) );
  96. REQUIRE( U(1, 0) == Approx( 0.0) );
  97. REQUIRE( U(1, 1) == Approx(-0.663928864062532) );
  98. REQUIRE( U(1, 2) == Approx( 0.747795736457915) );
  99. REQUIRE( U(2, 0) == Approx( 0.0) );
  100. REQUIRE( U(2, 1) == Approx( 0.747795736457915) );
  101. REQUIRE( U(2, 2) == Approx( 0.663928864062532) );
  102. REQUIRE( H(0, 0) == Approx( 0.061198000000000) );
  103. REQUIRE( H(0, 1) == Approx(-0.119391866749972) );
  104. REQUIRE( H(0, 2) == Approx( 0.164112052994157) );
  105. REQUIRE( H(1, 0) == Approx(-0.658567541896805) );
  106. REQUIRE( H(1, 1) == Approx( 0.291363559380149) );
  107. REQUIRE( H(1, 2) == Approx( 0.175033560375766) );
  108. REQUIRE( H(2, 0) == Approx( 0.0) );
  109. REQUIRE( H(2, 1) == Approx( 0.056980560375766) );
  110. REQUIRE( H(2, 2) == Approx( 0.081748440619851) );
  111. REQUIRE( H1(0, 0) == Approx( 0.061198000000000) );
  112. REQUIRE( H1(0, 1) == Approx(-0.119391866749972) );
  113. REQUIRE( H1(0, 2) == Approx( 0.164112052994157) );
  114. REQUIRE( H1(1, 0) == Approx(-0.658567541896805) );
  115. REQUIRE( H1(1, 1) == Approx( 0.291363559380149) );
  116. REQUIRE( H1(1, 2) == Approx( 0.175033560375766) );
  117. REQUIRE( H1(2, 0) == Approx( 0.0) );
  118. REQUIRE( H1(2, 1) == Approx( 0.056980560375766) );
  119. REQUIRE( H1(2, 2) == Approx( 0.081748440619851) );
  120. REQUIRE( H2(0, 0) == Approx( 0.061198000000000) );
  121. REQUIRE( H2(0, 1) == Approx(-0.119391866749972) );
  122. REQUIRE( H2(0, 2) == Approx( 0.164112052994157) );
  123. REQUIRE( H2(1, 0) == Approx(-0.658567541896805) );
  124. REQUIRE( H2(1, 1) == Approx( 0.291363559380149) );
  125. REQUIRE( H2(1, 2) == Approx( 0.175033560375766) );
  126. REQUIRE( H2(2, 0) == Approx( 0.0) );
  127. REQUIRE( H2(2, 1) == Approx( 0.056980560375766) );
  128. REQUIRE( H2(2, 2) == Approx( 0.081748440619851) );
  129. }
  130. TEST_CASE("fn_hess_4")
  131. {
  132. mat A =
  133. "\
  134. 0.061198 0.201990 0.019678 -0.493936;\
  135. 0.437242 0.058956 -0.149362 -0.045465;\
  136. -0.492474 -0.031309 0.314156 0.419733;\
  137. 0.336352 0.411541 0.458476 -0.393139;\
  138. ";
  139. mat U, H, H1, H2;
  140. hess(U, H, A);
  141. H1 = hess(A);
  142. hess(H2, A);
  143. REQUIRE( U(0, 0) == Approx(1.0) );
  144. REQUIRE( U(0, 1) == Approx(0.0) );
  145. REQUIRE( U(0, 2) == Approx(0.0) );
  146. REQUIRE( U(0, 3) == Approx(0.0) );
  147. REQUIRE( U(1, 0) == Approx( 0.0) );
  148. REQUIRE( U(1, 1) == Approx(-0.591275924818639) );
  149. REQUIRE( U(1, 2) == Approx(-0.462981984254642) );
  150. REQUIRE( U(1, 3) == Approx( 0.660333599770220) );
  151. REQUIRE( U(2, 0) == Approx( 0.0) );
  152. REQUIRE( U(2, 1) == Approx( 0.665965345962041) );
  153. REQUIRE( U(2, 2) == Approx( 0.181491258046004) );
  154. REQUIRE( U(2, 3) == Approx( 0.723568297557693) );
  155. REQUIRE( U(3, 0) == Approx( 0.0) );
  156. REQUIRE( U(3, 1) == Approx(-0.454843861899358) );
  157. REQUIRE( U(3, 2) == Approx( 0.867587808529208) );
  158. REQUIRE( U(3, 3) == Approx( 0.201018545870685) );
  159. REQUIRE( H(0, 0) == Approx( 0.061198000000000) );
  160. REQUIRE( H(0, 1) == Approx( 0.118336799794845) );
  161. REQUIRE( H(0, 2) == Approx(-0.518479197817449) );
  162. REQUIRE( H(0, 3) == Approx( 0.048328864303744) );
  163. REQUIRE( H(1, 0) == Approx(-0.739488928344434) );
  164. REQUIRE( H(1, 1) == Approx(-0.017815019577445) );
  165. REQUIRE( H(1, 2) == Approx( 0.549585804168668) );
  166. REQUIRE( H(1, 3) == Approx( 0.001541438669749) );
  167. REQUIRE( H(2, 0) == Approx( 0.0) );
  168. REQUIRE( H(2, 1) == Approx( 0.268224897826587) );
  169. REQUIRE( H(2, 2) == Approx(-0.266514530817371) );
  170. REQUIRE( H(2, 3) == Approx( 0.544078897369960) );
  171. REQUIRE( H(3, 0) == Approx( 0.0) );
  172. REQUIRE( H(3, 1) == Approx( 0.0) );
  173. REQUIRE( H(3, 2) == Approx( 0.163125252889179) );
  174. REQUIRE( H(3, 3) == Approx( 0.264302550394816) );
  175. REQUIRE( H1(0, 0) == Approx( 0.061198000000000) );
  176. REQUIRE( H1(0, 1) == Approx( 0.118336799794845) );
  177. REQUIRE( H1(0, 2) == Approx(-0.518479197817449) );
  178. REQUIRE( H1(0, 3) == Approx( 0.048328864303744) );
  179. REQUIRE( H1(1, 0) == Approx(-0.739488928344434) );
  180. REQUIRE( H1(1, 1) == Approx(-0.017815019577445) );
  181. REQUIRE( H1(1, 2) == Approx( 0.549585804168668) );
  182. REQUIRE( H1(1, 3) == Approx( 0.001541438669749) );
  183. REQUIRE( H1(2, 0) == Approx( 0.0) );
  184. REQUIRE( H1(2, 1) == Approx( 0.268224897826587) );
  185. REQUIRE( H1(2, 2) == Approx(-0.266514530817371) );
  186. REQUIRE( H1(2, 3) == Approx( 0.544078897369960) );
  187. REQUIRE( H1(3, 0) == Approx( 0.0) );
  188. REQUIRE( H1(3, 1) == Approx( 0.0) );
  189. REQUIRE( H1(3, 2) == Approx( 0.163125252889179) );
  190. REQUIRE( H1(3, 3) == Approx( 0.264302550394816) );
  191. REQUIRE( H2(0, 0) == Approx( 0.061198000000000) );
  192. REQUIRE( H2(0, 1) == Approx( 0.118336799794845) );
  193. REQUIRE( H2(0, 2) == Approx(-0.518479197817449) );
  194. REQUIRE( H2(0, 3) == Approx( 0.048328864303744) );
  195. REQUIRE( H2(1, 0) == Approx(-0.739488928344434) );
  196. REQUIRE( H2(1, 1) == Approx(-0.017815019577445) );
  197. REQUIRE( H2(1, 2) == Approx( 0.549585804168668) );
  198. REQUIRE( H2(1, 3) == Approx( 0.001541438669749) );
  199. REQUIRE( H2(2, 0) == Approx( 0.0) );
  200. REQUIRE( H2(2, 1) == Approx( 0.268224897826587) );
  201. REQUIRE( H2(2, 2) == Approx(-0.266514530817371) );
  202. REQUIRE( H2(2, 3) == Approx( 0.544078897369960) );
  203. REQUIRE( H2(3, 0) == Approx( 0.0) );
  204. REQUIRE( H2(3, 1) == Approx( 0.0) );
  205. REQUIRE( H2(3, 2) == Approx( 0.163125252889179) );
  206. REQUIRE( H2(3, 3) == Approx( 0.264302550394816) );
  207. }
  208. /***************** tests for complex matrix ****************/
  209. TEST_CASE("fn_hess_cx_empty")
  210. {
  211. cx_mat A(1, 1);
  212. A.reset();
  213. cx_mat U, H, H1, H2;
  214. hess(U, H, A);
  215. H1 = hess(A);
  216. hess(H2, A);
  217. REQUIRE( U.is_empty() == true );
  218. REQUIRE( H.is_empty() == true );
  219. REQUIRE( H1.is_empty() == true );
  220. REQUIRE( H2.is_empty() == true );
  221. }
  222. TEST_CASE("fn_hess_cx_1")
  223. {
  224. cx_mat A(1, 1);
  225. A(0, 0) = complex<double>(0.061198, 1.012234);
  226. cx_mat U, H, H1, H2;
  227. hess(U, H, A);
  228. H1 = hess(A);
  229. hess(H2, A);
  230. REQUIRE( U(0, 0).real() == Approx(1.0) );
  231. REQUIRE( U(0, 0).imag() == Approx(0.0) );
  232. REQUIRE( H(0, 0).real() == Approx(0.061198) );
  233. REQUIRE( H(0, 0).imag() == Approx(1.012234) );
  234. REQUIRE( H1(0, 0).real() == Approx(0.061198) );
  235. REQUIRE( H1(0, 0).imag() == Approx(1.012234) );
  236. REQUIRE( H2(0, 0).real() == Approx(0.061198) );
  237. REQUIRE( H2(0, 0).imag() == Approx(1.012234) );
  238. }
  239. TEST_CASE("fn_hess_cx_2")
  240. {
  241. mat B =
  242. "\
  243. 0.061198 0.201990;\
  244. 0.437242 0.058956;\
  245. ";
  246. cx_mat A(B, B*B);
  247. cx_mat U, H, H1, H2;
  248. hess(U, H, A);
  249. H1 = hess(A);
  250. hess(H2, A);
  251. REQUIRE( U(0, 0).real() == Approx(1.0) );
  252. REQUIRE( U(0, 0).imag() == Approx(0.0) );
  253. REQUIRE( U(0, 1).real() == Approx(0.0) );
  254. REQUIRE( U(0, 1).imag() == Approx(0.0) );
  255. REQUIRE( U(1, 0).real() == Approx(0.0) );
  256. REQUIRE( U(1, 0).imag() == Approx(0.0) );
  257. REQUIRE( U(1, 1).real() == Approx(1.0) );
  258. REQUIRE( U(1, 1).imag() == Approx(0.0) );
  259. REQUIRE( H(0, 0).real() == Approx( 0.061198000000000) );
  260. REQUIRE( H(0, 0).imag() == Approx( 0.092063706784000) );
  261. REQUIRE( H(0, 1).real() == Approx( 0.201990000000000) );
  262. REQUIRE( H(0, 1).imag() == Approx( 0.024269906460000) );
  263. REQUIRE( H(1, 0).real() == Approx( 0.437242000000000) );
  264. REQUIRE( H(1, 0).imag() == Approx( 0.052536375268000) );
  265. REQUIRE( H(1, 1).real() == Approx( 0.058956000000000) );
  266. REQUIRE( H(1, 1).imag() == Approx( 0.091794321516000) );
  267. REQUIRE( H1(0, 0).real() == Approx( 0.061198000000000) );
  268. REQUIRE( H1(0, 0).imag() == Approx( 0.092063706784000) );
  269. REQUIRE( H1(0, 1).real() == Approx( 0.201990000000000) );
  270. REQUIRE( H1(0, 1).imag() == Approx( 0.024269906460000) );
  271. REQUIRE( H1(1, 0).real() == Approx( 0.437242000000000) );
  272. REQUIRE( H1(1, 0).imag() == Approx( 0.052536375268000) );
  273. REQUIRE( H1(1, 1).real() == Approx( 0.058956000000000) );
  274. REQUIRE( H1(1, 1).imag() == Approx( 0.091794321516000) );
  275. REQUIRE( H2(0, 0).real() == Approx( 0.061198000000000) );
  276. REQUIRE( H2(0, 0).imag() == Approx( 0.092063706784000) );
  277. REQUIRE( H2(0, 1).real() == Approx( 0.201990000000000) );
  278. REQUIRE( H2(0, 1).imag() == Approx( 0.024269906460000) );
  279. REQUIRE( H2(1, 0).real() == Approx( 0.437242000000000) );
  280. REQUIRE( H2(1, 0).imag() == Approx( 0.052536375268000) );
  281. REQUIRE( H2(1, 1).real() == Approx( 0.058956000000000) );
  282. REQUIRE( H2(1, 1).imag() == Approx( 0.091794321516000) );
  283. }
  284. TEST_CASE("fn_hess_cx_3")
  285. {
  286. mat B =
  287. "\
  288. 0.061198 0.201990 0.019678;\
  289. 0.437242 0.058956 -0.149362;\
  290. -0.492474 -0.031309 0.314156;\
  291. ";
  292. cx_mat A(B, B*B);
  293. cx_mat U, H, H1, H2;
  294. hess(U, H, A);
  295. H1 = hess(A);
  296. hess(H2, A);
  297. REQUIRE( U(0, 0).real() == Approx(1.0) );
  298. REQUIRE( U(0, 0).imag() == Approx(0.0) );
  299. REQUIRE( U(0, 1).real() == Approx(0.0) );
  300. REQUIRE( U(0, 1).imag() == Approx(0.0) );
  301. REQUIRE( U(0, 2).real() == Approx(0.0) );
  302. REQUIRE( U(0, 2).imag() == Approx(0.0) );
  303. REQUIRE( U(1, 0).real() == Approx( 0.0) );
  304. REQUIRE( U(1, 0).imag() == Approx( 0.0) );
  305. REQUIRE( U(1, 1).real() == Approx(-0.625250908290361) );
  306. REQUIRE( U(1, 1).imag() == Approx(-0.180311900237219) );
  307. REQUIRE( U(1, 2).real() == Approx(-0.694923841863332) );
  308. REQUIRE( U(1, 2).imag() == Approx(-0.305989827159056) );
  309. REQUIRE( U(2, 0).real() == Approx( 0.0) );
  310. REQUIRE( U(2, 0).imag() == Approx( 0.0) );
  311. REQUIRE( U(2, 1).real() == Approx( 0.704232017531224) );
  312. REQUIRE( U(2, 1).imag() == Approx( 0.283912285396078) );
  313. REQUIRE( U(2, 2).real() == Approx(-0.565610163671470) );
  314. REQUIRE( U(2, 2).imag() == Approx(-0.321770449912063) );
  315. REQUIRE( H(0, 0).real() == Approx( 0.061198000000000) );
  316. REQUIRE( H(0, 0).imag() == Approx( 0.082372803412000) );
  317. REQUIRE( H(0, 1).real() == Approx(-0.101702999021493) );
  318. REQUIRE( H(0, 1).imag() == Approx(-0.061668749553784) );
  319. REQUIRE( H(0, 2).real() == Approx(-0.151590948501704) );
  320. REQUIRE( H(0, 2).imag() == Approx(-0.071689748472419) );
  321. REQUIRE( H(1, 0).real() == Approx(-0.699306461138236) );
  322. REQUIRE( H(1, 0).imag() == Approx( 0.0) );
  323. REQUIRE( H(1, 1).real() == Approx( 0.298129546829246) );
  324. REQUIRE( H(1, 1).imag() == Approx( 0.178624769103627) );
  325. REQUIRE( H(1, 2).real() == Approx(-0.165941859233838) );
  326. REQUIRE( H(1, 2).imag() == Approx( 0.014927427092653) );
  327. REQUIRE( H(2, 0).real() == Approx( 0.0) );
  328. REQUIRE( H(2, 0).imag() == Approx( 0.0) );
  329. REQUIRE( H(2, 1).real() == Approx(-0.061767777059231) );
  330. REQUIRE( H(2, 1).imag() == Approx( 0.0) );
  331. REQUIRE( H(2, 2).real() == Approx( 0.074982453170754) );
  332. REQUIRE( H(2, 2).imag() == Approx( 0.011525391092373) );
  333. REQUIRE( H1(0, 0).real() == Approx( 0.061198000000000) );
  334. REQUIRE( H1(0, 0).imag() == Approx( 0.082372803412000) );
  335. REQUIRE( H1(0, 1).real() == Approx(-0.101702999021493) );
  336. REQUIRE( H1(0, 1).imag() == Approx(-0.061668749553784) );
  337. REQUIRE( H1(0, 2).real() == Approx(-0.151590948501704) );
  338. REQUIRE( H1(0, 2).imag() == Approx(-0.071689748472419) );
  339. REQUIRE( H1(1, 0).real() == Approx(-0.699306461138236) );
  340. REQUIRE( H1(1, 0).imag() == Approx( 0.0) );
  341. REQUIRE( H1(1, 1).real() == Approx( 0.298129546829246) );
  342. REQUIRE( H1(1, 1).imag() == Approx( 0.178624769103627) );
  343. REQUIRE( H1(1, 2).real() == Approx(-0.165941859233838) );
  344. REQUIRE( H1(1, 2).imag() == Approx( 0.014927427092653) );
  345. REQUIRE( H1(2, 0).real() == Approx( 0.0) );
  346. REQUIRE( H1(2, 0).imag() == Approx( 0.0) );
  347. REQUIRE( H1(2, 1).real() == Approx(-0.061767777059231) );
  348. REQUIRE( H1(2, 1).imag() == Approx( 0.0) );
  349. REQUIRE( H1(2, 2).real() == Approx( 0.074982453170754) );
  350. REQUIRE( H1(2, 2).imag() == Approx( 0.011525391092373) );
  351. REQUIRE( H2(0, 0).real() == Approx( 0.061198000000000) );
  352. REQUIRE( H2(0, 0).imag() == Approx( 0.082372803412000) );
  353. REQUIRE( H2(0, 1).real() == Approx(-0.101702999021493) );
  354. REQUIRE( H2(0, 1).imag() == Approx(-0.061668749553784) );
  355. REQUIRE( H2(0, 2).real() == Approx(-0.151590948501704) );
  356. REQUIRE( H2(0, 2).imag() == Approx(-0.071689748472419) );
  357. REQUIRE( H2(1, 0).real() == Approx(-0.699306461138236) );
  358. REQUIRE( H2(1, 0).imag() == Approx( 0.0) );
  359. REQUIRE( H2(1, 1).real() == Approx( 0.298129546829246) );
  360. REQUIRE( H2(1, 1).imag() == Approx( 0.178624769103627) );
  361. REQUIRE( H2(1, 2).real() == Approx(-0.165941859233838) );
  362. REQUIRE( H2(1, 2).imag() == Approx( 0.014927427092653) );
  363. REQUIRE( H2(2, 0).real() == Approx( 0.0) );
  364. REQUIRE( H2(2, 0).imag() == Approx( 0.0) );
  365. REQUIRE( H2(2, 1).real() == Approx(-0.061767777059231) );
  366. REQUIRE( H2(2, 1).imag() == Approx( 0.0) );
  367. REQUIRE( H2(2, 2).real() == Approx( 0.074982453170754) );
  368. REQUIRE( H2(2, 2).imag() == Approx( 0.011525391092373) );
  369. }
  370. TEST_CASE("fn_hess_cx_4")
  371. {
  372. mat B =
  373. "\
  374. 0.061198 0.201990 0.019678 -0.493936;\
  375. 0.437242 0.058956 -0.149362 -0.045465;\
  376. -0.492474 -0.031309 0.314156 0.419733;\
  377. 0.336352 0.411541 0.458476 -0.393139;\
  378. ";
  379. cx_mat A(B, B*B);
  380. cx_mat U, H, H1, H2;
  381. hess(U, H, A*A);
  382. H1 = hess(A*A);
  383. hess(H2, A*A);
  384. REQUIRE( U(0, 0).real() == Approx(1.0) );
  385. REQUIRE( U(0, 0).imag() == Approx(0.0) );
  386. REQUIRE( U(0, 1).real() == Approx(0.0) );
  387. REQUIRE( U(0, 1).imag() == Approx(0.0) );
  388. REQUIRE( U(0, 2).real() == Approx(0.0) );
  389. REQUIRE( U(0, 2).imag() == Approx(0.0) );
  390. REQUIRE( U(0, 3).real() == Approx(0.0) );
  391. REQUIRE( U(0, 3).imag() == Approx(0.0) );
  392. REQUIRE( U(1, 0).real() == Approx( 0.0) );
  393. REQUIRE( U(1, 0).imag() == Approx( 0.0) );
  394. REQUIRE( U(1, 1).real() == Approx(-0.310409361344421) );
  395. REQUIRE( U(1, 1).imag() == Approx( 0.134965522927510) );
  396. REQUIRE( U(1, 2).real() == Approx( 0.368370931495079) );
  397. REQUIRE( U(1, 2).imag() == Approx( 0.620286967761253) );
  398. REQUIRE( U(1, 3).real() == Approx(-0.461565151978241) );
  399. REQUIRE( U(1, 3).imag() == Approx( 0.389788251419862) );
  400. REQUIRE( U(2, 0).real() == Approx( 0.0) );
  401. REQUIRE( U(2, 0).imag() == Approx( 0.0) );
  402. REQUIRE( U(2, 1).real() == Approx( 0.090510343531288) );
  403. REQUIRE( U(2, 1).imag() == Approx( 0.435448214446087) );
  404. REQUIRE( U(2, 2).real() == Approx(-0.629572243863963) );
  405. REQUIRE( U(2, 2).imag() == Approx( 0.277252591049466) );
  406. REQUIRE( U(2, 3).real() == Approx( 0.331725833624923) );
  407. REQUIRE( U(2, 3).imag() == Approx( 0.467889401534022) );
  408. REQUIRE( U(3, 0).real() == Approx( 0.0) );
  409. REQUIRE( U(3, 0).imag() == Approx( 0.0) );
  410. REQUIRE( U(3, 1).real() == Approx( 0.662749913792672) );
  411. REQUIRE( U(3, 1).imag() == Approx(-0.498383003349854) );
  412. REQUIRE( U(3, 2).real() == Approx(-0.073218600583049) );
  413. REQUIRE( U(3, 2).imag() == Approx(-0.030915392543373) );
  414. REQUIRE( U(3, 3).real() == Approx(-0.297561059397637) );
  415. REQUIRE( U(3, 3).imag() == Approx( 0.466387847936125) );
  416. REQUIRE( H(0, 0).real() == Approx(-0.059498334460944) );
  417. REQUIRE( H(0, 0).imag() == Approx( 0.187834910202221) );
  418. REQUIRE( H(0, 1).real() == Approx(-0.017930467829804) );
  419. REQUIRE( H(0, 1).imag() == Approx(-0.366928547670200) );
  420. REQUIRE( H(0, 2).real() == Approx(-0.021913405453089) );
  421. REQUIRE( H(0, 2).imag() == Approx(-0.128142818524165) );
  422. REQUIRE( H(0, 3).real() == Approx( 0.012590549436907) );
  423. REQUIRE( H(0, 3).imag() == Approx(-0.036787529849029) );
  424. REQUIRE( H(1, 0).real() == Approx(-0.212856818153491) );
  425. REQUIRE( H(1, 0).imag() == Approx( 0.0) );
  426. REQUIRE( H(1, 1).real() == Approx( 0.173480548915683) );
  427. REQUIRE( H(1, 1).imag() == Approx(-0.119570582029397) );
  428. REQUIRE( H(1, 2).real() == Approx(-0.098222486822866) );
  429. REQUIRE( H(1, 2).imag() == Approx(-0.073492477972392) );
  430. REQUIRE( H(1, 3).real() == Approx(-0.088126641335837) );
  431. REQUIRE( H(1, 3).imag() == Approx( 0.107905518898551) );
  432. REQUIRE( H(2, 0).real() == Approx( 0.0) );
  433. REQUIRE( H(2, 0).imag() == Approx( 0.0) );
  434. REQUIRE( H(2, 1).real() == Approx( 0.125544511009417) );
  435. REQUIRE( H(2, 1).imag() == Approx( 0.0) );
  436. REQUIRE( H(2, 2).real() == Approx( 0.374057080595739) );
  437. REQUIRE( H(2, 2).imag() == Approx( 0.061223114296791) );
  438. REQUIRE( H(2, 3).real() == Approx( 0.231175819260595) );
  439. REQUIRE( H(2, 3).imag() == Approx(-0.224564151240434) );
  440. REQUIRE( H(3, 0).real() == Approx( 0.0) );
  441. REQUIRE( H(3, 0).imag() == Approx( 0.0) );
  442. REQUIRE( H(3, 1).real() == Approx( 0.0) );
  443. REQUIRE( H(3, 1).imag() == Approx( 0.0) );
  444. REQUIRE( H(3, 2).real() == Approx(-0.238973358869022) );
  445. REQUIRE( H(3, 2).imag() == Approx( 0.0) );
  446. REQUIRE( H(3, 3).real() == Approx(-0.101771291133878) );
  447. REQUIRE( H(3, 3).imag() == Approx( 0.212030655387598) );
  448. REQUIRE( H1(0, 0).real() == Approx(-0.059498334460944) );
  449. REQUIRE( H1(0, 0).imag() == Approx( 0.187834910202221) );
  450. REQUIRE( H1(0, 1).real() == Approx(-0.017930467829804) );
  451. REQUIRE( H1(0, 1).imag() == Approx(-0.366928547670200) );
  452. REQUIRE( H1(0, 2).real() == Approx(-0.021913405453089) );
  453. REQUIRE( H1(0, 2).imag() == Approx(-0.128142818524165) );
  454. REQUIRE( H1(0, 3).real() == Approx( 0.012590549436907) );
  455. REQUIRE( H1(0, 3).imag() == Approx(-0.036787529849029) );
  456. REQUIRE( H1(1, 0).real() == Approx(-0.212856818153491) );
  457. REQUIRE( H1(1, 0).imag() == Approx( 0.0) );
  458. REQUIRE( H1(1, 1).real() == Approx( 0.173480548915683) );
  459. REQUIRE( H1(1, 1).imag() == Approx(-0.119570582029397) );
  460. REQUIRE( H1(1, 2).real() == Approx(-0.098222486822866) );
  461. REQUIRE( H1(1, 2).imag() == Approx(-0.073492477972392) );
  462. REQUIRE( H1(1, 3).real() == Approx(-0.088126641335837) );
  463. REQUIRE( H1(1, 3).imag() == Approx( 0.107905518898551) );
  464. REQUIRE( H1(2, 0).real() == Approx( 0.0) );
  465. REQUIRE( H1(2, 0).imag() == Approx( 0.0) );
  466. REQUIRE( H1(2, 1).real() == Approx( 0.125544511009417) );
  467. REQUIRE( H1(2, 1).imag() == Approx( 0.0) );
  468. REQUIRE( H1(2, 2).real() == Approx( 0.374057080595739) );
  469. REQUIRE( H1(2, 2).imag() == Approx( 0.061223114296791) );
  470. REQUIRE( H1(2, 3).real() == Approx( 0.231175819260595) );
  471. REQUIRE( H1(2, 3).imag() == Approx(-0.224564151240434) );
  472. REQUIRE( H1(3, 0).real() == Approx( 0.0) );
  473. REQUIRE( H1(3, 0).imag() == Approx( 0.0) );
  474. REQUIRE( H1(3, 1).real() == Approx( 0.0) );
  475. REQUIRE( H1(3, 1).imag() == Approx( 0.0) );
  476. REQUIRE( H1(3, 2).real() == Approx(-0.238973358869022) );
  477. REQUIRE( H1(3, 2).imag() == Approx( 0.0) );
  478. REQUIRE( H1(3, 3).real() == Approx(-0.101771291133878) );
  479. REQUIRE( H1(3, 3).imag() == Approx( 0.212030655387598) );
  480. REQUIRE( H2(0, 0).real() == Approx(-0.059498334460944) );
  481. REQUIRE( H2(0, 0).imag() == Approx( 0.187834910202221) );
  482. REQUIRE( H2(0, 1).real() == Approx(-0.017930467829804) );
  483. REQUIRE( H2(0, 1).imag() == Approx(-0.366928547670200) );
  484. REQUIRE( H2(0, 2).real() == Approx(-0.021913405453089) );
  485. REQUIRE( H2(0, 2).imag() == Approx(-0.128142818524165) );
  486. REQUIRE( H2(0, 3).real() == Approx( 0.012590549436907) );
  487. REQUIRE( H2(0, 3).imag() == Approx(-0.036787529849029) );
  488. REQUIRE( H2(1, 0).real() == Approx(-0.212856818153491) );
  489. REQUIRE( H2(1, 0).imag() == Approx( 0.0) );
  490. REQUIRE( H2(1, 1).real() == Approx( 0.173480548915683) );
  491. REQUIRE( H2(1, 1).imag() == Approx(-0.119570582029397) );
  492. REQUIRE( H2(1, 2).real() == Approx(-0.098222486822866) );
  493. REQUIRE( H2(1, 2).imag() == Approx(-0.073492477972392) );
  494. REQUIRE( H2(1, 3).real() == Approx(-0.088126641335837) );
  495. REQUIRE( H2(1, 3).imag() == Approx( 0.107905518898551) );
  496. REQUIRE( H2(2, 0).real() == Approx( 0.0) );
  497. REQUIRE( H2(2, 0).imag() == Approx( 0.0) );
  498. REQUIRE( H2(2, 1).real() == Approx( 0.125544511009417) );
  499. REQUIRE( H2(2, 1).imag() == Approx( 0.0) );
  500. REQUIRE( H2(2, 2).real() == Approx( 0.374057080595739) );
  501. REQUIRE( H2(2, 2).imag() == Approx( 0.061223114296791) );
  502. REQUIRE( H2(2, 3).real() == Approx( 0.231175819260595) );
  503. REQUIRE( H2(2, 3).imag() == Approx(-0.224564151240434) );
  504. REQUIRE( H2(3, 0).real() == Approx( 0.0) );
  505. REQUIRE( H2(3, 0).imag() == Approx( 0.0) );
  506. REQUIRE( H2(3, 1).real() == Approx( 0.0) );
  507. REQUIRE( H2(3, 1).imag() == Approx( 0.0) );
  508. REQUIRE( H2(3, 2).real() == Approx(-0.238973358869022) );
  509. REQUIRE( H2(3, 2).imag() == Approx( 0.0) );
  510. REQUIRE( H2(3, 3).real() == Approx(-0.101771291133878) );
  511. REQUIRE( H2(3, 3).imag() == Approx( 0.212030655387598) );
  512. }