#ifndef _theplu_yat_utility_matrix_weighted_ #define _theplu_yat_utility_matrix_weighted_ // $Id: MatrixWeighted.h 1706 2009-01-08 21:36:27Z peter $ /* Copyright (C) 2003 Daniel Dalevi, Peter Johansson Copyright (C) 2004 Jari Häkkinen, Peter Johansson Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson Copyright (C) 2009 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "DataWeight.h" #include "StrideIterator.h" #include namespace theplu { namespace yat { namespace utility { class Matrix; /// /// @brief Weighted Matrix /// class MatrixWeighted { public: /** value_type is DataWeight \since New in yat 0.5 */ typedef DataWeight value_type; /** reference type is DataWeight& */ typedef DataWeight& reference; /** const_reference type is const DataWeight& */ typedef const DataWeight& const_reference; /** Mutable iterator that iterates over all elements */ typedef std::vector::iterator iterator; /** Read-only iterator that iterates over all elements */ typedef std::vector::const_iterator const_iterator; /** Mutable iterator that iterates over one column */ typedef StrideIterator::iterator> column_iterator; /** Read-only iterator that iterates over one column */ typedef StrideIterator::const_iterator> const_column_iterator; /** Mutable iterator that iterates over one row */ typedef column_iterator row_iterator; /** Read-only iterator that iterates over one row */ typedef const_column_iterator const_row_iterator; /** @brief The default constructor. This contructor does not initialize underlying (essential) structures. */ MatrixWeighted(void); /** \brief Constructor allocating memory space for \a r times \a c elements, and sets all elements to DataWeight(\a init_value, \a init_weight) */ MatrixWeighted(size_t r, size_t c, double init_value=0, double init_weight=1.0); /** \brief The copy constructor. */ MatrixWeighted(const MatrixWeighted&); /** \brief constructor. Data is copied from \a other and weights are calculated using the nan function. */ explicit MatrixWeighted(const Matrix& other); /** \brief The istream constructor. This constructor first creates a Matrix using the istream constructor, and then constructs MatrixWeighted using MatrixWeighted(const Matrix&). */ explicit MatrixWeighted(std::istream &, char sep='\0'); /** Iterator iterates along a row. When end of row is reached it jumps to beginning of next row. \return iterator pointing to upper-left element. */ iterator begin(void); /** Iterator iterates along a row. When end of row is reached it jumps to beginning of next row. \return const_iterator pointing to upper-left element. */ const_iterator begin(void) const; /** Iterator iterates along a column. \return iterator pointing to first element of column \a i. */ column_iterator begin_column(size_t i); /** Iterator iterates along a column. \return const_iterator pointing to first element of column \a i. */ const_column_iterator begin_column(size_t i) const; /** Iterator iterates along a row. \return iterator pointing to first element of row \a i. */ row_iterator begin_row(size_t i); /** Iterator iterates along a row. \return const_iterator pointing to first element of row \a i. */ const_row_iterator begin_row(size_t i) const; /** \return The number of columns in the matrix. */ size_t columns(void) const; /** \return iterator pointing to end of matrix */ iterator end(void); /** \return const_iterator pointing to end of matrix */ const_iterator end(void) const; /** \return iterator pointing to end of column \a i */ column_iterator end_column(size_t i); /** \return const_iterator pointing to end of column \a i */ const_column_iterator end_column(size_t i) const; /** \return iterator pointing to end of row \a i */ row_iterator end_row(size_t i); /** \return const_iterator pointing to end of row \a i */ const_row_iterator end_row(size_t i) const; /** \brief swap objects Takes constant time. Invalidates iterators. */ void swap(MatrixWeighted& other); /** \brief Resize Matrix \note this function may invalidate iterators. */ void resize(size_t, size_t); /** \return The number of rows in the matrix. */ size_t rows(void) const; /** \brief Element access operator. \return Reference to the element position (\a row, \a column). */ DataWeight& operator()(size_t row,size_t column); /** \brief Element access operator. \return Const reference to the element position (\a row, \a column). */ const DataWeight& operator()(size_t row,size_t column) const; /** \brief The assignment operator. \return A const reference to the resulting Matrix. */ const MatrixWeighted& operator=(const MatrixWeighted& other); private: void copy(const Matrix&); void copy(const Matrix& data, const Matrix& weight); std::vector vec_; size_t columns_; }; /** \brief Exchange all elements. Takes constant time. \see MatrixWeighted::swap(MatrixWeighted&) */ void swap(MatrixWeighted&, MatrixWeighted&); }}} // of namespace utility, yat, and theplu #endif