Calculate the row echelon form (REF) of the matrix using the row
reduction method. Return the matrix and the number of swaps in a
tuple.

@return array
173014
public function rowReductionMethod() : array
    {
        $row = $col = $swaps = 0;

        $b = $this->a;

        while ($row < $this->m and $col < $this->n) {
            $t = $b[$row];

            if ($t[$col] == 0) {
                for ($i = $row + 1; $i < $this->m; $i++) {
                    if ($b[$i][$col] != 0) {
                        $temp = $b[$i];

                        $b[$i] = $t;
                        $t = $temp;
        
                        $swaps++;

                        break 1;
                    }
                }
            }

            if ($t[$col] == 0) {
                $col++;

                continue 1;
            }

            $divisor = $t[$col];

            if ($divisor != 1) {
                for ($i = 0; $i < $this->n; $i++) {
                    $t[$i] /= $divisor;
                }
            }

            for ($i = $row + 1; $i < $this->m; $i++) {
                $scale = $b[$i][$col];

                if ($scale != 0) {
                    for ($j = 0; $j < $this->n; $j++) {
                        $b[$i][$j] += -$scale * $t[$j];
                    }
                }
            }

            $b[$row] = $t;

            $row++;
            $col++;
        }

        $b = self::quick($b);

        return [$b, $swaps];
    }
169932
private function calculateColumnWidth()
    {
        foreach ($this->rows as $rowIndex => $row) {
            foreach ($row as $columnIndex => $column) {
                if ( ! isset($this->columnWidths[ $columnIndex ])) {
                    $this->columnWidths[ $columnIndex ] = strlen($column);
                } else {
                    if (strlen($column) > $this->columnWidths[ $columnIndex ]) {
                        $this->columnWidths[ $columnIndex ] = strlen($column);
                    }
                }
            }
        }

        return $this->columnWidths;
    }
854386
private int[] rows() {
        int[] rowIndexes = new int[rowCount()];
        for (int i = 0; i < rowCount(); i++) {
            rowIndexes[i] = i;
        }
        return rowIndexes;
    }
244887
public function toArray() {
        $out = [];
        for ($i=static::ROWS;$i-->0;) {
            $out[$i] = $this[$i]->toArray();
        }
        return $out;
    }
402131
protected function getDiscountForSwitchToYearly()
    {
        $amount = 0;

        foreach ($this->asBraintreeSubscription()->discounts as $discount) {
            if ($discount->id == 'plan-credit') {
                $amount += (float) $discount->amount * $discount->numberOfBillingCycles;
            }
        }

        return (object) [
            'amount' => $amount,
            'numberOfBillingCycles' => 1,
        ];
    }
36981
public function showUserMatrix()
	{
  		if ( Shinobi::can( config('watchtower.acl.user.viewmatrix', false) ) ) {
			$roles = Role::all();
			$users = $this->model::orderBy('name')->get();
			$us = DB::table('role_user')->select('role_id as r_id','user_id as u_id')->get();

			$pivot = [];
			foreach($us as $u) {
				$pivot[] = $u->r_id.":".$u->u_id;
			}

			return view( config('watchtower.views.users.usermatrix'), compact('roles','users','pivot') );
		}

	 	return view( config('watchtower.views.layouts.unauthorized'), [ 'message' => 'sync user roles' ]);
	}
1092698
public function getL()
    {
        $L = [];
        for ($i = 0; $i < $this->m; ++$i) {
            for ($j = 0; $j < $this->n; ++$j) {
                if ($i > $j) {
                    $L[$i][$j] = $this->LU[$i][$j];
                } elseif ($i == $j) {
                    $L[$i][$j] = 1.0;
                } else {
                    $L[$i][$j] = 0.0;
                }
            }
        }
        return new Matrix($L);
    }
579818
public function det()
    {
        if ($this->m == $this->n) {
            $d = $this->pivsign;
            for ($j = 0; $j < $this->n; $j++) {
                $d *= $this->LU[$j][$j];
            }
            return $d;
        } else {
            trigger_error(MatrixDimensionException, ERROR);
        }
    }
1191407
protected function calculateImplicit()
    {
        /** @var string[][] $explicit List of all items that have been explicitly added to this ChangeSet */
        $explicit = [];

        /** @var string[][] $referenced List of all items that are "referenced" by items in $explicit */
        $referenced = [];

        /** @var string[][] $references List of which explicit items reference each thing in referenced */
        $references = [];

        /** @var ChangeSetItem $item */
        foreach ($this->Changes()->filter(['Added' => ChangeSetItem::EXPLICITLY]) as $item) {
            $explicitKey = $this->implicitKey($item);
            $explicit[$explicitKey] = true;

            foreach ($item->findReferenced() as $referee) {
                try {
                    /** @var DataObject $referee */
                    $key = $this->implicitKey($referee);

                    $referenced[$key] = [
                        'ObjectID' => $referee->ID,
                        'ObjectClass' => $referee->baseClass(),
                    ];

                    $references[$key][] = $item->ID;

                    // Skip any bad records
                } catch (UnexpectedDataException $e) {
                }
            }
        }

        /** @var string[][] $explicit List of all items that are either in $explicit, $referenced or both */
        $all = array_merge($referenced, $explicit);

        /** @var string[][] $implicit Anything that is in $all, but not in $explicit, is an implicit inclusion */
        $implicit = array_diff_key($all, $explicit);

        foreach ($implicit as $key => $object) {
            $implicit[$key]['ReferencedBy'] = $references[$key];
        }

        return $implicit;
    }
890750
private function winningValues()
    {
        return array_merge(
        // rows
            $this->board->getBoard(),
            // columns
            $this->transpose($this->board->getBoard()),
            // diagonals
            $this->diagonals()
        );
    }
1197690
public function getMatrix()
    {
        if (func_num_args() > 0) {
            $args = func_get_args();
            $match = implode(',', array_map('gettype', $args));
            switch ($match) {
 
      //A($i0...; $j0...)
      case 'integer,integer':
        list($i0, $j0) = $args;
          $m = $i0 >= 0 ? $this->m - $i0 : trigger_error(ArgumentBoundsException, ERROR);
          $n = $j0 >= 0 ? $this->n - $j0 : trigger_error(ArgumentBoundsException, ERROR);
          $R = new Matrix($m, $n);
 
          for ($i = $i0; $i < $this->m; $i++) {
              for ($j = $j0; $j < $this->n; $j++) {
                  $R->set($i, $j, $this->A[$i][$j]);
              }
          }
 
          return $R;
          break;
 
      //A($i0...$iF; $j0...$jF)
      case 'integer,integer,integer,integer':
       list($i0, $iF, $j0, $jF) = $args;
        $m = (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) ? $iF - $i0 : trigger_error(ArgumentBoundsException, ERROR);
        $n = (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) ? $jF - $j0 : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m+1, $n+1);
 
        for ($i = $i0; $i <= $iF; $i++) {
            for ($j = $j0; $j <= $jF; $j++) {
                $R->set($i - $i0, $j - $j0, $this->A[$i][$j]);
            }
        }
 
        return $R;
        break;
 
      //$R = array of row indices; $C = array of column indices
      case 'array,array':
        list($RL, $CL) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i - $i0, $j - $j0, $this->A[$RL[$i]][$CL[$j]]);
            }
        }
 
        return $R;
        break;
 
      //$RL = array of row indices; $CL = array of column indices
      case 'array,array':
        list($RL, $CL) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i, $j, $this->A[$RL[$i]][$CL[$j]]);
            }
        }
 
        return $R;
        break;
 
      //A($i0...$iF); $CL = array of column indices
      case 'integer,integer,array':
        list($i0, $iF, $CL) = $args;
        $m = (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) ? $iF - $i0 : trigger_error(ArgumentBoundsException, ERROR);
        $n = count($CL) > 0 ? count($CL) : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n);
 
        for ($i = $i0; $i < $iF; $i++) {
            for ($j = 0; $j < $n; $j++) {
                $R->set($i - $i0, $j, $this->A[$RL[$i]][$j]);
            }
        }
 
        return $R;
        break;
 
      //$RL = array of row indices
      case 'array,integer,integer':
        list($RL, $j0, $jF) = $args;
        $m = count($RL) > 0 ? count($RL) : trigger_error(ArgumentBoundsException, ERROR);
        $n = (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) ? $jF - $j0 : trigger_error(ArgumentBoundsException, ERROR);
        $R = new Matrix($m, $n+1);
 
        for ($i = 0; $i < $m; $i++) {
            for ($j = $j0; $j <= $jF; $j++) {
                $R->set($i, $j - $j0, $this->A[$RL[$i]][$j]);
            }
        }
 
        return $R;
        break;
      default:
        trigger_error(PolymorphicArgumentException, ERROR);
        break;
      }
        } else {
            trigger_error(PolymorphicArgumentException, ERROR);
        }
    }
343644
public PermutationMatrix getP() {
        PermutationMatrix perm = PermutationMatrix.fromPartialPivots(piv);
        perm.transpose();
        return perm;
    }
1204241
public static function getSubMatrix($matrix, $skipRow = 0, $skipColumn = 0) : array {
        $size     = count($matrix);
        $newSize  = $size-1;
        $cfRow    = 0;
        $cfColumn = 0;
        $cfMatrix = [];

        for ($row=0;$row<$size;$row++) {
            for ($col=0;$col<$size;$col++) {

                if ($row !== $skipRow && $col !== $skipColumn) {
                    if (!isset($cfMatrix[$cfRow])) {
                        $cfMatrix[$cfRow] = [];
                    }
                    $cfMatrix[$cfRow][$cfColumn++] = $matrix[$row][$col];
                    if ($cfColumn === ($newSize)) {
                        $cfColumn = 0;
                        $cfRow++;
                    }
                }
            }
        }
        return $cfMatrix;
    }
223353
public function getAdjoinMatrix() : Matrix {
        $matrix = new static();
        for ($i=0; $i<static::ROWS; $i++) {
            for ($j=0; $j<static::COLUMNS; $j++) {
                $subMatrix      = MatrixMath::getSubMatrix($this->toArray(), $i, $j);
                $matrix[$i][$j] = MatrixMath::calculateDeterminant($subMatrix);
            }
        }
        return $matrix;
    }
403995
public function getFirstRow()
    {
        $rows = $this->data['rows'];
        if (empty($rows)) {
            return false;
        }

        $row = array_slice($rows, 0, 1);

        return current($row);
    }
814635
public function rowCounts()
    {
        if (!$this->rowCounts) {
            foreach ($this->data['resultSets'] as $resultSet) {
                $this->rowCounts[] = $resultSet['stats']['rowCountExact'];
            }
        }

        return $this->rowCounts;
    }
66007
public function items() {
        if ( $this->_max <= 1 ) {
            return [];
        }
        $end = min( $this->_max, $this->_current + floor( $this->count / 2 ) );
        $start = max( 1, $end - $this->count + 1 );
        $items = [];
        if ( $start != 1 ) {
            $items[] = $this->item( $this->label_to_start, 1);
        }
        for ( $i = $start; $i <= $end; $i ++ ) {
            $items[] = $this->item( $i, $i, ($i == $this->_current) );
        }
        if ( $this->_current != $this->_max ) {
            $items[] = $this->item( $this->label_next, ($this->_current + 1) );
        }
        return $items;
    }