MatrixPropertiesTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. <?php
  2. namespace MathPHP\Tests\LinearAlgebra\Matrix\Numeric;
  3. use MathPHP\LinearAlgebra\MatrixFactory;
  4. use MathPHP\LinearAlgebra\NumericMatrix;
  5. class MatrixPropertiesTest extends \PHPUnit\Framework\TestCase
  6. {
  7. use \MathPHP\Tests\LinearAlgebra\Fixture\MatrixDataProvider;
  8. /**
  9. * @test isSymmetric returns true for symmetric matrices.
  10. * @dataProvider dataProviderForSymmetricMatrix
  11. * @param array $A
  12. * @throws \Exception
  13. */
  14. public function testIsSymmetric(array $A)
  15. {
  16. // Given
  17. $A = MatrixFactory::create($A);
  18. // Then
  19. $this->assertTrue($A->isSymmetric());
  20. }
  21. /**
  22. * @test isSymmetric returns false for nonsymmetric matrices.
  23. * @dataProvider dataProviderForNotSymmetricMatrix
  24. * @dataProvider dataProviderForNotSquareMatrix
  25. * @param array $A
  26. * @throws \Exception
  27. */
  28. public function testIsNotSymmetric(array $A)
  29. {
  30. // Given
  31. $A = MatrixFactory::create($A);
  32. // Then
  33. $this->assertFalse($A->isSymmetric());
  34. }
  35. /**
  36. * @test isSkewSymmetric returns true for skew-symmetric matrices.
  37. * @dataProvider dataProviderForSkewSymmetricMatrix
  38. * @param array $A
  39. * @throws \Exception
  40. */
  41. public function testIsSkewSymmetric(array $A)
  42. {
  43. // Given
  44. $A = MatrixFactory::create($A);
  45. // Then
  46. $this->assertTrue($A->isSkewSymmetric());
  47. }
  48. /**
  49. * @test isSkewSymmetric returns false for non skew-symmetric matrices.
  50. * @dataProvider dataProviderForNotSkewSymmetricMatrix
  51. * @dataProvider dataProviderForNotSymmetricMatrix
  52. * @dataProvider dataProviderForNotSquareMatrix
  53. * @param array $A
  54. * @throws \Exception
  55. */
  56. public function testIsNotSkewSymmetric(array $A)
  57. {
  58. // Given
  59. $A = MatrixFactory::create($A);
  60. // Then
  61. $this->assertFalse($A->isSkewSymmetric());
  62. }
  63. /**
  64. * @test isSingular returns true for a singular matrix.
  65. * @dataProvider dataProviderForSingularMatrix
  66. * @param array $A
  67. * @throws \Exception
  68. */
  69. public function testIsSingular(array $A)
  70. {
  71. // Given
  72. $A = MatrixFactory::create($A);
  73. // Then
  74. $this->assertTrue($A->isSingular());
  75. }
  76. /**
  77. * @test isSingular returns false for a nonsingular matrix.
  78. * @dataProvider dataProviderForNonsingularMatrix
  79. * @param array $A
  80. * @throws \Exception
  81. */
  82. public function testIsSingularFalseForNonsingularMatrix(array $A)
  83. {
  84. // Given
  85. $A = MatrixFactory::create($A);
  86. // Then
  87. $this->assertFalse($A->isSingular());
  88. }
  89. /**
  90. * @test isNonsingular returns true for a nonsingular matrix.
  91. * @dataProvider dataProviderForNonsingularMatrix
  92. * @param array $A
  93. * @throws \Exception
  94. */
  95. public function testIsNonsingular(array $A)
  96. {
  97. // Given
  98. $A = MatrixFactory::create($A);
  99. // Then
  100. $this->assertTrue($A->isNonsingular());
  101. }
  102. /**
  103. * @test isInvertible returns true for a invertible matrix.
  104. * @dataProvider dataProviderForNonsingularMatrix
  105. * @param array $A
  106. * @throws \Exception
  107. */
  108. public function testIsInvertible(array $A)
  109. {
  110. // Given
  111. $A = MatrixFactory::create($A);
  112. // Then
  113. $this->assertTrue($A->isInvertible());
  114. }
  115. /**
  116. * @test isNonsingular returns false for a singular matrix.
  117. * @dataProvider dataProviderForSingularMatrix
  118. * @param array $A
  119. * @throws \Exception
  120. */
  121. public function testIsNonsingularFalseForSingularMatrix(array $A)
  122. {
  123. // Given
  124. $A = MatrixFactory::create($A);
  125. $this->assertFalse($A->isNonsingular());
  126. }
  127. /**
  128. * @test isInvertible returns false for a non-invertible matrix.
  129. * @dataProvider dataProviderForSingularMatrix
  130. * @param array $A
  131. * @throws \Exception
  132. */
  133. public function testIsInvertibleFalseForNonInvertibleMatrix(array $A)
  134. {
  135. // Given
  136. $A = MatrixFactory::create($A);
  137. // Then
  138. $this->assertFalse($A->isInvertible());
  139. }
  140. /**
  141. * @test isPositiveDefinite returns true for a positive definite square matrix.
  142. * @dataProvider dataProviderForPositiveDefiniteMatrix
  143. * @param array $A
  144. * @throws \Exception
  145. */
  146. public function testIsPositiveDefinite(array $A)
  147. {
  148. // Given
  149. $A = MatrixFactory::create($A);
  150. // Then
  151. $this->assertTrue($A->isPositiveDefinite());
  152. }
  153. /**
  154. * @test isPositiveDefinite returns false for a non positive definite square matrix.
  155. * @dataProvider dataProviderForNotPositiveDefiniteMatrix
  156. * @param array $A
  157. * @throws \Exception
  158. */
  159. public function testIsNotPositiveDefinite(array $A)
  160. {
  161. // Given
  162. $A = MatrixFactory::create($A);
  163. // Then
  164. $this->assertFalse($A->isPositiveDefinite());
  165. }
  166. /**
  167. * @test isPositiveSemidefinite returns true for a positive definite square matrix.
  168. * @dataProvider dataProviderForPositiveSemidefiniteMatrix
  169. * @param array $A
  170. * @throws \Exception
  171. */
  172. public function testIsPositiveSemidefinite(array $A)
  173. {
  174. // Given
  175. $A = MatrixFactory::create($A);
  176. // Then
  177. $this->assertTrue($A->isPositiveSemidefinite());
  178. }
  179. /**
  180. * @test isPositiveSemidefinite returns false for a non positive semidefinite square matrix.
  181. * @dataProvider dataProviderForNotPositiveSemidefiniteMatrix
  182. * @param array $A
  183. * @throws \Exception
  184. */
  185. public function testIsNotPositiveSemiDefinite(array $A)
  186. {
  187. // Given
  188. $A = MatrixFactory::create($A);
  189. // Then
  190. $this->assertFalse($A->isPositiveSemidefinite());
  191. }
  192. /**
  193. * @test isNegativeDefinite returns true for a negative definite square matrix.
  194. * @dataProvider dataProviderForNegativeDefiniteMatrix
  195. * @param array $A
  196. * @throws \Exception
  197. */
  198. public function testIsNegativeDefinite(array $A)
  199. {
  200. // Given
  201. $A = MatrixFactory::create($A);
  202. // Then
  203. $this->assertTrue($A->isNegativeDefinite());
  204. }
  205. /**
  206. * @test isNegativeDefinite returns false for a non negative definite square matrix.
  207. * @dataProvider dataProviderForNotNegativeDefiniteMatrix
  208. * @param array $A
  209. * @throws \Exception
  210. */
  211. public function testIsNotNegativeDefinite(array $A)
  212. {
  213. // Given
  214. $A = MatrixFactory::create($A);
  215. // Then
  216. $this->assertFalse($A->isNegativeDefinite());
  217. }
  218. /**
  219. * @test isNegativeSemidefinite returns true for a negative semidefinite square matrix.
  220. * @dataProvider dataProviderForNegativeSemidefiniteMatrix
  221. * @param array $A
  222. * @throws \Exception
  223. */
  224. public function testIsNegativeSemidefinite(array $A)
  225. {
  226. // Given
  227. $A = MatrixFactory::create($A);
  228. // Then
  229. $this->assertTrue($A->isNegativeSemidefinite());
  230. }
  231. /**
  232. * @test isNegativeSemidefinite returns false for a non negative semidefinite square matrix.
  233. * @dataProvider dataProviderForNotNegativeSemidefiniteMatrix
  234. * @param array $A
  235. * @throws \Exception
  236. */
  237. public function testIsNotNegativeSemidefinite(array $A)
  238. {
  239. // Given
  240. $A = MatrixFactory::create($A);
  241. // Then
  242. $this->assertFalse($A->isNegativeSemidefinite());
  243. }
  244. /**
  245. * @test Non square matrix is not any definite.
  246. * @throws \Exception
  247. */
  248. public function testNonSquareMatrixIsNotAnyDefinite()
  249. {
  250. // Given
  251. $A = new NumericMatrix([
  252. [1, 2, 3],
  253. [2, 3, 4],
  254. ]);
  255. // Then
  256. $this->assertFalse($A->isPositiveDefinite());
  257. $this->assertFalse($A->isPositiveSemidefinite());
  258. $this->assertFalse($A->isNegativeDefinite());
  259. $this->assertFalse($A->isNegativeSemidefinite());
  260. }
  261. /**
  262. * @test Non symmetric square matrix is not any definite.
  263. * @throws \Exception
  264. */
  265. public function testNonSymmetricSquareMatrixIsNotAnyDefinite()
  266. {
  267. // Given
  268. $A = new NumericMatrix([
  269. [1, 2, 3],
  270. [9, 8, 4],
  271. [6, 2, 5],
  272. ]);
  273. // Then
  274. $this->assertFalse($A->isPositiveDefinite());
  275. $this->assertFalse($A->isPositiveSemidefinite());
  276. $this->assertFalse($A->isNegativeDefinite());
  277. $this->assertFalse($A->isNegativeSemidefinite());
  278. }
  279. /**
  280. * @test isUpperTriangular returns true for an upper triangular matrix
  281. * @dataProvider dataProviderForUpperTriangularMatrix
  282. * @param array $U
  283. * @throws \Exception
  284. */
  285. public function testIsUpperTriangular(array $U)
  286. {
  287. // Given
  288. $U = MatrixFactory::create($U);
  289. // Then
  290. $this->assertTrue($U->isUpperTriangular());
  291. }
  292. /**
  293. * @test isUpperTriangular returns false for a non upper triangular matrix
  294. * @dataProvider dataProviderForNotTriangularMatrix
  295. * @param array $A
  296. * @throws \Exception
  297. */
  298. public function testIsNotUpperTriangular(array $A)
  299. {
  300. // Given
  301. $A = MatrixFactory::create($A);
  302. // Then
  303. $this->assertFalse($A->isUpperTriangular());
  304. }
  305. /**
  306. * @test isLowerTriangular returns true for an upper triangular matrix
  307. * @dataProvider dataProviderForLowerTriangularMatrix
  308. * @param array $L
  309. * @throws \Exception
  310. */
  311. public function testIsLowerTriangular(array $L)
  312. {
  313. // Given
  314. $L = MatrixFactory::create($L);
  315. // Then
  316. $this->assertTrue($L->isLowerTriangular());
  317. }
  318. /**
  319. * @test isLowerTriangular returns false for a non upper triangular matrix
  320. * @dataProvider dataProviderForNotTriangularMatrix
  321. * @param array $A
  322. * @throws \Exception
  323. */
  324. public function testIsNotLowerTriangular(array $A)
  325. {
  326. // Given
  327. $A = MatrixFactory::create($A);
  328. // Then
  329. $this->assertFalse($A->isLowerTriangular());
  330. }
  331. /**
  332. * @test isTriangular returns true for a lower triangular matrix
  333. * @dataProvider dataProviderForLowerTriangularMatrix
  334. * @param array $L
  335. * @throws \Exception
  336. */
  337. public function testIsTriangularForLowerTriangular(array $L)
  338. {
  339. // Given
  340. $L = MatrixFactory::create($L);
  341. $this->assertTrue($L->isTriangular());
  342. }
  343. /**
  344. * @test isTriangular returns true for an upper triangular matrix
  345. * @dataProvider dataProviderForUpperTriangularMatrix
  346. * @param array $U
  347. * @throws \Exception
  348. */
  349. public function testIsTriangularForUpperTriangular(array $U)
  350. {
  351. // Given
  352. $U = MatrixFactory::create($U);
  353. // Then
  354. $this->assertTrue($U->isTriangular());
  355. }
  356. /**
  357. * @test isTriangular returns false for a non triangular matrix
  358. * @dataProvider dataProviderForNotTriangularMatrix
  359. * @param array $A
  360. * @throws \Exception
  361. */
  362. public function testIsNotTriangular(array $A)
  363. {
  364. // Given
  365. $A = MatrixFactory::create($A);
  366. // Then
  367. $this->assertFalse($A->isTriangular());
  368. }
  369. /**
  370. * @test isDiagonal returns true for a diagonal matrix
  371. * @dataProvider dataProviderForDiagonalMatrix
  372. * @param array $D
  373. * @throws \Exception
  374. */
  375. public function testIsDiagonal(array $D)
  376. {
  377. // Given
  378. $D = MatrixFactory::create($D);
  379. // Then
  380. $this->assertTrue($D->isDiagonal());
  381. }
  382. /**
  383. * @test isDiagonal returns false for a non diagonal matrix
  384. * @dataProvider dataProviderForNotDiagonalMatrix
  385. * @param array $A
  386. * @throws \Exception
  387. */
  388. public function testIsDiagonalForLowerTriangular(array $A)
  389. {
  390. // Given
  391. $A = MatrixFactory::create($A);
  392. // Then
  393. $this->assertFalse($A->isDiagonal());
  394. }
  395. /**
  396. * @test isRectangularDiagonal returns true appropriately
  397. * @dataProvider dataProviderForRectangularDiagonalMatrix
  398. * @param array $D
  399. * @throws \Exception
  400. */
  401. public function testIsRectangularDiagonal(array $D)
  402. {
  403. // Given
  404. $D = MatrixFactory::create($D);
  405. // Then
  406. $this->assertTrue($D->isRectangularDiagonal());
  407. }
  408. /**
  409. * @test isRectangularDiagonal returns false appropriately
  410. * @dataProvider dataProviderForNotRectangularDiagonalMatrix
  411. * @param array $D
  412. * @throws \Exception
  413. */
  414. public function testIsNotRectangularDiagonal(array $D)
  415. {
  416. // Given
  417. $D = MatrixFactory::create($D);
  418. // Then
  419. $this->assertFalse($D->isRectangularDiagonal());
  420. }
  421. /**
  422. * @test isRef returns true for a matrix in row echelon form
  423. * @dataProvider dataProviderForRefMatrix
  424. * @param array $A
  425. * @throws \Exception
  426. */
  427. public function testIsRef(array $A)
  428. {
  429. // Given
  430. $A = MatrixFactory::create($A);
  431. // Then
  432. $this->assertTrue($A->isRef());
  433. }
  434. /**
  435. * @test isRef returns false for a matrix not in row echelon form
  436. * @dataProvider dataProviderForNotRefMatrix
  437. * @param array $A
  438. * @throws \Exception
  439. */
  440. public function testIsNotRef(array $A)
  441. {
  442. // Given
  443. $A = MatrixFactory::create($A);
  444. // Then
  445. $this->assertFalse($A->isRef());
  446. }
  447. /**
  448. * @test isRef returns true for a matrix in row echelon form
  449. * @dataProvider dataProviderForRrefMatrix
  450. * @param array $A
  451. * @throws \Exception
  452. */
  453. public function testIsRref(array $A)
  454. {
  455. // Given
  456. $A = MatrixFactory::create($A);
  457. $this->assertTrue($A->isRref());
  458. }
  459. /**
  460. * @test isRef returns false for a matrix not in row echelon form
  461. * @dataProvider dataProviderForNotRefMatrix
  462. * @param array $A
  463. * @throws \Exception
  464. */
  465. public function testIsNotRref(array $A)
  466. {
  467. // Given
  468. $A = MatrixFactory::create($A);
  469. // Then
  470. $this->assertFalse($A->isRref());
  471. }
  472. /**
  473. * @test isRef returns false for a ref matrix
  474. * @dataProvider dataProviderForNotRrefMatrix
  475. * @param array $A
  476. * @throws \Exception
  477. */
  478. public function testIsNotRrefForRefMatrix(array $A)
  479. {
  480. // Given
  481. $A = MatrixFactory::create($A);
  482. // Then
  483. $this->assertFalse($A->isRref());
  484. }
  485. /**
  486. * @test isIdempotent returns true for an Idempotent matrix
  487. * @dataProvider dataProviderForIdempotentMatrix
  488. * @param array $A
  489. * @throws \Exception
  490. */
  491. public function testIsIdempotent(array $A)
  492. {
  493. // Given
  494. $A = MatrixFactory::create($A);
  495. // Then
  496. $this->assertTrue($A->isIdempotent());
  497. }
  498. /**
  499. * @test isIdempotent returns false for a non-Idempotent matrix
  500. * @dataProvider dataProviderForNotIdempotentMatrix
  501. * @param array $A
  502. * @throws \Exception
  503. */
  504. public function testIsNotIdempotent(array $A)
  505. {
  506. // Given
  507. $A = MatrixFactory::create($A);
  508. // Then
  509. $this->assertFalse($A->isIdempotent());
  510. }
  511. /**
  512. * @test isNilpotent returns true for a nilpotent matrix
  513. * @dataProvider dataProviderForNilpotentMatrix
  514. * @param array $A
  515. * @throws \Exception
  516. */
  517. public function testIsNilpotent(array $A)
  518. {
  519. // Given
  520. $A = MatrixFactory::create($A);
  521. // Then
  522. $this->assertTrue($A->isNilpotent());
  523. }
  524. /**
  525. * @test isNilpotent returns false for a non-nilpotent matrix
  526. * @dataProvider dataProviderForNotNilpotentMatrix
  527. * @param array $A
  528. * @throws \Exception
  529. */
  530. public function testIsNotNilpotent(array $A)
  531. {
  532. // Given
  533. $A = MatrixFactory::create($A);
  534. // Then
  535. $this->assertFalse($A->isNilpotent());
  536. }
  537. /**
  538. * @test isInvolutory returns true for a Involutory matrix
  539. * @dataProvider dataProviderForInvolutoryMatrix
  540. * @param array $A
  541. * @throws \Exception
  542. */
  543. public function testIsInvolutory(array $A)
  544. {
  545. // Given
  546. $A = MatrixFactory::create($A);
  547. // Then
  548. $this->assertTrue($A->isInvolutory());
  549. }
  550. /**
  551. * @test isInvolutory returns false for a non-Involutory matrix
  552. * @dataProvider dataProviderForNotInvolutoryMatrix
  553. * @param array $A
  554. * @throws \Exception
  555. */
  556. public function testIsNotInvolutory(array $A)
  557. {
  558. // Given
  559. $A = MatrixFactory::create($A);
  560. // Then
  561. $this->assertFalse($A->isInvolutory());
  562. }
  563. /**
  564. * @test isSignature returns true for a Signature matrix
  565. * @dataProvider dataProviderForSignatureMatrix
  566. * @param array $A
  567. * @throws \Exception
  568. */
  569. public function testIsSignature(array $A)
  570. {
  571. // Given
  572. $A = MatrixFactory::create($A);
  573. // Then
  574. $this->assertTrue($A->isSignature());
  575. }
  576. /**
  577. * @test isSignature returns false for a non-Signature matrix
  578. * @dataProvider dataProviderForNotSignatureMatrix
  579. * @param array $A
  580. * @throws \Exception
  581. */
  582. public function testIsNotSignature(array $A)
  583. {
  584. // Given
  585. $A = MatrixFactory::create($A);
  586. $this->assertFalse($A->isSignature());
  587. }
  588. /**
  589. * @test isUpperBidiagonal returns true for an upper bidiagonal matrix
  590. * @dataProvider dataProviderForUpperBidiagonalMatrix
  591. * @param array $A
  592. * @throws \Exception
  593. */
  594. public function testIsUpperBidiagonal(array $A)
  595. {
  596. // Given
  597. $A = MatrixFactory::create($A);
  598. // Then
  599. $this->assertTrue($A->isUpperBidiagonal());
  600. }
  601. /**
  602. * @test isUpperBidiagonal returns false for a non upper bidiagonal matrix
  603. * @dataProvider dataProviderForNotUpperBidiagonalMatrix
  604. * @param array $A
  605. * @throws \Exception
  606. */
  607. public function testIsNotUpperBidiagonal(array $A)
  608. {
  609. // Given
  610. $A = MatrixFactory::create($A);
  611. // Then
  612. $this->assertFalse($A->isUpperBidiagonal());
  613. }
  614. /**
  615. * @test isLowerBidiagonal returns true for a lower bidiagonal matrix
  616. * @dataProvider dataProviderForLowerBidiagonalMatrix
  617. * @param array $A
  618. * @throws \Exception
  619. */
  620. public function testIsLowerBidiagonal(array $A)
  621. {
  622. // Given
  623. $A = MatrixFactory::create($A);
  624. $this->assertTrue($A->isLowerBidiagonal());
  625. }
  626. /**
  627. * @test isLowerBidiagonal returns false for a non lower bidiagonal matrix
  628. * @dataProvider dataProviderForNotLowerBidiagonalMatrix
  629. * @param array $A
  630. * @throws \Exception
  631. */
  632. public function testIsNotLowerBidiagonal(array $A)
  633. {
  634. $A = MatrixFactory::create($A);
  635. // Then
  636. $this->assertFalse($A->isLowerBidiagonal());
  637. }
  638. /**
  639. * @test isBidiagonal returns true for a lower bidiagonal matrix
  640. * @dataProvider dataProviderForLowerBidiagonalMatrix
  641. * @param array $A
  642. * @throws \Exception
  643. */
  644. public function testLowerBidiagonalIsBidiagonal(array $A)
  645. {
  646. // Given
  647. $A = MatrixFactory::create($A);
  648. // Then
  649. $this->assertTrue($A->isBidiagonal());
  650. }
  651. /**
  652. * @test isBidiagonal returns true for an upper bidiagonal matrix
  653. * @dataProvider dataProviderForUpperBidiagonalMatrix
  654. * @param array $A
  655. * @throws \Exception
  656. */
  657. public function testUpperBidiagonalIsBidiagonal(array $A)
  658. {
  659. // Given
  660. $A = MatrixFactory::create($A);
  661. // Then
  662. $this->assertTrue($A->isBidiagonal());
  663. }
  664. /**
  665. * @test isBidiagonal returns false for a non bidiagonal matrix
  666. * @dataProvider dataProviderForNotBidiagonalMatrix
  667. * @param array $A
  668. * @throws \Exception
  669. */
  670. public function testIsNotBidiagonal(array $A)
  671. {
  672. // Given
  673. $A = MatrixFactory::create($A);
  674. $this->assertFalse($A->isBidiagonal());
  675. }
  676. /**
  677. * @test isTridiagonal returns true for a tridiagonal matrix
  678. * @dataProvider dataProviderForTridiagonalMatrix
  679. * @param array $A
  680. * @throws \Exception
  681. */
  682. public function testIsTridiagonal(array $A)
  683. {
  684. // Given
  685. $A = MatrixFactory::create($A);
  686. // Then
  687. $this->assertTrue($A->isTridiagonal());
  688. }
  689. /**
  690. * @test isTridiagonal returns false for a non tridiagonal matrix
  691. * @dataProvider dataProviderForNotTridiagonalMatrix
  692. * @param array $A
  693. * @throws \Exception
  694. */
  695. public function testIsNotTridiagonal(array $A)
  696. {
  697. // Given
  698. $A = MatrixFactory::create($A);
  699. // Then
  700. $this->assertFalse($A->isTridiagonal());
  701. }
  702. /**
  703. * @test isUpperHessenberg returns true for an upper Hessenberg matrix
  704. * @dataProvider dataProviderForUpperHessenbergMatrix
  705. * @param array $A
  706. * @throws \Exception
  707. */
  708. public function testIsUpperHessenberg(array $A)
  709. {
  710. // Given
  711. $A = MatrixFactory::create($A);
  712. $this->assertTrue($A->isUpperHessenberg());
  713. }
  714. /**
  715. * @test isUpperHessenberg returns false for a non upper Hessenberg matrix
  716. * @dataProvider dataProviderForNotUpperHessenbergMatrix
  717. * @param array $A
  718. * @throws \Exception
  719. */
  720. public function testIsNotUpperHessenberg(array $A)
  721. {
  722. // Given
  723. $A = MatrixFactory::create($A);
  724. // Then
  725. $this->assertFalse($A->isUpperHessenberg());
  726. }
  727. /**
  728. * @test isLowerHessenberg returns true for an lower Hessenberg matrix
  729. * @dataProvider dataProviderForLowerHessenbergMatrix
  730. * @param array $A
  731. * @throws \Exception
  732. */
  733. public function testIsLowerHessenberg(array $A)
  734. {
  735. // Given
  736. $A = MatrixFactory::create($A);
  737. // Then
  738. $this->assertTrue($A->isLowerHessenberg());
  739. }
  740. /**
  741. * @test isLowerHessenberg returns false for a non lower Hessenberg matrix
  742. * @dataProvider dataProviderForNotLowerHessenbergMatrix
  743. * @param array $A
  744. * @throws \Exception
  745. */
  746. public function testIsNotLowerHessenberg(array $A)
  747. {
  748. // Given
  749. $A = MatrixFactory::create($A);
  750. // Then
  751. $this->assertFalse($A->isLowerHessenberg());
  752. }
  753. /**
  754. * @test isOrthogonal
  755. * @dataProvider dataProviderForOrthogonalMatrix
  756. * @param array $A
  757. * @throws \Exception
  758. */
  759. public function testIsOrthogonal2(array $A)
  760. {
  761. // Given
  762. $A = MatrixFactory::create($A);
  763. // Then
  764. $this->assertTrue($A->isOrthogonal());
  765. }
  766. /**
  767. * @test isOrthogonal when not orthogonal
  768. * @dataProvider dataProviderForNonOrthogonalMatrix
  769. * @param array $A
  770. * @throws \Exception
  771. */
  772. public function testIsOrthogonalWhenNotOrthogonal(array $A)
  773. {
  774. // Given
  775. $A = MatrixFactory::create($A);
  776. // Then
  777. $this->assertFalse($A->isOrthogonal());
  778. }
  779. /**
  780. * @test isNormal
  781. * @dataProvider dataProviderForOrthogonalMatrix
  782. * @dataProvider dataProviderForSkewSymmetricMatrix
  783. * @dataProvider dataProviderForDiagonalMatrix
  784. * @param array $A
  785. * @throws \Exception
  786. */
  787. public function testisNormal(array $A)
  788. {
  789. // Given
  790. $A = MatrixFactory::create($A);
  791. // Then
  792. $this->assertTrue($A->isNormal());
  793. }
  794. /**
  795. * @test isNormal when not normal
  796. * @dataProvider dataProviderForNonNormalMatrix
  797. * @param array $A
  798. * @throws \Exception
  799. */
  800. public function testIsNormalWhenNotNormal(array $A)
  801. {
  802. // Given
  803. $A = MatrixFactory::create($A);
  804. // Then
  805. $this->assertFalse($A->isNormal());
  806. }
  807. /**
  808. * @test isUnitary
  809. * @dataProvider dataProviderForOrthogonalMatrix
  810. * @param array $A
  811. * @throws \Exception
  812. */
  813. public function testIsUnitary(array $A)
  814. {
  815. // Given
  816. $A = MatrixFactory::create($A);
  817. // Then
  818. $this->assertTrue($A->isUnitary());
  819. }
  820. /**
  821. * @test isUnitary when not unitary
  822. * @dataProvider dataProviderForNonOrthogonalMatrix
  823. * @param array $A
  824. * @throws \Exception
  825. */
  826. public function testIsUnitaryWhenNotUnitary(array $A)
  827. {
  828. // Given
  829. $A = MatrixFactory::create($A);
  830. // Then
  831. $this->assertFalse($A->isUnitary());
  832. }
  833. /**
  834. * @test isHermitian returns true for hermitian matrices.
  835. * @dataProvider dataProviderForSymmetricMatrix
  836. * @param array $A
  837. * @throws \Exception
  838. */
  839. public function testIsHermitian(array $A)
  840. {
  841. // Given
  842. $A = MatrixFactory::create($A);
  843. // Then
  844. $this->assertTrue($A->isHermitian());
  845. }
  846. /**
  847. * @test isHermitian returns false for nonhermitian matrices.
  848. * @dataProvider dataProviderForNotSymmetricMatrix
  849. * @dataProvider dataProviderForNotSquareMatrix
  850. * @param array $A
  851. * @throws \Exception
  852. */
  853. public function testIsHermitianWhenNotHermitian(array $A)
  854. {
  855. // Given
  856. $A = MatrixFactory::create($A);
  857. // Then
  858. $this->assertFalse($A->isHermitian());
  859. }
  860. }