24#include <boost/numeric/conversion/converter.hpp>
37template <
typename _Scalar>
87 if (this->cols() != this->rows()) {
88 throw std::invalid_argument(
"SquareMatrix::SquareMatrix(const MatrixX<Scalar>&): The given matrix is not square.");
100 template <
typename DerivedExpression>
120 size_t column_index = 0;
121 size_t row_index = column_index + 1;
122 for (
size_t vector_index = 0; vector_index < v.size(); vector_index++) {
123 A(row_index, column_index) = v(vector_index);
125 if (row_index == dim - 1) {
127 row_index = column_index + 1;
156 for (
const auto& index : indices) {
158 throw std::invalid_argument(
"SquareMatrix::PartitionMatrix(std::vector<size_t>, size_t): index is larger than matrix dimension");
177 std::vector<size_t> l(range);
178 std::iota(std::begin(l), std::end(l), start);
205 return A_random + A_random.adjoint();
220 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>> unitary_solver {A_symmetric};
222 return unitary_solver.eigenvectors();
238 for (
size_t i = 0; i < dim; i++) {
239 for (
size_t j = i; j < dim; j++) {
262 double D = 1 + 8 * v.size();
263 double dim = (1 + std::sqrt(D)) / 2;
268 for (
size_t i = 0; i < dim; i++) {
269 for (
size_t j = i; j < dim; j++) {
299 size_t dimension()
const {
return static_cast<size_t>(this->cols()); }
305 bool isSelfAdjoint(
const double threshold = 1.0e-08)
const {
return (*this).adjoint().isApprox(*
this, threshold); }
317 bool isAntiHermitian(
const double threshold = 1.0e-08)
const {
return (*this).adjoint().isApprox(-*
this, threshold); }
323 bool isSymmetric(
const double threshold = 1.0e-08)
const {
return (*this).transpose().isApprox(*
this, threshold); }
343 for (
size_t i = 0; i < M; i++) {
347 for (
size_t k = i; k < M; k++) {
351 for (
size_t j = 0; j < i; j++) {
352 sum += (L(i, j) * U(j, k));
361 for (
size_t k = i; k < M; k++) {
368 for (
size_t j = 0; j < i; j++) {
369 sum += (L(k, j) * U(j, i));
373 L(k, i) = (this->
operator()(k, i) - sum) / U(i, i);
380 if (A.isApprox(*
this)) {
381 return std::array<Self, 2>({L, U});
383 throw std::runtime_error(
"SquareMatrix<Scalar>::noPivotLUDecompose(): The decomposition was not stable");
407 size_t vector_index = 0;
408 for (
size_t q = 0; q < dim; q++) {
409 for (
size_t p = q + 1; p < dim; p++) {
429 if ((this->rows() == 1) && (this->cols() == 1)) {
435 for (
size_t i = 0; i < this->rows(); i++) {
454 size_t number_of_submatrices = boost::numeric::converter<size_t, double>::convert(std::pow(2, n));
455 for (
size_t S = 1; S < number_of_submatrices; S++) {
459 size_t k = __builtin_popcountll(gray_code_value);
463 while (gray_code_value != 0) {
464 size_t index = __builtin_ctzll(gray_code_value);
466 X.col(j) = this->col(index);
468 gray_code_value ^= gray_code_value & -gray_code_value;
474 double product_of_rowsums = X.array().rowwise().sum().prod();
477 int sign = std::pow(-1, t);
478 value += sign * product_of_rowsums;
Definition: Matrix.hpp:47
enable_if_t< Self::is_vector &&(Rows==3), Z > operator()(const CartesianDirection direction) const
Definition: Matrix.hpp:275
enable_if_t< Self::is_matrix, Z > calculateMinor(size_t i, size_t j) const
Definition: Matrix.hpp:308
Definition: SquareMatrix.hpp:39
static Self PartitionMatrix(const std::vector< size_t > &indices, const size_t M)
Definition: SquareMatrix.hpp:152
bool isSelfAdjoint(const double threshold=1.0e-08) const
Definition: SquareMatrix.hpp:305
SquareMatrix(const MatrixX< Scalar > &M)
Definition: SquareMatrix.hpp:83
bool isSymmetric(const double threshold=1.0e-08) const
Definition: SquareMatrix.hpp:323
size_t dimension() const
Definition: SquareMatrix.hpp:299
SquareMatrix(const size_t dim)
Definition: SquareMatrix.hpp:65
static Self Random(const size_t dim)
Definition: SquareMatrix.hpp:191
SquareMatrix(const size_t rows, const size_t cols)
Definition: SquareMatrix.hpp:74
static Self RandomUnitary(const size_t dim)
Definition: SquareMatrix.hpp:216
bool isHermitian(const double threshold=1.0e-08) const
Definition: SquareMatrix.hpp:311
static Self Identity(const size_t dim)
Definition: SquareMatrix.hpp:143
SquareMatrix(const Eigen::MatrixBase< DerivedExpression > &expression)
Definition: SquareMatrix.hpp:101
_Scalar Scalar
Definition: SquareMatrix.hpp:42
std::array< Self, 2 > noPivotLUDecompose() const
Definition: SquareMatrix.hpp:335
static Self SymmetricFromUpperTriangleWithoutDiagonal(const VectorX< Scalar > &v)
Definition: SquareMatrix.hpp:260
double calculatePermanentCombinatorial() const
Definition: SquareMatrix.hpp:426
static Self Zero(const size_t dim)
Definition: SquareMatrix.hpp:289
SquareMatrix()
Definition: SquareMatrix.hpp:56
static Self SymmetricFromUpperTriangle(const VectorX< Scalar > &v)
Definition: SquareMatrix.hpp:231
double calculatePermanentRyser() const
Definition: SquareMatrix.hpp:448
VectorX< Scalar > pairWiseStrictReduced() const
Definition: SquareMatrix.hpp:401
static Self FromStrictTriangle(const VectorX< Scalar > &v)
Definition: SquareMatrix.hpp:115
static Self RandomSymmetric(const size_t dim)
Definition: SquareMatrix.hpp:201
static Self PartitionMatrix(const size_t start, const size_t range, const size_t M)
Definition: SquareMatrix.hpp:175
bool isAntiHermitian(const double threshold=1.0e-08) const
Definition: SquareMatrix.hpp:317
Definition: BaseOneElectronIntegralBuffer.hpp:25
size_t strictTriangularRootOf(const size_t x)
Definition: miscellaneous.cpp:226
size_t triangularRootOf(const size_t x)
Definition: miscellaneous.cpp:237
size_t grayCodeOf(const size_t S)
Definition: miscellaneous.cpp:165