Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. #ifndef MATRIX_DEF_H
  2. #define MATRIX_DEF_H
  3.  
  4. #include "matrix_test_def.h"
  5.  
  6. template<class T>
  7. class Matrix {
  8.     friend class matrix_test;
  9.  
  10. protected:
  11.     std::vector<std::vector<T>> data;
  12.  
  13. public:
  14.     // CONSTRUCTORS & DESTRUCTORS
  15.     Matrix() : data{ {T{}} } {}; // Implemented
  16.     Matrix(std::vector<std::vector<T>> _data) : data(_data) {}; // Implemented
  17.     Matrix(unsigned int const lines, unsigned int const cols) : data(lines, std::vector<T>(cols, T())) {}; // Implemented
  18.     template<class T2> Matrix(Matrix<T2> const& other) : data(other.data) {}; // Implemented
  19.  
  20.     // UTILITIES
  21.     unsigned int cols() const; // Implemented
  22.     unsigned int lines() const; // Implemented
  23.     std::string str() const;
  24.  
  25.     // OPERATORS
  26.     template<class T2> auto operator+(Matrix<T2> const& other) const; // Implemented
  27.     template<class T2> auto operator-(Matrix<T2> const& other) const; // Implemented
  28.     Matrix<T> operator-() const; // Implemented
  29.     template<class T2> bool operator==(Matrix<T2> const& other) const; // Implemented
  30.     template<class T2> Matrix<T> operator=(Matrix<T2> const& other); // Implemented
  31.     template<class T2> auto operator*(T2 const& other) const; // Implemented
  32.     auto operator*(T const& other) const; // Implemented
  33.     std::vector<T>& operator[](unsigned pos); // Implemented
  34.  
  35.     // MATHEMATICS
  36.     T det() const; // Implemented, tested
  37.     template<class T2> auto dot(Matrix<T2> const& other) const;  // Implemented, tested
  38.     Matrix<T> transp() const; // Implemented, tested
  39.     std::vector<T> diag() const; // Implemented, tested
  40.     Matrix<T> inv() const; // Implemented, tested
  41.     Matrix<T> tri_lo(bool include_diag = false) const; // Implemented, tested
  42.     Matrix<T> tri_up(bool include_diag = false) const; // Implemented, tested
  43.     T highest_eigenval_iteratedPower(std::vector<T> x0, T precision, unsigned long long maxiter) const; // Implemented, tested
  44.     T lowest_eigenval_invIteratedPower(std::vector<T> x0, T precision, unsigned long long maxiter) const; // Implemented, tested
  45.     Matrix<T> abs() const; // Implemented, tested
  46.     T norm() const; // Implemented
  47.     Matrix<T> adj() const; // Implemented, tested
  48.     T cofactor(unsigned int const line, unsigned int const col) const; // Implemented, tested
  49.     std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> decomp_PLU() const; // Implemented, tested
  50.     Matrix<T> decomp_cholesky() const; // Implemented
  51.     std::tuple<Matrix<T>, Matrix<T>> decomp_QR() const;
  52.     // TODO : ?? decomp_SVD() const;
  53.     bool isDiagonal() const; // Implemented
  54.     std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> diagonalize() const;
  55.     Matrix<T> eigenvects() const;
  56.     std::vector<T> eigenvals() const;  
  57.     T rank() const;
  58.     T trace() const; // Implemented
  59.     Matrix<T> pivot() const; // Implemented
  60.  
  61.     // GENERATORS
  62.     static Matrix<T> gen_random(unsigned int size, T min, T max); // Implemented
  63.     static Matrix<T> gen_random(unsigned int lines, unsigned int cols, T min, T max); // Implemented
  64.     static Matrix<T> gen_diag(unsigned int size, T value = T()); // Implemented
  65.     static Matrix<T> gen_diag(unsigned int lines, unsigned int cols, T value = T()); // Implemented
  66.     static Matrix<T> gen_diag(std::vector<T> values); // Implemented
  67.     static Matrix<T> gen_full(unsigned int size, T value = T()); // Implemented
  68.     static Matrix<T> gen_full(unsigned int lines, unsigned int cols, T value = T()); // Implemented
  69.     static Matrix<T> gen_col(std::vector<T> values); // Implemented
  70.     static Matrix<T> gen_line(std::vector<T> values); // Implemented
  71.  
  72.     // COMPARATORS
  73.     bool allclose(Matrix<T> other, T abs_precision, T rel_precision) const; // Implemented
  74.     static bool close(T lhs, T rhs, T abs_precision, T rel_precision); // Implemented
  75.     static bool allclose(std::vector<T> lhs, std::vector<T> rhs, T abs_precision, T rel_precision); // Implemented
  76.  
  77.     // SOLVERS
  78.     static Matrix<T> solve_descent(Matrix<T> A, Matrix<T> B);
  79.     static Matrix<T> solve_climb(Matrix<T> A, Matrix<T> B);
  80.  
  81.     // MISC
  82.     static void run_tests(); // Implemented
  83. };
  84.  
  85. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement