aboutsummaryrefslogtreecommitdiffstats
path: root/libprakpp/include/prakmatrix.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libprakpp/include/prakmatrix.hpp')
-rw-r--r--libprakpp/include/prakmatrix.hpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/libprakpp/include/prakmatrix.hpp b/libprakpp/include/prakmatrix.hpp
index f1ccddc..2f87401 100644
--- a/libprakpp/include/prakmatrix.hpp
+++ b/libprakpp/include/prakmatrix.hpp
@@ -2,6 +2,7 @@
#include "prakcommon.hpp"
+#include <iomanip>
#include <cstring>
#include <ostream>
#include <optional>
@@ -75,7 +76,7 @@ struct matrix : public std::vector<T> {
}
/// multiply matrix by a scalar
template <typename Arg>
- std::enable_if_t<std::is_arithmetic_v<Arg>, struct matrix<T>>::type
+ typename std::enable_if_t<std::is_arithmetic_v<Arg>, struct matrix<T>>::type
operator*(const Arg other) const {
struct matrix<T> ret(rows, cols);
for (size_t i = 0; i < this->size(); ++i)
@@ -161,12 +162,27 @@ struct matrix : public std::vector<T> {
}
return ret;
}
+
+ void add_row(size_t index, std::vector<T> row_data) {
+ ++rows;
+ this->resize(rows * cols);
+ memmove(this->data() + cols * (index+1), this->data() + cols * index, (rows - index - 1) * cols * sizeof (T));
+ for (size_t i = 0; i < cols; ++i)
+ this->operator[](index * cols + i) = row_data[i];
+ }
+ void add_column(size_t index, std::vector<T> column_data) {
+ this->reserve(rows * (cols + 1));
+ for (size_t i = 0; i < rows; ++i)
+ this->insert(this->begin() + (cols + 1) * i + index, column_data[i]);
+ ++cols;
+ }
std::ostream &print(std::ostream &out = std::cout, size_t width = 10) const {
+ std::cout.setf(std::ios::left);
for (size_t row = 0; row < rows; ++row) {
for (size_t col = 0; col < cols; ++col)
- out << "|" << std::setw(width) << SUBSCR_OPRTR(row, col);
- std::cout << "|\n";
+ out /*<< "|"*/ << std::setw(width) << SUBSCR_OPRTR(row, col);
+ std::cout << "\n";
}
return out;
}