--- trunk/gadget/matrix.h 2015/07/23 19:00:38 11 +++ trunk/gadget/matrix.h 2015/07/29 17:33:41 13 @@ -1,18 +1,16 @@ #ifndef matrix_h #define matrix_h -//#include "doublevector.h" #include "intvector.h" #include "doublematrix.h" -//TODO doc all /** * \class Matrix - * \brief This class implements a Matrix + * \brief This class implements a Matrix of doubles, composed of an array of nc*nr doubles */ class Matrix { public: /** - * \brief This is the default DoubleMatrix constructor + * \brief This is the default Matrix constructor */ Matrix() { nrow = 0; @@ -21,117 +19,85 @@ } ; /** - * \brief This is the DoubleMatrix constructor for a specified size - * \param nr is the size of the vector to be created - * \param nc is the length of each row to be created (ie. the size of the DoubleVector to be created for each row) - * \param initial is the initial value for all the entries of the vector + * \brief This is the Matrix constructor for a specified size + * \param nr is the length of each row of the matrix + * \param nc is the length of each column of the matrix + * \param initial is the initial value for all the entries of the matrix */ Matrix(int nr, int nc, double initial); /** - * \brief This is the DoubleMatrix constructor that creates a copy of an existing DoubleMatrix - * \param initial is the DoubleMatrix to copy - */ - //TODO OJO - //Matrix(const DoubleMatrix& initial); - /** - * \brief This is the DoubleMatrix destructor - * \note This will free all the memory allocated to all the elements of the vector + * \brief This is the Matrix destructor + * \note This will free all the memory allocated to all the elements of the matrix */ ~Matrix(); /** - * \brief This will return the number of columns in row i of the vector - * \param i is the row of the vector to have the number of columns counted - * \return the number of columns in row i of the vector - * \note This is the number of entries in the DoubleVector that is entry i of the DoubleMatrix - */ -// int Ncol(int i = 0) const { return v[i]->Size(); }; - /** - * \brief This will return the number of rows of the vector - * \return the number of rows of the vector + * \brief This will return the number of rows of the matrix + * \return the number of rows of the matrix */ int Nrow() const { return nrow; } ; /** - * \brief This will return the value of an element of the vector - * \param pos is the element of the vector to be returned - * \return the value of the specified element + * \brief This will return the number of columns of the matrix + * \return the number of columns of the matrix */ - int Ncol() const { return ncol; } ; - -// double** GetMatrix () const { return m;}; - double* operator [] (int i) { return m + (i*ncol); }; - + /** + * \brief This will return the pointer to the row i of the matrix + * \param i is the row to be returned + * \return the pointer to the part of the array where the specified row begins + */ + double* operator [] (int i) { return m + (i*ncol); }; + /** + * \brief This will return the pointer to the row i of the matrix + * \param i is the row to be returned + * \return the pointer to the part of the array where the specified row begins + */ const double* operator [] (int i) const { return m + (i*ncol); }; /** - * \brief This will return the value of an element of the vector - * \param pos is the element of the vector to be returned - * \return the value of the specified element - */ -// const DoubleVector& operator [] (int pos) const { return *v[pos]; }; - /** - * \brief This will add new entries to the vector - * \param add is the number of new entries to the vector - * \param length is the number of entries to the DoubleVector that is created + * \brief This will add new entries to the matrix + * \param add is the number of new entries to the matrix + * \param length is the number of entries to the Matrix that is created * \param value is the value that will be entered for the new entries */ void AddRows(int add, int length, double value); /** - * \brief This will delete an entry from the vector - * \param pos is the element of the vector to be deleted - * \note This will free the memory allocated to the deleted element of the vector + * \brief This will reset the matrix + * \note This will delete every entry from the matrix and set the number of rows and columns to zero */ -// void Delete(int pos); + void Reset(); /** - * \brief This will reset the vector - * \note This will delete every entry from the vector and set the number of rows to zero + * \brief This is will initialize the matrix to a specified size with a initial value + * \param nr is the length of each row of the matrix + * \param nc is the length of each column of the matrix + * \param initial is the initial value for all the entries of the matrix */ - void Reset(); - - //FIXME: doc void Initialize(int nr, int nc, double initial); /** - * \brief This function will set all of the entries of the vector to zero + * \brief This function will set all of the entries of the matrix to zero */ void setToZero(); /** - * \brief This function will print the data stored in the vector + * \brief This function will print the data stored in the matrix * \param outfile is the ofstream that all the model information gets sent to */ void Print(ofstream& outfile) const; - /** - * \brief This operator will set the vector equal to an existing DoubleMatrix - * \param d is the DoubleMatrix to copy - */ -// Matrix& operator = (const Matrix& d); -// double GetValue(int i, int j) const { -// return m[i * ncol + j]; -// } -// ; -// -// void SetValue(int i, int j, double value) const { -// m[i * ncol + j] = value; -// } -// ; - protected: /** - * \brief This is number of rows of the vector + * \brief This is number of rows of the matrix */ int nrow; + /** + * \brief This is number of columns of the matrix + */ int ncol; - - //FIXME: doc /** - * \brief This is the vector of DoubleVector values + * \brief This is the array of nr*nc doubles that represents the matrix */ - //DoubleVector** v; - //double** v; double *m; };