daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 62 in 151 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iterator>
  3. #include <thread>
  4. #include <vector>
  5.  
  6. class DenseMat {
  7.  public:
  8.   explicit DenseMat(int32_t rows = 0, int32_t cols = 0)
  9.       : rows_(rows), cols_(cols) {
  10.     matrix_.resize(rows);
  11.     for (size_t i = 0; i < matrix_.size(); ++i) matrix_[i].resize(cols);
  12.   }
  13.  
  14.   DenseMat(int32_t rows, int32_t cols, const std::vector<int32_t>& data)
  15.       : DenseMat(rows, cols) {
  16.     auto it = begin(data);
  17.     for (size_t i = 0; i < rows; ++i)
  18.       for (size_t j = 0; j < cols; ++j) {
  19.         matrix_[i][j] = *it;
  20.         it++;
  21.       }
  22.   }
  23.  
  24.   int32_t Rows() const { return rows_; }
  25.  
  26.   int32_t Cols() const { return cols_; }
  27.  
  28.   const int32_t& operator()(int row, int col) const {
  29.     return matrix_[row][col];
  30.   }
  31.  
  32.   int32_t& operator()(int row, int col) { return matrix_[row][col]; }
  33.  
  34.   bool operator==(const DenseMat& other) const {
  35.     if (Rows() != other.Rows() && Cols() != other.Cols()) return false;
  36.     for (size_t i = 0; i < Rows(); ++i)
  37.       for (size_t j = 0; j < Cols(); ++j)
  38.         if (matrix_[i][j] != other.matrix_[i][j]) return false;
  39.     return true;
  40.   }
  41.  
  42.   bool operator!=(const DenseMat& other) const {
  43.     if (*this == other) return false;
  44.     return true;
  45.   }
  46.  
  47.  private:
  48.   int32_t rows_, cols_;
  49.   std::vector<std::vector<int32_t>> matrix_;
  50. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top