1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_MATRIX_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_MATRIX_H
3#include <molpro/linalg/scalar_traits.h>
48 throw std::runtime_error(
"data buffer is of the wrong size");
53 throw std::runtime_error(
"data buffer is of the wrong size");
71 std::vector<T>&&
data() && {
86 throw std::out_of_range(
"index is larger than size");
148 throw std::runtime_error(
"row is out of range");
156 throw std::runtime_error(
"column is out of range");
187 throw std::runtime_error(
"specified incorrect corners");
188 if (
upl.first < 0 ||
upl.second < 0)
189 throw std::runtime_error(
"slice is out of range");
191 throw std::runtime_error(
"slice is out of range");
201 throw std::runtime_error(
"attempting to copy slices of different dimensions");
215 throw std::runtime_error(
"attempting to copy slices of different dimensions");
246 *
this =
right.m_slice;
251 *
this =
right.slice({0, 0},
right.dimensions());
284template <
class ML,
class MR>
287 for (
size_t i = 0;
i <
ml.rows(); ++
i)
288 for (
size_t j = 0;
j <
ml.cols(); ++
j)
298template <
class ML,
class MR>
301 for (
size_t i = 0;
i <
ml.rows(); ++
i)
302 for (
size_t j = 0;
j <
ml.cols(); ++
j)
308 auto s = std::stringstream{};
309 s << std::setprecision(precision);
310 auto dims =
m.dimensions();
311 if (
dims.first *
dims.second != 0) {
313 for (
size_t i = 0;
i <
dims.first; ++
i) {
315 for (
size_t j = 0;
j <
dims.second; ++
j) {
317 if (
j !=
dims.second - 1)
321 if (
i !=
dims.first - 1)
334struct std::formatter<
molpro::linalg::itsolv::subspace::Matrix<T>> : std::formatter<std::string_view> {
335 using Base = std::formatter<std::string_view>;
337 std::size_t precision = 6;
339 constexpr auto parse(std::format_parse_context &ctx) {
340 auto it = ctx.begin();
342 if (it == ctx.end()) {
347 return Base::parse(ctx);
352 if (it == ctx.end() || ( *it <
'0' && *it >
'9' )) {
353 throw std::format_error(
"Format string uses precision quantifier '.' without giving a (numeric) precision");
359 while (it != ctx.end() && ( *it >=
'0' && *it <=
'9' )) {
361 precision += *it -
'0';
367 return Base::parse(ctx);
373 return Base::format(tmp, ctx);
Constant slice that cannot be assigned to.
Definition Matrix.h:266
CSlice(CSlice &&) noexcept=default
Slice m_slice
Definition Matrix.h:280
CSlice(const Matrix< T > &matrix, coord_type upper_left, coord_type bottom_right)
Definition Matrix.h:270
CSlice(const CSlice &)=delete
Proxy mapping to a rectangular slice of the matrix data. Implements simple assignment.
Definition Matrix.h:182
coord_type upl
upper left corner
Definition Matrix.h:261
Slice & operator=(const CSlice &right)
Definition Matrix.h:245
Slice(Slice &&) noexcept=default
coord_type dimensions() const
Definition Matrix.h:255
Matrix< T > & mat
matrix being sliced
Definition Matrix.h:260
Slice & fill(T a)
Fill all elements of the slice with new values.
Definition Matrix.h:238
Slice(Matrix< T > &matrix, coord_type upper_left, coord_type bottom_right)
Definition Matrix.h:184
Slice(const Slice &)=delete
size_t rows() const
Definition Matrix.h:256
T operator()(size_t i, size_t j) const
Definition Matrix.h:211
T & operator()(size_t i, size_t j)
Definition Matrix.h:210
coord_type btr
bottom right corner
Definition Matrix.h:262
Slice & operator=(const Matrix< T > &right)
Definition Matrix.h:250
size_t cols() const
Definition Matrix.h:257
Slice & axpy(T a, const CSlice &x)
Definition Matrix.h:224
Slice & scal(T a)
Scale all elements of the slice.
Definition Matrix.h:230
Slice & axpy(T a, const Slice &x)
Definition Matrix.h:213
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition Matrix.h:32
Matrix(const std::vector< T > &data, coord_type dims)
Definition Matrix.h:50
index_type m_rows
number of rows
Definition Matrix.h:175
Slice slice()
Access the whole matrix as a slice.
Definition Matrix.h:106
T operator()(index_type i, index_type j) const
Access element.
Definition Matrix.h:66
Slice row(size_t i)
Access row slice.
Definition Matrix.h:122
T value_type
Definition Matrix.h:38
Slice col(size_t j)
Access column slice.
Definition Matrix.h:126
std::pair< size_t, size_t > coord_type
Definition Matrix.h:40
void remove_row(index_type row)
removes a row from the matrix
Definition Matrix.h:146
Slice slice(coord_type upper_left, coord_type bottom_right)
Access a rectangular slice of the matrix.
Definition Matrix.h:101
std::vector< T > m_buffer
data buffer
Definition Matrix.h:177
void remove_row_col(index_type row, index_type col)
removes row and column
Definition Matrix.h:164
CSlice row(size_t i) const
Definition Matrix.h:123
Matrix(const Matrix< T > &)=default
CSlice col(size_t j) const
Definition Matrix.h:127
CSlice slice(coord_type upper_left, coord_type bottom_right) const
Access a constant rectangular slice of the matrix.
Definition Matrix.h:114
const std::vector< T > & data() const &
Access the underlying data buffer.
Definition Matrix.h:69
void clear()
Clears all elements and sets dimensions to 0.
Definition Matrix.h:81
void remove_col(index_type col)
removes a column from the matrix
Definition Matrix.h:154
coord_type dimensions() const
Definition Matrix.h:171
Matrix(coord_type dims)
Definition Matrix.h:43
size_t size() const
Definition Matrix.h:172
bool empty() const
Returns true if matrix is empty.
Definition Matrix.h:78
Matrix(std::vector< T > &&data, coord_type dims)
Construct a matrix by taking ownership of an existing data buffer which must be of correct size.
Definition Matrix.h:45
void fill(T value)
Sets all elements of matrix to value.
Definition Matrix.h:93
Matrix(Matrix< T > &&) noexcept=default
void resize(const coord_type &dims)
Resize the matrix. The old data is preserved and any new rows/cols are zeroed.
Definition Matrix.h:130
CSlice slice() const
Access the whole matrix as a slice.
Definition Matrix.h:119
index_type rows() const
Definition Matrix.h:169
coord_type to_coord(size_t ind) const
Converts index of 1D data to matrix coordinate.
Definition Matrix.h:84
size_t index_type
Definition Matrix.h:39
index_type cols() const
Definition Matrix.h:170
std::vector< T > && data() &&
Access the raw data buffer of an r-value matrix. The matrix is left empty.
Definition Matrix.h:71
index_type m_cols
number of columns
Definition Matrix.h:176
std::string as_string(const Mat &m, int precision=6)
Definition Matrix.h:307
void transpose_copy(ML &&ml, const MR &mr)
Definition Matrix.h:285
void conjugate_transpose_copy(ML &&ml, const MR &mr)
Copies the conjugate transpose of mr into ml.
Definition Matrix.h:299
std::unique_ptr< LinearEigensystem< R, Q, P > > create_LinearEigensystem(const LinearEigensystemOptions &options, const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers=std::make_shared< molpro::linalg::itsolv::ArrayHandlers< R, Q, P > >())
Definition SolverFactory.h:111
T conjugate(const T &x)
Complex conjugate, staying within the scalar type; the identity for a real type.
Definition scalar_traits.h:47