4#include <gsl/gsl_matrix.h>
5#include <gsl/gsl_linalg.h>
6#include <gsl/gsl_eigen.h>
13#include "../special/special_generic.h"
98 return { gsl_eigen_symmv_alloc(n), &gsl_eigen_symmv_free };
160 RealMatrix(std::vector<double> data_, std::size_t rows, std::size_t cols);
170 RealMatrix(std::vector<std::vector<double>> data_);
178 RealMatrix(std::size_t rows, std::size_t cols);
193 double& at(
size_t i,
size_t j);
204 double& unchecked_at(
size_t i,
size_t j);
215 const double& at(
size_t i,
size_t j)
const;
226 const double& unchecked_at(
size_t i,
size_t j)
const;
231 std::size_t rows()
const;
236 std::size_t cols()
const;
252 void remove_row(std::size_t row_idx);
264 void remove_column(std::size_t col_idx);
278 void remove_row_and_column(std::size_t dim_idx);
290 static RealMatrix from_gsl_copy(
const gsl_matrix* A);
310 bool is_symmetric()
const;
472 std::vector<double> data;
473 std::size_t rows_, cols_;
561template<
typename... Ms>
563 return block_diag(std::vector<RealMatrix>{ms...});
std::ostream & operator<<(std::ostream &os, BinnedObservableId const &id)
Streams a human-readable binned observable identifier.
std::shared_ptr< Parameter > & operator+=(std::shared_ptr< Parameter > &lhs, const std::shared_ptr< Parameter > &rhs)
Adds the payload of one shared parameter into another.
gsl_vector_sptr make_gsl_vector(size_t size)
Allocates a GSL vector with automatic RAII destruction.
RealMatrix nearest_psd(RealMatrix R, double thr=1e-12)
Projects a matrix to the nearest positive semi-definite correlation-like matrix.
gsl_permutation_sptr make_gsl_permutation(size_t size)
Allocates a GSL permutation with automatic RAII destruction.
std::unique_ptr< gsl_matrix, decltype(&gsl_matrix_free)> gsl_matrix_sptr
Owning smart pointer for a GSL matrix.
std::unique_ptr< gsl_vector, decltype(&gsl_vector_free)> gsl_vector_sptr
Owning smart pointer for a GSL vector.
RealMatrix eye(std::size_t n)
Returns the identity matrix of size n.
RealMatrix diag(const gsl_vector *X)
Builds a diagonal matrix from a GSL vector.
RealMatrix cholesky_L(RealMatrix R)
Returns the lower-triangular Cholesky factor of a PSD matrix.
RealMatrix block_diag(const std::vector< RealMatrix > &blocks)
Builds a block-diagonal matrix from several square blocks.
gsl_eigen_workspace_sptr make_eigen_workspace(size_t n)
Allocates a GSL symmetric eigensolver workspace with RAII destruction.
gsl_matrix_sptr make_gsl_matrix(size_t rows, size_t cols)
Allocates a GSL matrix with automatic RAII destruction.
std::unique_ptr< gsl_eigen_symmv_workspace, decltype(&gsl_eigen_symmv_free)> gsl_eigen_workspace_sptr
Owning smart pointer for a GSL symmetric-eigensystem workspace.
std::unique_ptr< gsl_permutation, decltype(&gsl_permutation_free)> gsl_permutation_sptr
Owning smart pointer for a GSL permutation.
friend RealMatrix operator*(double scalar, RealMatrix rhs)
Left scalar multiplication.
friend RealMatrix operator*(RealMatrix lhs, const RealMatrix &rhs)
Matrix product.
friend RealMatrix operator/(RealMatrix lhs, double scalar)
Scalar division.
RealMatrix()
Constructs an empty 0×0 matrix.
friend RealMatrix operator+(RealMatrix lhs, const RealMatrix &rhs)
Matrix addition.
friend RealMatrix operator*(RealMatrix lhs, double scalar)
Right scalar multiplication.
friend RealMatrix operator-(RealMatrix lhs, const RealMatrix &rhs)
Matrix subtraction.
scalar_t operator-(scalar_t lhs, const scalar_t &rhs)
Container for an eigendecomposition.
RealMatrix P
Diagonal matrix of eigenvalues.
Signed logarithmic determinant representation.
int sign
Natural logarithm of the absolute determinant.