37 namespace LAPACKFullMatrixImplementation
60 static_assert(std::is_same<T, double>::value ||
61 std::is_same<T, float>::value,
62 "Only implemented for double and float");
63 Assert(
matrix.size() ==
static_cast<std::size_t
>(n_rows * n_rows),
70 Assert(
static_cast<std::size_t
>(n_rows * n_rows) <=
74 Assert(
static_cast<std::size_t
>(n_rows * n_rows) <=
100 template <
typename T>
116 std::is_same<T, double>::value || std::is_same<T, float>::value,
117 "Only implemented for std::complex<double> and std::complex<float>");
118 Assert(
matrix.size() ==
static_cast<std::size_t
>(n_rows * n_rows),
123 Assert(
static_cast<std::size_t
>(n_rows * n_rows) <=
127 Assert(
static_cast<std::size_t
>(n_rows * n_rows) <=
154 template <
typename T>
171 Assert(
static_cast<std::size_t
>(n_rows * n_cols) ==
matrix.size(),
198 template <
typename T>
207 std::vector<std::complex<T>> & work,
215 Assert(
static_cast<std::size_t
>(n_rows * n_cols) ==
matrix.size(),
247template <
typename number>
256template <
typename number>
265template <
typename number>
274template <
typename number>
280 property =
M.property;
286template <
typename number>
296template <
typename number>
305 (*
this)(i,
j) = copy(i,
j);
310template <
typename number>
313 const std::array<number, 3> &
csr,
326 const number t =
A(i,
j);
335 const number t =
A(
j, i);
344template <
typename number>
364 (*this)(i,
j) = copy(
ii,
jj);
371template <
typename number>
381template <
typename number>
382template <
typename number2>
388 for (
size_type i = 0; i < this->m(); ++i)
390 (*
this)(i,
j) =
M(i,
j);
399template <
typename number>
400template <
typename number2>
406 for (
size_type i = 0; i < this->m(); ++i)
408 (*
this)(i,
j) =
M.el(i,
j);
417template <
typename number>
425 this->reset_values();
433template <
typename number>
442 const char type =
'G';
443 const number
cfrom = 1.;
450 number * values = this->values.data();
462template <
typename number>
473 const char type =
'G';
474 const number
cto = 1.;
481 number * values = this->values.data();
493template <
typename number>
511 number * values = this->values.data();
521 template <
typename number>
550 const std::array<number, 3>
csr =
556 const number t =
A(i,
k);
558 z(i) = -
csr[1] * t +
csr[0] * z(i);
593 const std::array<number, 3>
csr =
599 const number t =
A(i,
k);
601 z(i) = -
csr[1] * t +
csr[0] * z(i);
608 template <
typename number>
611 const std::complex<number> ,
612 const Vector<std::complex<number>> & )
620template <
typename number>
642 const size_type
N = this->m();
646 for (size_type i = 0; i <
N; ++i)
648 (*
this)(i,
j) = (*
this)(
j, i);
660template <
typename number>
668 const number
alpha = 1.;
670 const number
null = 0.;
681 const char diag =
'N';
682 const char trans =
'N';
721 std::lock_guard<std::mutex> lock(mutex);
730 svd_vt->values.
data(),
738 for (size_type i = 0; i < wr.
size(); ++i)
745 svd_u->values.
data(),
756 std::lock_guard<std::mutex> lock(mutex);
765 svd_u->values.
data(),
773 for (size_type i = 0; i < wr.
size(); ++i)
780 svd_vt->values.
data(),
796template <
typename number>
804 const number
alpha = 1.;
806 const number
null = 0.;
817 const char diag =
'N';
818 const char trans =
'T';
858 std::lock_guard<std::mutex> lock(mutex);
868 svd_u->values.
data(),
883 svd_vt->values.
data(),
894 std::lock_guard<std::mutex> lock(mutex);
904 svd_vt->values.
data(),
919 svd_u->values.
data(),
935template <
typename number>
945template <
typename number>
955template <
typename number>
970 const number
alpha = 1.;
990template <
typename number>
1004 const number
alpha = 1.;
1026template <
typename number>
1053 std::lock_guard<std::mutex> lock(mutex);
1055 work.resize(
kk *
nn);
1064 work[
j *
kk + i] =
V(i) *
B(i,
j);
1068 const number
alpha = 1.;
1077 this->values.
data(),
1088template <
typename number>
1097#ifdef DEAL_II_LAPACK_WITH_MKL
1098 const number
one = 1.;
1109template <
typename number>
1126template <
typename number>
1141 const number
alpha = 1.;
1151 this->values.
data(),
1172 this->values.
data(),
1184template <
typename number>
1198 const number
alpha = 1.;
1220template <
typename number>
1235 const number
alpha = 1.;
1245 this->values.
data(),
1266 this->values.
data(),
1278template <
typename number>
1292 const number
alpha = 1.;
1314template <
typename number>
1329 const number
alpha = 1.;
1338 this->values.
data(),
1349template <
typename number>
1363 const number
alpha = 1.;
1385template <
typename number>
1394 number *
const values = this->values.data();
1409template <
typename number>
1418template <
typename number>
1422 const char type(
'O');
1428template <
typename number>
1432 const char type(
'I');
1438template <
typename number>
1442 const char type(
'F');
1448template <
typename number>
1452 std::lock_guard<std::mutex> lock(mutex);
1456 ExcMessage(
"norms can be called in matrix state only."));
1460 const number *
const values = this->values.data();
1465 (type ==
'I' || type ==
'O') ? std::max<types::blas_int>(1,
N) : 0;
1473 (type ==
'I') ? std::max<types::blas_int>(1,
M) : 0;
1481template <
typename number>
1487 ExcMessage(
"Trace can be called in matrix state only."));
1491 for (
size_type i = 0; i < this->m(); ++i)
1492 tr += (*
this)(i, i);
1499template <
typename number>
1512 number *
const values = this->values.data();
1526template <
typename number>
1530 std::lock_guard<std::mutex> lock(mutex);
1535 const number * values = this->values.data();
1559template <
typename number>
1563 std::lock_guard<std::mutex> lock(mutex);
1569 const number *
const values = this->values.data();
1575 const char norm =
'1';
1576 const char diag =
'N';
1597template <
typename number>
1607 std::fill(wr.begin(), wr.end(), 0.);
1608 ipiv.resize(8 *
mm);
1610 svd_u = std::make_unique<LAPACKFullMatrix<number>>(
mm,
mm);
1611 svd_vt = std::make_unique<LAPACKFullMatrix<number>>(
nn,
nn);
1619 std::vector<typename numbers::NumberTraits<number>::real_type>
real_work;
1623 std::size_t min =
std::min(this->m(), this->n());
1624 std::size_t max =
std::max(this->m(), this->n());
1626 std::max(5 * min * min + 5 * min, 2 * max * min + 2 * min * min + min));
1674template <
typename number>
1688 wr[i] =
one / wr[i];
1697template <
typename number>
1700 const unsigned int kernel_size)
1708 const unsigned int n_wr = wr.
size();
1710 wr[i] =
one / wr[i];
1718template <
typename number>
1727 number *
const values = this->values.data();
1733 compute_lu_factorization();
1736 inv_work.resize(
mm);
1742 compute_cholesky_factorization();
1750 this->el(i,
j) = this->el(
j, i);
1761template <
typename number>
1769 const number *
const values = this->values.data();
1796 "The matrix has to be either factorized or triangular."));
1804template <
typename number>
1815 const number *
const values = this->values.data();
1864 "The matrix has to be either factorized or triangular."));
1872template <
typename number>
1896 for (
size_type i = 0; i < this->m(); ++i)
1898 (ipiv[i] ==
types::blas_int(i + 1) ? this->el(i, i) : -this->el(i, i));
1904template <
typename number>
1919 const char jobvr = (right) ?
V :
N;
1920 const char jobvl = (left) ?
V :
N;
1934 std::vector<typename numbers::NumberTraits<number>::real_type>
real_work;
1981 std::to_string(-
info) +
1983 " parameter had an illegal value."));
1990 "Lapack error in geev: the QR algorithm failed to compute "
1991 "all the eigenvalues, and no eigenvectors have been computed."));
2009 template <
typename RealNumber>
2012 const std::vector<RealNumber> & vr,
2013 const std::complex<RealNumber> & eigenvalue,
2015 unsigned int & index)
2017 const std::size_t n =
result.n();
2018 if (eigenvalue.imag() != 0.)
2020 for (std::size_t
j = 0;
j < n; ++
j)
2022 result(
j, index).real(vr[index * n +
j]);
2023 result(
j, index + 1).real(vr[index * n +
j]);
2024 result(
j, index).imag(vr[(index + 1) * n +
j]);
2025 result(
j, index + 1).imag(-vr[(index + 1) * n +
j]);
2034 for (
unsigned int j = 0;
j < n; ++
j)
2035 result(
j, index).real(vr[index * n +
j]);
2044 template <
typename ComplexNumber>
2047 const std::vector<ComplexNumber> &vr,
2050 unsigned int & index)
2052 const std::size_t n =
result.n();
2053 for (
unsigned int j = 0;
j < n; ++
j)
2063template <
typename number>
2069 ExcMessage(
"Right eigenvectors are not available! Did you "
2070 "set the associated flag in compute_eigenvalues()?"));
2075 for (
unsigned int i = 0; i < n();)
2083template <
typename number>
2089 ExcMessage(
"Left eigenvectors are not available! Did you "
2090 "set the associated flag in compute_eigenvalues()?"));
2095 for (
unsigned int i = 0; i < n();)
2103template <
typename number>
2106 const number lower_bound,
2107 const number upper_bound,
2123 const char *
const jobz(&
V);
2124 const char *
const uplo(&
U);
2125 const char *
const range(&
V);
2127 std::vector<types::blas_int> iwork(
static_cast<size_type>(5 *
nn));
2198 std::to_string(-
info) +
2200 " parameter had an illegal value."));
2206 "Lapack error in syevx: " + std::to_string(
info) +
2207 " eigenvectors failed to converge."
2208 " (You may need to scale the abs_accuracy according"
2209 " to your matrix norm.)"));
2214 ExcMessage(
"Lapack error in syevx: unknown error."));
2235template <
typename number>
2239 const number lower_bound,
2240 const number upper_bound,
2260 const char *
const jobz(&
V);
2261 const char *
const uplo(&
U);
2262 const char *
const range(&
V);
2343 std::to_string(-
info) +
2345 " parameter had an illegal value."));
2352 "Lapack error in sygvx: ssyevx/dsyevx failed to converge, and " +
2353 std::to_string(
info) +
2354 " eigenvectors failed to converge."
2355 " (You may need to scale the abs_accuracy"
2356 " according to the norms of matrices A and B.)"));
2362 "Lapack error in sygvx: the leading minor of order " +
2363 std::to_string(
info -
nn) +
2364 " of matrix B is not positive-definite."
2365 " The factorization of B could not be completed and"
2366 " no eigenvalues or eigenvectors were computed."));
2371 ExcMessage(
"Lapack error in sygvx: unknown error."));
2393template <
typename number>
2406 ExcMessage(
"eigenvectors.size() > matrix.n()"));
2418 const char *
const uplo = (&
U);
2473 std::to_string(-
info) +
2475 " parameter had an illegal value."));
2482 "Lapack error in sygv: ssyev/dsyev failed to converge, and " +
2483 std::to_string(
info) +
2484 " off-diagonal elements of an intermediate "
2485 " tridiagonal did not converge to zero."
2486 " (You may need to scale the abs_accuracy"
2487 " according to the norms of matrices A and B.)"));
2493 "Lapack error in sygv: the leading minor of order " +
2494 std::to_string(
info -
nn) +
2495 " of matrix B is not positive-definite."
2496 " The factorization of B could not be completed and"
2497 " no eigenvalues or eigenvectors were computed."));
2502 ExcMessage(
"Lapack error in sygv: unknown error."));
2519template <
typename number>
2522 const unsigned int precision,
2523 const bool scientific,
2524 const unsigned int width_,
2527 const double threshold)
const
2529 unsigned int width =
width_;
2539 std::ios::fmtflags
old_flags = out.flags();
2544 out.setf(std::ios::scientific, std::ios::floatfield);
2546 width = precision + 7;
2550 out.setf(std::ios::fixed, std::ios::floatfield);
2552 width = precision + 2;
2555 for (
size_type i = 0; i < this->m(); ++i)
2563 out << std::setw(width) << (*this)(i,
j) <<
' ';
2564 else if (
std::abs(this->el(i,
j)) > threshold)
2565 out << std::setw(width) << this->el(i,
j) *
denominator <<
' ';
2580template <
typename number>
2589template <
typename number>
2599template <
typename number>
2605 matrix->solve(dst,
false);
2609template <
typename number>
2615 matrix->solve(dst,
true);
2619template <
typename number>
2627 matrix->solve(*aux,
false);
2632template <
typename number>
2640 matrix->solve(*aux,
true);
2646#include "lapack_full_matrix.inst"
void omatcopy(char, char, ::types::blas_int, ::types::blas_int, const number1, const number2 *, ::types::blas_int, number3 *, ::types::blas_int)
value_type * data() const noexcept
LAPACKFullMatrix< number > & operator*=(const number factor)
number reciprocal_condition_number() const
void Tmmult(LAPACKFullMatrix< number > &C, const LAPACKFullMatrix< number > &B, const bool adding=false) const
void scale_rows(const Vector< number > &V)
FullMatrix< std::complex< typename numbers::NumberTraits< number >::real_type > > get_right_eigenvectors() const
void add(const number a, const LAPACKFullMatrix< number > &B)
void Tvmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void transpose(LAPACKFullMatrix< number > &B) const
void mTmult(LAPACKFullMatrix< number > &C, const LAPACKFullMatrix< number > &B, const bool adding=false) const
void compute_eigenvalues_symmetric(const number lower_bound, const number upper_bound, const number abs_accuracy, Vector< number > &eigenvalues, FullMatrix< number > &eigenvectors)
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void reinit(const size_type size)
std::make_unsigned< types::blas_int >::type size_type
void compute_cholesky_factorization()
LAPACKFullMatrix< number > & operator=(const LAPACKFullMatrix< number > &)
void compute_lu_factorization()
FullMatrix< std::complex< typename numbers::NumberTraits< number >::real_type > > get_left_eigenvectors() const
void print_formatted(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const unsigned int width=0, const char *zero_string=" ", const double denominator=1., const double threshold=0.) const
void grow_or_shrink(const size_type size)
void apply_givens_rotation(const std::array< number, 3 > &csr, const size_type i, const size_type k, const bool left=true)
void set_property(const LAPACKSupport::Property property)
number norm(const char type) const
void solve(Vector< number > &v, const bool transposed=false) const
void compute_eigenvalues(const bool right_eigenvectors=false, const bool left_eigenvectors=false)
number frobenius_norm() const
LAPACKFullMatrix(const size_type size=0)
void compute_inverse_svd(const double threshold=0.)
void compute_generalized_eigenvalues_symmetric(LAPACKFullMatrix< number > &B, const number lower_bound, const number upper_bound, const number abs_accuracy, Vector< number > &eigenvalues, std::vector< Vector< number > > &eigenvectors, const types::blas_int itype=1)
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
number linfty_norm() const
void TmTmult(LAPACKFullMatrix< number > &C, const LAPACKFullMatrix< number > &B, const bool adding=false) const
void compute_inverse_svd_with_kernel(const unsigned int kernel_size)
void Tvmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void rank1_update(const number a, const Vector< number > &v)
void remove_row_and_column(const size_type row, const size_type col)
LAPACKFullMatrix< number > & operator/=(const number factor)
number determinant() const
void mmult(LAPACKFullMatrix< number > &C, const LAPACKFullMatrix< number > &B, const bool adding=false) const
void vmult(Vector< number > &, const Vector< number > &) const
void initialize(const LAPACKFullMatrix< number > &)
void Tvmult(Vector< number > &, const Vector< number > &) const
Subscriptor & operator=(const Subscriptor &)
void reinit(const size_type size1, const size_type size2, const bool omit_default_initialization=false)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcErrorCode(std::string arg1, types::blas_int arg2)
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
static ::ExceptionBase & ExcProperty(Property arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcSingular()
#define AssertIsFinite(number)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcState(State arg1)
#define AssertThrow(cond, exc)
void getrs(const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, const ::types::blas_int *, number2 *, const ::types::blas_int *, ::types::blas_int *)
void syrk(const char *, const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, const number3 *, number4 *, const ::types::blas_int *)
void geev(const char *, const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, number2 *, number3 *, number4 *, const ::types::blas_int *, number5 *, const ::types::blas_int *, number6 *, const ::types::blas_int *, ::types::blas_int *)
void gemm(const char *, const char *, const ::types::blas_int *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, const number3 *, const ::types::blas_int *, const number4 *, number5 *, const ::types::blas_int *)
void pocon(const char *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, const number2 *, number3 *, number4 *, ::types::blas_int *, ::types::blas_int *)
void lascl(const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, const ::types::blas_int *, number3 *, const ::types::blas_int *, ::types::blas_int *)
void syr(const char *, const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, number3 *, const ::types::blas_int *)
void trtrs(const char *, const char *, const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *, ::types::blas_int *)
void syevx(const char *, const char *, const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, const number2 *, const number3 *, const ::types::blas_int *, const ::types::blas_int *, const number4 *, ::types::blas_int *, number5 *, number6 *, const ::types::blas_int *, number7 *, const ::types::blas_int *, ::types::blas_int *, ::types::blas_int *, ::types::blas_int *)
void trcon(const char *, const char *, const char *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, number3 *, ::types::blas_int *, ::types::blas_int *)
void gesdd(const char *, const ::types::blas_int *, const ::types::blas_int *, number1 *, const ::types::blas_int *, number2 *, number3 *, const ::types::blas_int *, number4 *, const ::types::blas_int *, number5 *, const ::types::blas_int *, ::types::blas_int *, ::types::blas_int *)
void axpy(const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, number3 *, const ::types::blas_int *)
void trmv(const char *, const char *, const char *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *)
void sygvx(const ::types::blas_int *, const char *, const char *, const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *, const number3 *, const number4 *, const ::types::blas_int *, const ::types::blas_int *, const number5 *, ::types::blas_int *, number6 *, number7 *, const ::types::blas_int *, number8 *, const ::types::blas_int *, ::types::blas_int *, ::types::blas_int *, ::types::blas_int *)
void gemv(const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const number2 *, const ::types::blas_int *, const number3 *, const ::types::blas_int *, const number4 *, number5 *, const ::types::blas_int *)
number1 lange(const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *)
void potrs(const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *, ::types::blas_int *)
void sygv(const ::types::blas_int *, const char *, const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *, number3 *, number4 *, const ::types::blas_int *, ::types::blas_int *)
void potri(const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, ::types::blas_int *)
number1 lansy(const char *, const char *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *)
void potrf(const char *, const ::types::blas_int *, number1 *, const ::types::blas_int *, ::types::blas_int *)
void getrf(const ::types::blas_int *, const ::types::blas_int *, number1 *, const ::types::blas_int *, ::types::blas_int *, ::types::blas_int *)
void getri(const ::types::blas_int *, number1 *, const ::types::blas_int *, const ::types::blas_int *, number2 *, const ::types::blas_int *, ::types::blas_int *)
@ cholesky
Contents is a Cholesky decomposition.
@ lu
Contents is an LU decomposition.
@ matrix
Contents is actually a matrix.
@ unusable
Contents is something useless.
@ inverse_matrix
Contents is the inverse of a matrix.
@ svd
Matrix contains singular value decomposition,.
@ inverse_svd
Matrix is the inverse of a singular value decomposition.
@ eigenvalues
Eigenvalue vector is filled.
@ symmetric
Matrix is symmetric.
@ upper_triangular
Matrix is upper triangular.
@ lower_triangular
Matrix is lower triangular.
@ general
No special properties.
static const types::blas_int one
std::array< NumberType, 3 > givens_rotation(const NumberType &x, const NumberType &y)
std::array< NumberType, 3 > hyperbolic_rotation(const NumberType &x, const NumberType &y)
void gesdd_helper(const char job, const types::blas_int n_rows, const types::blas_int n_cols, AlignedVector< T > &matrix, std::vector< T > &singular_values, AlignedVector< T > &left_vectors, AlignedVector< T > &right_vectors, std::vector< T > &real_work, std::vector< T > &, std::vector< types::blas_int > &integer_work, const types::blas_int work_flag, types::blas_int &info)
void geev_helper(const char vl, const char vr, AlignedVector< T > &matrix, const types::blas_int n_rows, std::vector< T > &real_part_eigenvalues, std::vector< T > &imag_part_eigenvalues, std::vector< T > &left_eigenvectors, std::vector< T > &right_eigenvectors, std::vector< T > &real_work, std::vector< T > &, const types::blas_int work_flag, types::blas_int &info)
bool is_nan(const double x)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
static bool equal(const T *p1, const T *p2)
static constexpr const number & conjugate(const number &x)
std::array< std::pair< Number, Tensor< 1, dim, Number > >, std::integral_constant< int, dim >::value > eigenvectors(const SymmetricTensor< 2, dim, Number > &T, const SymmetricTensorEigenvectorMethod method=SymmetricTensorEigenvectorMethod::ql_implicit_shifts)