LU and LU inverse is done
This commit is contained in:
+17
-1
@@ -45,7 +45,7 @@ public:
|
||||
return !(*this == A);
|
||||
}
|
||||
bool nearly_equal(const Matrix<T>& A, T tol = static_cast<T>(1e-9)) const {
|
||||
if (rows_ != A.rows_ || cols_ != A.cols_) return false;
|
||||
if (rows_ != A.rows() || cols_ != A.cols()) return false;
|
||||
for (uint64_t i = 0; i < rows_; ++i)
|
||||
for (uint64_t j = 0; j < cols_; ++j) {
|
||||
T a = (*this)(i,j);
|
||||
@@ -59,6 +59,22 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void eye(uint64_t rows_cols){
|
||||
rows_ = cols_ = rows_cols;
|
||||
|
||||
data_.clear();
|
||||
data_.resize(rows_cols*rows_cols, T{0});
|
||||
for (uint64_t i = 0; i < rows_; ++i){
|
||||
data_[i * cols_ + i] = T{1};
|
||||
}
|
||||
}
|
||||
|
||||
void resize(uint64_t rows, uint64_t cols, const T& value = T(0)){
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
data_.resize(rows_*cols_, value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//# MATRIX: row helpers (copy out) #
|
||||
|
||||
+27
-2
@@ -27,6 +27,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
|
||||
//##########################################################
|
||||
//# VECTOR: --- basic properties --- #
|
||||
//##########################################################
|
||||
@@ -399,13 +400,37 @@ public:
|
||||
void print() const{
|
||||
std::cout << *this << std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool nearly_equal(const Vector<T>& a, T tol = static_cast<T>(1e-9)) const {
|
||||
if (v.size() != a.size()){
|
||||
return false;
|
||||
}
|
||||
for (uint64_t i = 0; i < v.size(); ++i){
|
||||
T val1 = v[i];
|
||||
T val2 = a[i];
|
||||
if (std::is_floating_point<T>::value) {
|
||||
if (std::fabs(val1 - val2) > tol) return false;
|
||||
} else {
|
||||
if (val1 != val2) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
typedef Vector<int> Vi;
|
||||
typedef Vector<float> Vf;
|
||||
typedef Vector<double> Vd;
|
||||
|
||||
|
||||
/*
|
||||
if (std::is_floating_point<T>::value) {
|
||||
if (std::fabs(a - b) > tol) return false;
|
||||
} else {
|
||||
if (a != b) return false;
|
||||
}*/
|
||||
} // namespace utils
|
||||
|
||||
#endif // _vector_n_
|
||||
Reference in New Issue
Block a user