public function spliceRows(int $offset, int $length = null, array $replacement = null) : self { if ($replacement) { if ($this->getColumnCount() !== count($replacement[0])) { throw new MatrixException('Cannot splice [' . count($replacement) . '] columns into matrix of [' . $this->getRowCount() . '] column.'); } if (!static::subArraysAreEqualSize($replacement)) { throw new MatrixException('Cannot splice in new rows of unequal size.'); } } $spliced = $this->toArray(); array_splice($spliced, $offset, $length, $replacement); return new static($spliced); }
public function testSpliceUnevenRows() { $matrix = new Matrix([[1, -1, 2], [4, 0, 6], [0, 1, -1]]); static::expectException(MatrixException::class); $matrix->spliceRows(1, 1, [[8, 5, 1], [2]]); }