Lines Matching refs:Matrix
1 //===------ Math.h - PBQP Vector and Matrix classes -------------*- C++ -*-===//
162 /// \brief PBQP Matrix class
163 class Matrix {
165 friend hash_code hash_value(const Matrix &);
168 /// \brief Construct a PBQP Matrix with the given dimensions.
169 Matrix(unsigned Rows, unsigned Cols) :
173 /// \brief Construct a PBQP Matrix with the given dimensions and initial
175 Matrix(unsigned Rows, unsigned Cols, PBQPNum InitVal)
180 /// \brief Copy construct a PBQP matrix.
181 Matrix(const Matrix &M)
186 /// \brief Move construct a PBQP matrix.
187 Matrix(Matrix &&M)
193 /// \brief Destroy this matrix, return its memory.
194 ~Matrix() { delete[] Data; }
197 Matrix& operator=(const Matrix &M) {
206 Matrix& operator=(Matrix &&M) {
217 bool operator==(const Matrix &M) const {
218 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
224 /// \brief Return the number of rows in this matrix.
226 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
230 /// \brief Return the number of cols in this matrix.
232 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
236 /// \brief Matrix element access.
238 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
243 /// \brief Matrix element access.
245 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
252 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
261 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
268 /// \brief Reset the matrix to the given value.
269 Matrix& reset(PBQPNum Val = 0) {
270 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
275 /// \brief Set a single row of this matrix to the given value.
276 Matrix& setRow(unsigned R, PBQPNum Val) {
277 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
283 /// \brief Set a single column of this matrix to the given value.
284 Matrix& setCol(unsigned C, PBQPNum Val) {
285 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
292 /// \brief Matrix transpose.
293 Matrix transpose() const {
294 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
295 Matrix M(Cols, Rows);
302 /// \brief Returns the diagonal of the matrix as a vector.
304 /// Matrix must be square.
306 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
307 assert(Rows == Cols && "Attempt to diagonalize non-square matrix.");
314 /// \brief Add the given matrix to this one.
315 Matrix& operator+=(const Matrix &M) {
316 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
318 "Matrix dimensions mismatch.");
324 Matrix operator+(const Matrix &M) {
325 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
326 Matrix Tmp(*this);
333 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
340 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
349 Matrix& subFromRow(unsigned R, PBQPNum Val) {
350 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
359 Matrix& subFromCol(unsigned C, PBQPNum Val) {
360 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
366 /// \brief Returns true if this is a zero matrix.
368 assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
379 /// \brief Return a hash_code for the given matrix.
380 inline hash_code hash_value(const Matrix &M) {
386 /// \brief Output a textual representation of the given matrix on the given
389 OStream& operator<<(OStream &OS, const Matrix &M) {
390 assert((M.getRows() != 0) && "Zero-row matrix badness.");
412 class MDMatrix : public Matrix {
414 MDMatrix(const Matrix &m) : Matrix(m), md(*this) { }
415 MDMatrix(Matrix &&m) : Matrix(std::move(m)), md(*this) { }
423 return hash_value(static_cast<const Matrix&>(M));