for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare (strict_types=1);
namespace Np\linAlgb\decompositions;
use Np\matrix;
use Np\core\lapack;
/**
* Cholesky
*
* An efficient decomposition of a square positive definite matrix into a
* lower triangular matrix and its conjugate transpose.
* @package Np
* @category Scientific Library
* @author ghost (Shubham Chaudhary)
* @email [email protected]
* @copyright (c) 2020-2021, Shubham Chaudhary
*/
class cholesky {
* @param matrix $m
* @return matrix|null
public static function factory(matrix $m): matrix|null {
if ($m->isSquare()) {
$ar = $m->copy();
$lp = lapack::potrf($ar);
if ($lp != 0) {
return null;
}
for ($i = 0; $i < $m->col; ++$i) {
for ($j = $i + 1; $j < $m->col; ++$j) {
$ar->data[$i * $m->col + $j] = 0.0;
unset($lp);
return $ar;