/* ___col___ / \ +---------+ \ | + + + + | | row - 第一维度 | + + + + | | +---------+ / */ #pragma once #include #include #include #include #include namespace qing { template class Matrx { public: Matrx(); Matrx(const uint64_t row, const uint64_t col); Matrx(const uint64_t row, const uint64_t col, const std::vector& src); const T& get(uint64_t row, uint64_t col) const; //-------------旧接口---------------- T& witch(uint64_t row, uint64_t col); //-------------新接口---------------- void set(uint64_t row, uint64_t col, T v); //----------------------------------- const std::vector& get_data() const; const uint64_t get_col() const; const uint64_t get_row() const; bool has_same_shape(const Matrx& other); bool has_dot_shape(const Matrx& other); void assert_same_shape(const Matrx& other); void assert_dot_shape(const Matrx& other); Matrx operator+(const Matrx& other); Matrx operator+(T& item); Matrx operator-(const Matrx& other); Matrx operator-(T& item); Matrx operator*(const Matrx& other); Matrx operator*(T& item); Matrx operator/(T& item); Matrx operator/(const Matrx& other); Matrx dot(const Matrx& other); void save(std::ostream& out) { out << row << " " << col; for (const auto& item : arr) { out << " "; out << item; } } private: uint64_t row, col; std::vector arr; }; }