15 explicit Storage(Eigen::MatrixXd value)
16 :
data(std::move(value)) {}
19 static constexpr const char* kNaIdError =
20 "matrix operation on na ID";
21 static constexpr const char* kInvalidSnapshotError =
22 "matrix restore from invalid snapshot";
24 std::shared_ptr<Storage> storage_;
27 : storage_(std::make_shared<Storage>(std::move(
data))) {}
29 [[nodiscard]] Storage& require_storage();
30 [[nodiscard]]
const Storage& require_storage()
const;
37 NumericMatrix(const NumericMatrix&) noexcept = default;
38 NumericMatrix& operator=(const NumericMatrix&) noexcept = default;
42 NumericMatrix(NumericMatrix&& other) noexcept : storage_(other.storage_) {}
43 NumericMatrix&
operator=(NumericMatrix&& other)
noexcept {
44 if (
this != &other) storage_ = other.storage_;
53 std::shared_ptr<Storage> identity_;
54 Eigen::MatrixXd state_;
56 Snapshot(std::shared_ptr<Storage> identity,
57 const Eigen::MatrixXd& state)
58 : identity_(std::move(identity)), state_(state) {}
70 static NumericMatrix
new_(
int rows,
int cols,
double init_val = 0.0);
76 std::vector<double>
row(
int idx)
const;
77 std::vector<double>
col(
int idx)
const;
82 void add_row(
int idx,
const std::vector<double>& values);
83 void add_col(
int idx,
const std::vector<double>& values);
92 NumericMatrix
copy()
const;
93 NumericMatrix
submatrix(
int from_row,
int to_row,
int from_col,
int to_col)
const;
97 void sort(
int column,
bool ascending =
true);
98 NumericMatrix
concat(
const NumericMatrix& other,
bool horizontal)
const;
108 NumericMatrix
diff(
const NumericMatrix& other)
const;
109 NumericMatrix
mult(
const NumericMatrix& other)
const;
110 NumericMatrix
pow(
int n)
const;
114 NumericMatrix
inv()
const;
122 NumericMatrix
kron(
const NumericMatrix& other)
const;
129 [[nodiscard]]
bool is_na() const noexcept {
return !storage_; }
147 const Eigen::MatrixXd&
data()
const {
return require_storage().data; }
148 Eigen::MatrixXd&
data() {
return require_storage().data; }
152 return matrix.is_na();
Snapshot & operator=(const Snapshot &)=default
Snapshot(Snapshot &&)=default
Snapshot(const Snapshot &)=default
Snapshot & operator=(Snapshot &&)=default
friend class NumericMatrix
NumericMatrix transpose() const
static NumericMatrix new_(int rows, int cols, double init_val=0.0)
NumericMatrix() noexcept=default
void swap_columns(int i, int j)
bool is_stochastic() const
bool is_na() const noexcept
std::vector< double > row(int idx) const
void add_row(int idx, const std::vector< double > &values)
NumericMatrix kron(const NumericMatrix &other) const
NumericMatrix & operator=(NumericMatrix &&other) noexcept
void add_col(int idx, const std::vector< double > &values)
NumericMatrix copy() const
NumericMatrix pow(int n) const
NumericMatrix inv() const
NumericMatrix eigenvectors() const
bool is_antidiagonal() const
bool is_symmetric() const
void set(int row, int col, double val)
std::vector< double > col(int idx) const
Snapshot snapshot() const
NumericMatrix pinv() const
void sort(int column, bool ascending=true)
void reshape(int rows, int cols)
void restore(const Snapshot &snapshot)
bool is_antisymmetric() const
void swap_rows(int i, int j)
NumericMatrix concat(const NumericMatrix &other, bool horizontal) const
NumericMatrix mult(const NumericMatrix &other) const
NumericMatrix submatrix(int from_row, int to_row, int from_col, int to_col) const
bool is_triangular() const
int elements_count() const
std::vector< double > eigenvalues() const
const Eigen::MatrixXd & data() const
NumericMatrix diff(const NumericMatrix &other) const
double get(int row, int col) const
bool is_na(const Line &h)