⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.hpp

📁 一个gps小工具包
💻 HPP
📖 第 1 页 / 共 2 页
字号:
         /// the size of the slice      size_t size() const { return s; }         /// the number of columns in the slice      size_t cols() const { return colSize(); }         /// the number of rows in the slice      size_t rows() const { return rowSize(); }         /// the (i,j) element of the slice, const.      T operator() (size_t i, size_t j) const          { return (*m)(i * rowStride() + rowStart(),                        j * colStride() + colStart()); }         /// returns the number of rows in this slice      size_t rowSize() const { return rSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t rowStart() const{ return rSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t rowStride() const { return rSlice.stride(); }         /// returns the number of columns in this slice      size_t colSize() const { return cSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t colStart() const { return cSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t colStride() const { return cSlice.stride(); }   private:         /// the matrix this slice refers to.      const Matrix<T>* m;      std::slice rSlice, ///< the row slice         cSlice; ///< the column slice      size_t s; ///< the size of the slice   };/** * an assignable single column slice of a matrix */   template <class T>   class MatrixColSlice : public RefMatrixSliceBase<T, MatrixColSlice<T> >   {   public:         /// default constructor      MatrixColSlice() : m(NULL), c(0), rSlice(std::slice(0,0,0)) {}         /// makes a slice of the column \c col from matrix \c mat.      MatrixColSlice(Matrix<T>& mat, size_t col)            : m(&mat), c(col), rSlice(std::slice(0,mat.rows(),1))         {             matSliceCheck(mat.rows(), mat.cols());          }         /// makes a slice of the column from the matrix using \c s to         /// further slice the column.      MatrixColSlice(Matrix<T>& mat, size_t col, const std::slice& s)            : m(&mat), c(col), rSlice(s)         {                // decide if the input is reasonable            matSliceCheck(mat.rows(), mat.cols());         }         /// assigns this column to x      template <class V>      MatrixColSlice& operator=(const ConstMatrixBase<T, V>& x)         { return assignFrom(x); }         /// assigns this column to x      template <class V>      MatrixColSlice& operator=(const ConstVectorBase<T, V>& x)         { return assignFrom(x); }         /// assigns this column to x      MatrixColSlice& operator=(const std::valarray<T>& x)         { return assignFrom(x); }         /// assigns this column to x      MatrixColSlice& operator=(const T x)         { return assignFrom(x); }         /// assigns this column to x      MatrixColSlice& operator=(const T* x)         { return assignFrom(x); }         /// returns the i'th element of the column, non-const      T& operator[] (size_t i)          { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the i'th element of the column, non-const      T& operator() (size_t i)          { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the i'th element of the column, const      T operator[] (size_t i) const         { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the i'th element of the column, const      T operator() (size_t i) const         { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the (i,j) element, non-const      T& operator() (size_t i, size_t j)          { return (*m)(rowStart() + i * rowStride(), j + c); }         /// returns the (i,j) element, non-const      T operator() (size_t i, size_t j) const         { return (*m)(rowStart() + i * rowStride(), j + c); }         /// returns the number of rows in the slice      size_t rows() const {return size();}         /// returns the number of columns in the slice      size_t cols() const {return 1;}         /// returns the size of the slice      size_t size() const {return rowSize();}         /// returns the number of rows in this slice      size_t rowSize() const { return rSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t rowStart() const{ return rSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t rowStride() const { return rSlice.stride(); }         /// returns the number of columns in this slice      size_t colSize() const { return 1; }         /// returns the starting row in the base matrix of this slice      size_t colStart() const { return c; }         /// returns the number of elements between the i'th and i+1'th row      size_t colStride() const { return 1; }   private:         /// the matrix this slice refers to.      Matrix<T>* m;         /// the column this slice is for      size_t c;         /// slice down the rows      std::slice rSlice;   };/** * a constant slice of a single column from a matrix. */   template <class T>   class ConstMatrixColSlice : public ConstMatrixSliceBase<T, ConstMatrixColSlice<T> >   {   public:         /// default constructor      ConstMatrixColSlice()             : m(NULL), c(0), rSlice(std::slice(0,0,0))          {}         /// constructor taking a slice of column \c col from the matrix.      ConstMatrixColSlice(const Matrix<T>& mat, size_t col)            : m(&mat), c(col), rSlice(std::slice(0,mat.rows(),1))         { matSliceCheck(mat.rows(), mat.cols()); }         /// constructor taking a slice of column \c col from the matrix,         /// slicing the column by \c s.      ConstMatrixColSlice(const Matrix<T>& mat, size_t col,                        const std::slice& s)            : m(&mat), c(col), rSlice(s)         {                // decide if the input is reasonable            matSliceCheck(mat.rows(), mat.cols());         }         /// returns the i'th element of the column slice      T operator[] (size_t i) const         { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the i'th element of the column slice      T operator() (size_t i) const         { return (*m)(rowStart() + i * rowStride(), c); }         /// returns the (i,j) element of the column slice      T operator() (size_t i, size_t j) const         { return (*m)(rowStart() + i * rowStride(), j + c); }         /// returns the size of the slice in rows      size_t rows() const {return rowSize();}         /// returns the size of the slice in columns      size_t cols() const {return 1;}         /// returns the overall size of the slice      size_t size() const {return rowSize();}         /// returns the number of rows in this slice      size_t rowSize() const { return rSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t rowStart() const{ return rSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t rowStride() const { return rSlice.stride(); }         /// returns the number of columns in this slice      size_t colSize() const { return 1; }         /// returns the starting row in the base matrix of this slice      size_t colStart() const { return c; }         /// returns the number of elements between the i'th and i+1'th row      size_t colStride() const { return 1; }   private:         /// the matrix this slice refers to      const Matrix<T>* m;         /// the column this slice refers to      size_t c;         /// a slice down the rows      std::slice rSlice;   };/** * an assignable single row slice of a matrix */   template <class T>   class MatrixRowSlice : public RefMatrixSliceBase<T, MatrixRowSlice<T> >   {   public:         /// default constructor      MatrixRowSlice()             : m(NULL), r(0), cSlice(std::slice(0,0,0))          {}         /// makes a slice of row \c row from the matrix.      MatrixRowSlice(Matrix<T>& mat, size_t row)            : m(&mat), r(row), cSlice(std::slice(0,mat.cols(),1))         { matSliceCheck(mat.rows(), mat.cols()); }         /// makes a slice of row \c row from the matrix, slicing it by \c s.      MatrixRowSlice(Matrix<T>& mat, size_t row,                   const std::slice& s)            : m(&mat), r(row), cSlice(s)         {                // decide if the input is reasonable            matSliceCheck(mat.rows(), mat.cols());         }            /// assigns this row to x.      template <class V>      MatrixRowSlice& operator=(const ConstMatrixBase<T, V>& x)         { return assignFrom(x); }         /// assigns this row to x.      template <class V>      MatrixRowSlice& operator=(const ConstVectorBase<T, V>& x)         { return assignFrom(x); }         /// assigns this row to x.      MatrixRowSlice& operator=(const std::valarray<T>& x)         { return assignFrom(x); }         /// assigns this row to x.      MatrixRowSlice& operator=(const T x)         { return assignFrom(x); }         /// assigns this row to x.      MatrixRowSlice& operator=(const T* x)         { return assignFrom(x); }         /// returns the j'th element of the slice, non-const      T& operator[] (size_t j)         { return (*m)(r, colStart() + j * colStride()); }         /// returns the j'th element of the slice, non-const      T& operator() (size_t j)         { return (*m)(r, colStart() + j * colStride()); }         /// returns the j'th element of the slice, const      T operator[] (size_t j) const         { return (*m)(r, colStart() + j * colStride()); }         /// returns the j'th element of the slice, const      T operator() (size_t j) const         { return (*m)(r, colStart() + j * colStride()); }         /// returns the (i,j) element of the slice, non-const      T& operator() (size_t i, size_t j)          { return (*m)(i + r, colStart() + j * colStride()); }         /// returns the (i,j) element of the slice, const      T operator() (size_t i, size_t j) const         { return (*m)(i + r, colStart() + j * colStride()); }         /// returns the number of rows in the row slice      size_t rows() const {return 1;}         /// returns the number of columns in the row slice      size_t cols() const {return colSize();}         /// returns the size of the slice      size_t size() const {return colSize();}         /// returns the number of rows in this slice      size_t rowSize() const { return 1; }         /// returns the starting row in the base matrix of this slice      size_t rowStart() const{ return r; }         /// returns the number of elements between the i'th and i+1'th row      size_t rowStride() const { return 1; }         /// returns the number of columns in this slice      size_t colSize() const { return cSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t colStart() const { return cSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t colStride() const { return cSlice.stride(); }   private:         /// the matrix this slice refers to.      Matrix<T>* m;         /// the row of the slice      size_t r;         /// the column slice of the row.      std::slice cSlice;   };/** * an unmodifiable row slice of a matrix. */   template <class T>   class ConstMatrixRowSlice : public ConstMatrixSliceBase<T, ConstMatrixRowSlice<T> >   {   public:         /// default constructor      ConstMatrixRowSlice()             : m(NULL), r(0), cSlice(std::slice(0,0,0))          {}         /// makes a const row slice from the matrix      ConstMatrixRowSlice(const Matrix<T>& mat, size_t row)            : m(&mat), r(row), cSlice(std::slice(0,mat.cols(),1))         { matSliceCheck(mat.rows(), mat.cols()); }         /// makes a const row slice from the matrix, slicing that row by \c s.      ConstMatrixRowSlice(const Matrix<T>& mat, size_t row,                        const std::slice& s)            : m(&mat), r(row), cSlice(s)         {                // decide if the input is reasonable            matSliceCheck(mat.rows(), mat.cols());         }            /// returns the i'th element of the slice      T operator[] (size_t i) const         { return (*m)(r, colStart() + i * colStride()); }         /// returns the i'th element of the slice      T operator() (size_t i) const         { return (*m)(r, colStart() + i * colStride()); }         /// returns the (i,j) element of the slice      T operator() (size_t i, size_t j) const         { return (*m)(i + r, colStart() + j * colStride()); }         /// returns the number of rows in the slice      size_t rows() const {return 1;}         /// returns the number of columns in the slice      size_t cols() const {return colSize();}         /// returns the overall size of the slice      size_t size() const {return colSize();}         /// returns the number of rows in this slice      size_t rowSize() const { return 1; }         /// returns the starting row in the base matrix of this slice      size_t rowStart() const{ return r; }         /// returns the number of elements between the i'th and i+1'th row      size_t rowStride() const { return 1; }         /// returns the number of columns in this slice      size_t colSize() const { return cSlice.size(); }         /// returns the starting row in the base matrix of this slice      size_t colStart() const { return cSlice.start(); }         /// returns the number of elements between the i'th and i+1'th row      size_t colStride() const { return cSlice.stride(); }   private:         /// the matrix this slice refers to      const Matrix<T>* m;         /// the row of the slice      size_t r;         /// the slice of the row's columns      std::slice cSlice;   };   //@}}  // namespace#include "MatrixImplementation.hpp"#include "MatrixOperators.hpp"#include "MatrixFunctors.hpp"#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -