/** * Tests NumArray::dot with empty vectors */ public function testDotEmptyVectorVector() { $vector1 = NumPHP::zeros(0); $vector2 = NumPHP::zeros(0); $expectedNumArray = new NumArray(0); $this->assertNumArrayEquals($expectedNumArray, $vector1->dot($vector2)); }
/** * @param NumArray $matrix * @param NumArray $vector * @return NumArray */ protected static function backSubstitution(NumArray $matrix, NumArray $vector) { $shape = $matrix->getShape(); $xVector = \NumPHP\Core\NumPHP::zeros($shape[0]); for ($i = $shape[0] - 1; $i >= 0; $i--) { $sum = 0; for ($j = $i + 1; $j < $shape[0]; $j++) { $sum += $matrix->get($i, $j)->dot($xVector->get($j))->getData(); } $xVector->set($i, ($vector->get($i)->getData() - $sum) / $matrix->get($i, $i)->getData()); } return $xVector; }
/** * Tests NumArray::getSize on a 2x3x4 matrix */ public function getSize2x3x4() { $numArray = NumPHP::zeros(2, 3, 4); $this->assertSame(24, $numArray->getSize()); }
/** * Build the upper triangular matrix from given matrix * * @param NumArray $numArray given matrix * * @return NumArray * * @since 1.0.0 */ protected static function buildUMatrix(NumArray $numArray) { $shape = $numArray->getShape(); $nAxis = $shape[1]; $size = min($shape[0], $nAxis); $uMatrix = NumPHP::zeros($size, $nAxis); for ($i = 0; $i < $size; $i++) { $slice = sprintf("%d:", $i); $uMatrix->set($i, $slice, $numArray->get($i, $slice)); } return $uMatrix; }
/** * Tests NumArray::getShape on matrix size 2x4 */ public function testGetShape2x4() { $numArray = NumPHP::zeros(2, 4); $this->assertSame([2, 4], $numArray->getShape()); }
/** * Tests NumPHP::zerosLike with 2x3 matrix */ public function testZerosLike() { $numArray = new NumArray([[1, 2, 3], [4, 5, 6]]); $expectedNumArray = NumPHP::zeros(2, 3); $this->assertNumArrayEquals($expectedNumArray, NumPHP::zerosLike($numArray)); }