342 lu.col(k).tail(
rrows) /= lu.coeff(k,k);
344 else if(first_zero_pivot==-1)
348 first_zero_pivot = k;
352 lu.bottomRightCorner(rrows,rcols).noalias() -= lu.col(k).tail(rrows) * lu.row(k).tail(rcols);
354 return first_zero_pivot;
372 static Index blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, PivIndex* row_transpositions, PivIndex& nb_transpositions, Index maxBlockSize=256)
374 MapLU lu1(lu_data,StorageOrder==
RowMajor?rows:luStride,StorageOrder==
RowMajor?luStride:cols);
375 MatrixType lu(lu1,0,0,rows,cols);
377 const Index size = (std::min)(rows,cols);
382 return unblocked_lu(lu, row_transpositions, nb_transpositions);
390 blockSize = (blockSize/16)*16;
391 blockSize = (std::min)((std::max)(blockSize,Index(8)), maxBlockSize);
394 nb_transpositions = 0;
395 Index first_zero_pivot = -1;
396 for(Index k = 0; k < size; k+=blockSize)
398 Index bs = (std::min)(size-k,blockSize);
399 Index trows = rows - k - bs;
400 Index tsize = size - k - bs;
406 BlockType A_0(lu,0,0,rows,k);
407 BlockType A_2(lu,0,k+bs,rows,tsize);
408 BlockType A11(lu,k,k,bs,bs);
409 BlockType A12(lu,k,k+bs,bs,tsize);
410 BlockType A21(lu,k+bs,k,trows,bs);
411 BlockType A22(lu,k+bs,k+bs,trows,tsize);
413 PivIndex nb_transpositions_in_panel;
416 Index ret = blocked_lu(trows+bs, bs, &lu.coeffRef(k,k), luStride,
417 row_transpositions+k, nb_transpositions_in_panel, 16);
418 if(ret>=0 && first_zero_pivot==-1)
419 first_zero_pivot = k+ret;
421 nb_transpositions += nb_transpositions_in_panel;
423 for(Index i=k; i<k+bs; ++i)
425 Index piv = (row_transpositions[i] += k);
426 A_0.row(i).swap(A_0.row(piv));
432 for(Index i=k;i<k+bs; ++i)
433 A_2.row(i).swap(A_2.row(row_transpositions[i]));
436 A11.template triangularView<UnitLower>().solveInPlace(A12);
438 A22.noalias() -= A21 * A12;
441 return first_zero_pivot;
447template<
typename MatrixType,
typename TranspositionType>
448void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions,
typename TranspositionType::StorageIndex& nb_transpositions)
450 eigen_assert(lu.cols() == row_transpositions.size());
451 eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
455 ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
460template<
typename MatrixType>
461template<
typename InputType>
462PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(
const EigenBase<InputType>& matrix)
464 check_template_parameters();
467 eigen_assert(matrix.rows()<NumTraits<int>::highest());
469 m_lu = matrix.derived();
471 eigen_assert(matrix.rows() == matrix.cols() &&
"PartialPivLU is only for square (and moreover invertible) matrices");
472 const Index size = matrix.rows();
474 m_rowsTranspositions.resize(size);
476 typename TranspositionType::StorageIndex nb_transpositions;
477 internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
478 m_det_p = (nb_transpositions%2) ? -1 : 1;
480 m_p = m_rowsTranspositions;
482 m_isInitialized =
true;
486template<
typename MatrixType>
489 eigen_assert(m_isInitialized &&
"PartialPivLU is not initialized.");
490 return Scalar(m_det_p) * m_lu.diagonal().prod();
496template<
typename MatrixType>
499 eigen_assert(m_isInitialized &&
"LU is not initialized.");
505 res = m_p.inverse() * res;
515template<
typename DstXprType,
typename MatrixType,
typename Scalar>
522 dst =
src.nestedExpression().solve(MatrixType::Identity(
src.rows(),
src.cols()));
536template<
typename Derived>
553template<
typename Derived>