c++boost.gifMatrix Proxies

Matrix Row

Description

The templated class matrix_row<M> allows addressing a row of a matrix.

Example

int main () {
    using namespace boost::numeric::ublas;
    matrix<double> m (3, 3);
    for (int i = 0; i < m.size1 (); ++ i) {
        matrix_row<matrix<double> > mr (m, i);
        for (int j = 0; j < mr.size (); ++ j) 
            mr (j) = 3 * i + j;
        std::cout << mr << std::endl;
    }
}

Definition

Defined in the header matrix_proxy.hpp.

Template parameters

Parameter Description Default
M The type of matrix referenced.  

Model of

Vector Expression.

Type requirements

None, except for those imposed by the requirements of Vector Expression.

Public base classes

vector_expression<matrix_row<M> >

Members

Member Description
matrix_row (matrix_type &data, size_type i) Constructs a sub vector.
size_type size () const Returns the size of the sub vector.
const_reference operator () (size_type i) const Returns the value of the i-th element.
reference operator () (size_type i) Returns a reference of the i-th element.
matrix_row &operator = (const matrix_row &mr) The assignment operator.
matrix_row &assign_temporary (matrix_row &mr) Assigns a temporary. May change the matrix row mr.
template<class AE>
matrix_row &operator = (const vector_expression<AE> &ae)
The extended assignment operator.
template<class AE>
matrix_row &assign (const vector_expression<AE> &ae)
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
template<class AE>
matrix_row &operator += (const vector_expression<AE> &ae)
A computed assignment operator. Adds the vector expression to the sub vector.
template<class AE>
matrix_row &plus_assign (const vector_expression<AE> &ae)
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
template<class AE>
matrix_row &operator -= (const vector_expression<AE> &ae)
A computed assignment operator. Subtracts the vector expression from the sub vector.
template<class AE>
matrix_row &minus_assign (const vector_expression<AE> &ae)
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent.
template<class AT>
matrix_row &operator *= (const AT &at)
A computed assignment operator. Multiplies the sub vector with a scalar.
template<class AT>
matrix_row &operator /= (const AT &at)
A computed assignment operator. Divides the sub vector through a scalar.
void swap (matrix_row &mr) Swaps the contents of the sub vectors.
const_iterator begin () const Returns a const_iterator pointing to the beginning of the matrix_row.
const_iterator end () const Returns a const_iterator pointing to the end of the matrix_row.
iterator begin () Returns a iterator pointing to the beginning of the matrix_row.
iterator end () Returns a iterator pointing to the end of the matrix_row.
const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the reversed matrix_row.
const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed matrix_row.
reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed matrix_row.
reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed matrix_row.

Interface

    // Matrix based row vector class
    template<class M>
    class matrix_row:
        public vector_expression<matrix_row<M> > {
    public:      
        typedef const M const_matrix_type;
        typedef M matrix_type;
        typedef typename M::size_type size_type;
        typedef typename M::difference_type difference_type;
        typedef typename M::value_type value_type;
        typedef typename M::const_reference const_reference;
        typedef typename M::reference reference;
        typedef typename M::const_pointer const_pointer;
        typedef typename M::pointer pointer;
        typedef const vector_const_reference<const matrix_row<matrix_type> > const_closure_type;
        typedef vector_reference<matrix_row<matrix_type> > closure_type;
        typedef typename M::const_iterator2 const_iterator_type;
        typedef typename M::iterator2 iterator_type;
        typedef typename storage_restrict_traits<typename M::storage_category,
                                                 dense_proxy_tag>::storage_category storage_category;

        // Construction and destruction
        matrix_row ();
        matrix_row (matrix_type &data, size_type i);

        // Accessors
        size_type size () const;
        const_matrix_type &data () const;
        matrix_type &data ();


        // Element access
        const_reference operator () (size_type j) const;
        reference operator () (size_type j);

        const_reference operator [] (size_type j) const;
        reference operator [] (size_type j);

        // Assignment
        matrix_row &operator = (const matrix_row &mr);
        matrix_row &assign_temporary (matrix_row &mr);
        template<class AE>
        matrix_row &operator = (const vector_expression<AE> &ae);
        template<class AE>
        matrix_row &assign (const vector_expression<AE> &ae);
        template<class AE>
        matrix_row &operator += (const vector_expression<AE> &ae);
        template<class AE>
        matrix_row &plus_assign (const vector_expression<AE> &ae);
        template<class AE>
        matrix_row &operator -= (const vector_expression<AE> &ae);
        template<class AE>
        matrix_row &minus_assign (const vector_expression<AE> &ae);
        template<class AT>
        matrix_row &operator *= (const AT &at);
        template<class AT>
        matrix_row &operator /= (const AT &at);

        // Swapping
        void swap (matrix_row &mr);
        friend void swap (matrix_row &mr1, matrix_row &mr2);

        class const_iterator;
        class iterator;

        // Element lookup
        const_iterator find_first (size_type j) const;
        iterator find_first (size_type j);
        const_iterator find_last (size_type j) const;
        iterator find_last (size_type j);

        // Iterators simply are pointers.

        class const_iterator:
            public container_const_reference<matrix_row>,
            public random_access_iterator_base<const_iterator, value_type> {
        public:
            typedef typename M::const_iterator2::iterator_category iterator_category;
            typedef typename M::const_iterator2::difference_type difference_type;
            typedef typename M::const_iterator2::value_type value_type;
            typedef typename M::const_iterator2::reference reference;
            typedef typename M::const_iterator2::pointer pointer;

            // Construction and destruction
            const_iterator ();
            const_iterator (const matrix_row &mr, const const_iterator_type &it);
            const_iterator (const iterator &it);

            // Arithmetic
            const_iterator &operator ++ ();
            const_iterator &operator -- ();
            const_iterator &operator += (difference_type n);
            const_iterator &operator -= (difference_type n);
            difference_type operator - (const const_iterator &it) const;

            // Dereference
            reference operator * () const;

            // Index
            size_type index () const;

            // Assignment 
            const_iterator &operator = (const const_iterator &it);

            // Comparison
            bool operator == (const const_iterator &it) const;
            bool operator <(const const_iterator &it) const;
        };

        const_iterator begin () const;
        const_iterator end () const;

        class iterator:
            public container_reference<matrix_row>,
            public random_access_iterator_base<iterator, value_type> {
        public:
            typedef typename M::iterator2::iterator_category iterator_category;
            typedef typename M::iterator2::difference_type difference_type;
            typedef typename M::iterator2::value_type value_type;
            typedef typename M::iterator2::reference reference;
            typedef typename M::iterator2::pointer pointer;

            // Construction and destruction
            iterator ();
            iterator (matrix_row &mr, const iterator_type &it);

            // Arithmetic
            iterator &operator ++ ();
            iterator &operator -- ();
            iterator &operator += (difference_type n);
            iterator &operator -= (difference_type n);
            difference_type operator - (const iterator &it) const;

            // Dereference
            reference operator * () const;

            // Index
            size_type index () const;

            // Assignment 
            iterator &operator = (const iterator &it);

            // Comparison
            bool operator == (const iterator &it) const;
            bool operator <(const iterator &it) const;
        };

        iterator begin ();
        iterator end ();

        // Reverse iterator

        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;

        const_reverse_iterator rbegin () const;
        const_reverse_iterator rend () const;

        typedef reverse_iterator_base<iterator> reverse_iterator;

        reverse_iterator rbegin ();
        reverse_iterator rend ();
    };

Projections

Prototypes

    template<class M>
    matrix_row<M> row (M &data, std::size_t i);
    template<class M>
    const matrix_row<const M> row (const M &data, std::size_t i);

Description

The free row functions support the construction of matrix rows.

Definition

Defined in the header matrix_proxy.hpp.

Type requirements

  • M is a model of Matrix Expression.
  • Preconditions

    Complexity

    Linear depending from the size of the row.

    Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i) {
            for (int j = 0; j < m.size2 (); ++ j) 
                row (m, i) (j) = 3 * i + j;
            std::cout << row (m, i) << std::endl;
        }
    }

    Matrix Column

    Description

    The templated class matrix_column<M> allows addressing a column of a matrix.

    Example

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int j = 0; j < m.size2 (); ++ j) {
            matrix_column<matrix<double> > mc (m, j);
            for (int i = 0; i < mc.size (); ++ i)
                mc (i) = 3 * i + j;
            std::cout << mc << std::endl;
        }
    }

    Definition

    Defined in the header matrix_proxy.hpp.

    Template parameters

    Parameter Description Default
    M The type of matrix referenced.  

    Model of

    Vector Expression.

    Type requirements

    None, except for those imposed by the requirements of Vector Expression.

    Public base classes

    vector_expression<matrix_column<M> >

    Members

    Member Description
    matrix_column (matrix_type &data, size_type j) Constructs a sub vector.
    size_type size () const Returns the size of the sub vector.
    const_reference operator () (size_type i) const Returns the value of the i-th element.
    reference operator () (size_type i) Returns a reference of the i-th element.
    matrix_column &operator = (const matrix_column &mc) The assignment operator.
    matrix_column &assign_temporary (matrix_column &mc) Assigns a temporary. May change the matrix column mc.
    template<class AE>
    matrix_column &operator = (const vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    matrix_column &assign (const vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_column &operator += (const vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector expression to the sub vector.
    template<class AE>
    matrix_column &plus_assign (const vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_column &operator -= (const vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector expression from the sub vector.
    template<class AE>
    matrix_column &minus_assign (const vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent.
    template<class AT>
    matrix_column &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub vector with a scalar.
    template<class AT>
    matrix_column &operator /= (const AT &at)
    A computed assignment operator. Divides the sub vector through a scalar.
    void swap (matrix_column &mc) Swaps the contents of the sub vectors.
    const_iterator begin () const Returns a const_iterator pointing to the beginning of the matrix_column.
    const_iterator end () const Returns a const_iterator pointing to the end of the matrix_column.
    iterator begin () Returns a iterator pointing to the beginning of the matrix_column.
    iterator end () Returns a iterator pointing to the end of the matrix_column.
    const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the reversed matrix_column.
    const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed matrix_column.
    reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed matrix_column.
    reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed matrix_column.

    Interface

        // Matrix based column vector class
        template<class M>
        class matrix_column:
            public vector_expression<matrix_column<M> > {
        public:      
            typedef const M const_matrix_type;
            typedef M matrix_type;
            typedef typename M::size_type size_type;
            typedef typename M::difference_type difference_type;
            typedef typename M::value_type value_type;
            typedef typename M::const_reference const_reference;
            typedef typename M::reference reference;
            typedef typename M::const_pointer const_pointer;
            typedef typename M::pointer pointer;
            typedef const vector_const_reference<const matrix_column<matrix_type> > const_closure_type;
            typedef vector_reference<matrix_column<matrix_type> > closure_type;
            typedef typename M::const_iterator1 const_iterator_type;
            typedef typename M::iterator1 iterator_type;
            typedef typename storage_restrict_traits<typename M::storage_category,
                                                     dense_proxy_tag>::storage_category storage_category;
    
            // Construction and destruction
            matrix_column ();
            matrix_column (matrix_type &data, size_type j);
    
            // Accessors
            size_type size () const;
            const_matrix_type &data () const;
            matrix_type &data ();
    
    
            // Element access
            const_reference operator () (size_type i) const;
            reference operator () (size_type i);
    
            const_reference operator [] (size_type i) const;
            reference operator [] (size_type i);
    
            // Assignment
            matrix_column &operator = (const matrix_column &mc);
            matrix_column &assign_temporary (matrix_column &mc);
            template<class AE>
            matrix_column &operator = (const vector_expression<AE> &ae);
            template<class AE>
            matrix_column &assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_column &operator += (const vector_expression<AE> &ae);
            template<class AE>
            matrix_column &plus_assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_column &operator -= (const vector_expression<AE> &ae);
            template<class AE>
            matrix_column &minus_assign (const vector_expression<AE> &ae);
            template<class AT>
            matrix_column &operator *= (const AT &at);
            template<class AT>
            matrix_column &operator /= (const AT &at);
    
            // Swapping
            void swap (matrix_column &mc);
            friend void swap (matrix_column &mc1, matrix_column &mc2);
    
            class const_iterator;
            class iterator;
    
            // Element lookup
            const_iterator find_first (size_type i) const;
            iterator find_first (size_type i);
            const_iterator find_last (size_type i) const;
            iterator find_last (size_type i);
    
            // Iterators simply are pointers.
    
            class const_iterator:
                public container_const_reference<matrix_column>,
                public random_access_iterator_base<const_iterator, value_type> {
            public:
                typedef typename M::const_iterator1::iterator_category iterator_category;
                typedef typename M::const_iterator1::difference_type difference_type;
                typedef typename M::const_iterator1::value_type value_type;
                typedef typename M::const_iterator1::reference reference;
                typedef typename M::const_iterator1::pointer pointer;
    
                // Construction and destruction
                const_iterator ();
                const_iterator (const matrix_column &mc, const const_iterator_type &it);
                const_iterator (const iterator &it);
    
                // Arithmetic
                const_iterator &operator ++ ();
                const_iterator &operator -- ();
                const_iterator &operator += (difference_type n);
                const_iterator &operator -= (difference_type n);
                difference_type operator - (const const_iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type index () const;
    
                // Assignment 
                const_iterator &operator = (const const_iterator &it);
    
                // Comparison
                bool operator == (const const_iterator &it) const;
                bool operator <(const const_iterator &it) const;
            };
    
            const_iterator begin () const;
            const_iterator end () const;
    
            class iterator:
                public container_reference<matrix_column>,
                public random_access_iterator_base<iterator, value_type> {
            public:
                typedef typename M::iterator1::iterator_category iterator_category;
                typedef typename M::iterator1::difference_type difference_type;
                typedef typename M::iterator1::value_type value_type;
                typedef typename M::iterator1::reference reference;
                typedef typename M::iterator1::pointer pointer;
    
                // Construction and destruction
                iterator ();
                iterator (matrix_column &mc, const iterator_type &it);
    
                // Arithmetic
                iterator &operator ++ ();
                iterator &operator -- ();
                iterator &operator += (difference_type n);
                iterator &operator -= (difference_type n);
                difference_type operator - (const iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type index () const;
    
                // Assignment 
                iterator &operator = (const iterator &it);
    
                // Comparison
                bool operator == (const iterator &it) const;
                bool operator <(const iterator &it) const;
            };
    
            iterator begin ();
            iterator end ();
    
            // Reverse iterator
    
            typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    
            const_reverse_iterator rbegin () const;
            const_reverse_iterator rend () const;
    
            typedef reverse_iterator_base<iterator> reverse_iterator;
    
            reverse_iterator rbegin ();
            reverse_iterator rend ();
        };

    Projections

    Prototypes

        template<class M>
        matrix_column<M> column (M &data, std::size_t j);
        template<class M>
        const matrix_column<const M> column (const M &data, std::size_t j);

    Description

    The free column functions support the construction of matrix columns.

    Definition

    Defined in the header matrix_proxy.hpp.

    Type requirements

  • M is a model of Matrix Expression.
  • Preconditions

    Complexity

    Linear depending from the size of the column.

    Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int j = 0; j < m.size2 (); ++ j) {
            for (int i = 0; i < m.size1 (); ++ i)
                column (m, j) (i) = 3 * i + j;
            std::cout << column (m, j) << std::endl;
        }
    }

    Vector Range

    Description

    The templated class matrix_vector_range<M> allows addressing a sub vector of a matrix.

    Example

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i) 
            for (int j = 0; j < m.size2 (); ++ j) 
                m (i, j) = 3 * i + j;
    
        matrix_vector_range<matrix<double> > mvr (m, range (0, 3), range (0, 3));
        std::cout << mvr << std::endl;
    }

    Definition

    Defined in the header matrix_proxy.hpp.

    Template parameters

    Parameter Description Default
    M The type of matrix referenced.  

    Model of

    Vector Expression.

    Type requirements

    None, except for those imposed by the requirements of Vector Expression.

    Public base classes

    vector_expression<matrix_vector_range<M> >

    Members

    Member Description
    matrix_vector_range (matrix_type &data,
     const range &r1, const range &r2)
    Constructs a sub vector.
    size_type size () const Returns the size of the sub vector.
    const_reference operator () (size_type i) const Returns the value of the i-th element.
    reference operator () (size_type i) Returns a reference of the i-th element.
    matrix_vector_range &operator = (const matrix_vector_range &mvr) The assignment operator.
    matrix_vector_range &assign_temporary (matrix_vector_range &mvr) Assigns a temporary. May change the matrix vector range mvr.
    template<class AE>
    matrix_vector_range &operator = (const vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    matrix_vector_range &assign (const vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_vector_range &operator += (const vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector expression to the sub vector.
    template<class AE>
    matrix_vector_range &plus_assign (const vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_vector_range &operator -= (const vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector expression from the sub vector.
    template<class AE>
    matrix_vector_range &minus_assign (const vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent.
    template<class AT>
    matrix_vector_range &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub vector with a scalar.
    template<class AT>
    matrix_vector_range &operator /= (const AT &at)
    A computed assignment operator. Divides the sub vector through a scalar.
    void swap (matrix_vector_range &mvr) Swaps the contents of the sub vectors.
    const_iterator begin () const Returns a const_iterator pointing to the beginning of the matrix_vector_range.
    const_iterator end () const Returns a const_iterator pointing to the end of the matrix_vector_range.
    iterator begin () Returns a iterator pointing to the beginning of the matrix_vector_range.
    iterator end () Returns a iterator pointing to the end of the matrix_vector_range.
    const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the matrix_vector_range.
    const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed matrix_vector_range.
    reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed matrix_vector_range.
    reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed matrix_vector_range.

    Interface

        // Matrix based vector range class
        template<class M>
        class matrix_vector_range:
            public vector_expression<matrix_vector_range<M> > {
        public:      
            typedef const M const_matrix_type;
            typedef M matrix_type;
            typedef typename M::size_type size_type;
            typedef typename M::difference_type difference_type;
            typedef typename M::value_type value_type;
            typedef typename M::const_reference const_reference;
            typedef typename M::reference reference;
            typedef typename M::const_pointer const_pointer;
            typedef typename M::pointer pointer;
            typedef const vector_const_reference<const matrix_vector_range<matrix_type> > const_closure_type;
            typedef vector_reference<matrix_vector_range<matrix_type> > closure_type;
            typedef range::const_iterator const_iterator1_type;
            typedef range::const_iterator iterator1_type;
            typedef range::const_iterator const_iterator2_type;
            typedef range::const_iterator iterator2_type;
            typedef typename storage_restrict_traits<typename M::storage_category,
                                                     dense_proxy_tag>::storage_category storage_category;
    
            // Construction and destruction
            matrix_vector_range ();
            matrix_vector_range (matrix_type &data, const range &r1, const range &r2);
    
            // Accessors
            size_type size () const;
            const_matrix_type &data () const;
            matrix_type &data ();
    
    
            // Element access
            const_reference operator () (size_type i) const;
            reference operator () (size_type i);
    
            const_reference operator [] (size_type i) const;
            reference operator [] (size_type i);
    
            // Assignment
            matrix_vector_range &operator = (const matrix_vector_range &mvr);
            matrix_vector_range &assign_temporary (matrix_vector_range &mvr);
            template<class AE>
            matrix_vector_range &operator = (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_range &assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_range &operator += (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_range &plus_assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_range &operator -= (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_range &minus_assign (const vector_expression<AE> &ae);
            template<class AT>
            matrix_vector_range &operator *= (const AT &at);
            template<class AT>
            matrix_vector_range &operator /= (const AT &at);
    
            // Swapping
            void swap (matrix_vector_range &mvr);
            friend void swap (matrix_vector_range &mvr1, matrix_vector_range &mvr2);
    
            class const_iterator;
            class iterator;
    
            // Element lookup
            const_iterator find_first (size_type i) const;
            iterator find_first (size_type i);
            const_iterator find_last (size_type i) const;
            iterator find_last (size_type i);
    
            // Iterators simply are indices.
    
            class const_iterator:
                public container_const_reference<matrix_vector_range>,
                public random_access_iterator_base<const_iterator, value_type> {
            public:
                typedef typename restrict_traits<typename M::const_iterator1::iterator_category,
                                                 typename M::const_iterator2::iterator_category>::iterator_category iterator_category; 
                typedef typename matrix_vector_range::difference_type difference_type;
                typedef typename matrix_vector_range::value_type value_type;
                typedef typename matrix_vector_range::const_reference reference;
                typedef typename matrix_vector_range::const_pointer pointer;
    
                // Construction and destruction
                const_iterator ();
                const_iterator (const matrix_vector_range &mvr, const const_iterator1_type &it1, const const_iterator2_type &it2);
                const_iterator (const iterator &it);
    
                // Arithmetic
                const_iterator &operator ++ ();
                const_iterator &operator -- ();
                const_iterator &operator += (difference_type n);
                const_iterator &operator -= (difference_type n);
                difference_type operator - (const const_iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type  index () const;
    
                // Assignment 
                const_iterator &operator = (const const_iterator &it);
    
                // Comparison
                bool operator == (const const_iterator &it) const;
                bool operator <(const const_iterator &it) const;
            };
    
            const_iterator begin () const;
            const_iterator end () const;
    
            class iterator:
                public container_reference<matrix_vector_range>,
                public random_access_iterator_base<iterator, value_type> {
            public:
                typedef typename restrict_traits<typename M::iterator1::iterator_category,
                                                 typename M::iterator2::iterator_category>::iterator_category iterator_category; 
                typedef typename matrix_vector_range::difference_type difference_type;
                typedef typename matrix_vector_range::value_type value_type;
                typedef typename matrix_vector_range::reference reference;
                typedef typename matrix_vector_range::pointer pointer;
    
                // Construction and destruction
                iterator ();
                iterator (matrix_vector_range &mvr, const iterator1_type &it1, const iterator2_type &it2);
    
                // Arithmetic
                iterator &operator ++ ();
                iterator &operator -- ();
                iterator &operator += (difference_type n);
                iterator &operator -= (difference_type n);
                difference_type operator - (const iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type index () const;
    
                // Assignment 
                iterator &operator = (const iterator &it);
    
                // Comparison
                bool operator == (const iterator &it) const;
                bool operator <(const iterator &it) const;
            };
    
            iterator begin ();
            iterator end ();
    
            // Reverse iterator
    
            typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    
            const_reverse_iterator rbegin () const;
            const_reverse_iterator rend () const;
    
            typedef reverse_iterator_base<iterator> reverse_iterator;
    
            reverse_iterator rbegin ();
            reverse_iterator rend ();
        };

    Vector Slice

    Description

    The templated class matrix_vector_slice<M> allows addressing a sliced sub vector of a matrix.

    Example

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i) 
            for (int j = 0; j < m.size2 (); ++ j) 
                m (i, j) = 3 * i + j;
    
        matrix_vector_range<matrix<double> > mvs (m, slice (0, 1, 3), slice (0, 1, 3));
        std::cout << mvs << std::endl;
    }

    Definition

    Defined in the header matrix_proxy.hpp.

    Template parameters

    Parameter Description Default
    M The type of matrix referenced.  

    Model of

    Vector Expression.

    Type requirements

    None, except for those imposed by the requirements of Vector Expression.

    Public base classes

    vector_expression<matrix_vector_slice<M> >

    Members

    Member Description
    matrix_vector_slice (matrix_type &data,
     const slice &s1, const slice &s2)
    Constructs a sub vector.
    size_type size () const Returns the size of the sub vector.
    const_reference operator () (size_type i) const Returns the value of the i-th element.
    reference operator () (size_type i) Returns a reference of the i-th element.
    matrix_vector_slice &operator = (const matrix_vector_slice &mvs) The assignment operator.
    matrix_vector_slice &assign_temporary (matrix_vector_slice &mvs) Assigns a temporary. May change the matrix vector slice vs.
    template<class AE>
    matrix_vector_slice &operator = (const vector_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    matrix_vector_slice &assign (const vector_expression<AE> &ae)
    Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_vector_slice &operator += (const vector_expression<AE> &ae)
    A computed assignment operator. Adds the vector expression to the sub vector.
    template<class AE>
    matrix_vector_slice &plus_assign (const vector_expression<AE> &ae)
    Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_vector_slice &operator -= (const vector_expression<AE> &ae)
    A computed assignment operator. Subtracts the vector expression from the sub vector.
    template<class AE>
    matrix_vector_slice &minus_assign (const vector_expression<AE> &ae)
    Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent.
    template<class AT>
    matrix_vector_slice &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub vector with a scalar.
    template<class AT>
    matrix_vector_slice &operator /= (const AT &at)
    A computed assignment operator. Divides the sub vector through a scalar.
    void swap (matrix_vector_slice &mvs) Swaps the contents of the sub vectors.
    const_iterator begin () const Returns a const_iterator pointing to the beginning of the matrix_vector_slice.
    const_iterator end () const Returns a const_iterator pointing to the end of the matrix_vector_slice.
    iterator begin () Returns a iterator pointing to the beginning of the matrix_vector_slice.
    iterator end () Returns a iterator pointing to the end of the matrix_vector_slice.
    const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the reversed matrix_vector_slice.
    const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed matrix_vector_slice.
    reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed matrix_vector_slice.
    reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed matrix_vector_slice.

    Interface

        // Matrix based vector slice class
        template<class M>
        class matrix_vector_slice:
            public vector_expression<matrix_vector_slice<M> > {
        public:      
            typedef const M const_matrix_type;
            typedef M matrix_type;
            typedef typename M::size_type size_type;
            typedef typename M::difference_type difference_type;
            typedef typename M::value_type value_type;
            typedef typename M::const_reference const_reference;
            typedef typename M::reference reference;
            typedef typename M::const_pointer const_pointer;
            typedef typename M::pointer pointer;
            typedef const vector_const_reference<const matrix_vector_slice<matrix_type> > const_closure_type;
            typedef vector_reference<matrix_vector_slice<matrix_type> > closure_type;
            typedef slice::const_iterator const_iterator1_type;
            typedef slice::const_iterator iterator1_type;
            typedef slice::const_iterator const_iterator2_type;
            typedef slice::const_iterator iterator2_type;
            typedef typename storage_restrict_traits<typename M::storage_category,
                                                     dense_proxy_tag>::storage_category storage_category;
    
            // Construction and destruction
            matrix_vector_slice ();
            matrix_vector_slice (matrix_type &data, const slice &s1, const slice &s2);
    
            // Accessors
            size_type size () const;
            const_matrix_type &data () const;
            matrix_type &data ();
    
    
            // Element access
            const_reference operator () (size_type i) const;
            reference operator () (size_type i);
    
            const_reference operator [] (size_type i) const;
            reference operator [] (size_type i);
    
            // Assignment
            matrix_vector_slice &operator = (const matrix_vector_slice &mvs);
            matrix_vector_slice &assign_temporary (matrix_vector_slice &mvs);
            template<class AE>
            matrix_vector_slice &operator = (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_slice &assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_slice &operator += (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_slice &plus_assign (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_slice &operator -= (const vector_expression<AE> &ae);
            template<class AE>
            matrix_vector_slice &minus_assign (const vector_expression<AE> &ae);
            template<class AT>
            matrix_vector_slice &operator *= (const AT &at);
            template<class AT>
            matrix_vector_slice &operator /= (const AT &at);
    
            // Swapping
            void swap (matrix_vector_slice &mvs);
            friend void swap (matrix_vector_slice &mvs1, matrix_vector_slice &mvs2);
    
            class const_iterator;
            class iterator;
    
            // Element lookup
            const_iterator find_first (size_type i) const;
            iterator find_first (size_type i);
            const_iterator find_last (size_type i) const;
            iterator find_last (size_type i);
    
            // Iterators simply are indices.
    
            class const_iterator:
                public container_const_reference<matrix_vector_slice>,
                public random_access_iterator_base<const_iterator, value_type> {
            public:
                typedef typename restrict_traits<typename M::const_iterator1::iterator_category,
                                                 typename M::const_iterator2::iterator_category>::iterator_category iterator_category; 
                typedef typename matrix_vector_slice::difference_type difference_type;
                typedef typename matrix_vector_slice::value_type value_type;
                typedef typename matrix_vector_slice::const_reference reference;
                typedef typename matrix_vector_slice::const_pointer pointer;
    
                // Construction and destruction
                const_iterator ();
                const_iterator (const matrix_vector_slice &mvs, const const_iterator1_type &it1, const const_iterator2_type &it2);
                const_iterator (const iterator &it);
    
                // Arithmetic
                const_iterator &operator ++ ();
                const_iterator &operator -- ();
                const_iterator &operator += (difference_type n);
                const_iterator &operator -= (difference_type n);
                difference_type operator - (const const_iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type  index () const;
    
                // Assignment 
                const_iterator &operator = (const const_iterator &it);
    
                // Comparison
                bool operator == (const const_iterator &it) const;
                bool operator <(const const_iterator &it) const;
            };
    
            const_iterator begin () const;
            const_iterator end () const;
    
            class iterator:
                public container_reference<matrix_vector_slice>,
                public random_access_iterator_base<iterator, value_type> {
            public:
                typedef typename restrict_traits<typename M::iterator1::iterator_category,
                                                 typename M::iterator2::iterator_category>::iterator_category iterator_category; 
                typedef typename matrix_vector_slice::difference_type difference_type;
                typedef typename matrix_vector_slice::value_type value_type;
                typedef typename matrix_vector_slice::reference reference;
                typedef typename matrix_vector_slice::pointer pointer;
    
                // Construction and destruction
                iterator ();
                iterator (matrix_vector_slice &mvs, const iterator1_type &it1, const iterator2_type &it2);
    
                // Arithmetic
                iterator &operator ++ ();
                iterator &operator -- ();
                iterator &operator += (difference_type n);
                iterator &operator -= (difference_type n);
                difference_type operator - (const iterator &it) const;
    
                // Dereference
                reference operator * () const;
    
                // Index
                size_type index () const;
    
                // Assignment 
                iterator &operator = (const iterator &it);
    
                // Comparison
                bool operator == (const iterator &it) const;
                bool operator <(const iterator &it) const;
            };
    
            iterator begin ();
            iterator end ();
    
            // Reverse iterator
    
            typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
    
            const_reverse_iterator rbegin () const;
            const_reverse_iterator rend () const;
    
            typedef reverse_iterator_base<iterator> reverse_iterator;
    
            reverse_iterator rbegin ();
            reverse_iterator rend ();
        };

    Matrix Range

    Description

    The templated class matrix_range<M> allows addressing a sub matrix of a matrix.

    Example

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        matrix_range<matrix<double> > mr (m, range (0, 3), range (0, 3));
        for (int i = 0; i < mr.size1 (); ++ i) 
            for (int j = 0; j < mr.size2 (); ++ j) 
                mr (i, j) = 3 * i + j;
        std::cout << mr << std::endl;
    }

    Definition

    Defined in the header matrix_proxy.hpp.

    Template parameters

    Parameter Description Default
    M The type of matrix referenced.  

    Model of

    Matrix Expression.

    Type requirements

    None, except for those imposed by the requirements of Matrix Expression.

    Public base classes

    matrix_expression<matrix_range<M> >

    Members

    Member Description
    matrix_range (matrix_type &data,
     const range &r1, const range &r2)
    Constructs a sub matrix.
    size_type start1 () const Returns the index of the first row.
    size_type size1 () const Returns the number of rows.
    size_type start2 () const Returns the index of the first column.
    size_type size2 () const Returns the number of columns.
    const_reference operator () (size_type i, size_type j) const Returns the value of the j-th element in the i-th row.
    reference operator () (size_type i, size_type j) Returns a reference of the j-th element in the i-th row.
    matrix_range &operator = (const matrix_range &mr) The assignment operator.
    matrix_range &assign_temporary (matrix_range &mr) Assigns a temporary. May change the matrix range mr.
    template<class AE>
    matrix_range &operator = (const matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    matrix_range &assign (const matrix_expression<AE> &ae)
    Assigns a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_range &operator += (const matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix expression to the sub matrix.
    template<class AE>
    matrix_range &plus_assign (const matrix_expression<AE> &ae)
    Adds a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_range &operator -= (const matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix expression from the sub matrix.
    template<class AE>
    matrix_range &minus_assign (const matrix_expression<AE> &ae)
    Subtracts a matrix expression from the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AT>
    matrix_range &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub matrix with a scalar.
    template<class AT>
    matrix_range &operator /= (const AT &at)
    A computed assignment operator. Divides the sub matrix through a scalar.
    void swap (matrix_range &mr) Swaps the contents of the sub matrices.
    const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the matrix_range.
    const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the matrix_range.
    iterator1 begin1 () Returns a iterator1 pointing to the beginning of the matrix_range.
    iterator1 end1 () Returns a iterator1 pointing to the end of the matrix_range.
    const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the matrix_range.
    const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the matrix_range.
    iterator2 begin2 () Returns a iterator2 pointing to the beginning of the matrix_range.
    iterator2 end2 () Returns a iterator2 pointing to the end of the matrix_range.
    const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed matrix_range.
    const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed matrix_range.
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to the beginning of the reversed matrix_range.
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to the end of the reversed matrix_range.
    const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed matrix_range.
    const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed matrix_range.
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to the beginning of the reversed matrix_range.
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to the end of reversed the matrix_range.

    Interface

        // Matrix based range class
        template<class M>
        class matrix_range:
            public matrix_expression<matrix_range<M> > {
        public:      
            typedef const M const_matrix_type;
            typedef M matrix_type;
            typedef typename M::size_type size_type;
            typedef typename M::difference_type difference_type;
            typedef typename M::value_type value_type;
            typedef typename M::const_reference const_reference;
            typedef typename M::reference reference;
            typedef typename M::const_pointer const_pointer;
            typedef typename M::pointer pointer;
            typedef const matrix_const_reference<const matrix_range<matrix_type> > const_closure_type;
            typedef matrix_reference<matrix_range<matrix_type> > closure_type;
            typedef typename M::const_iterator1 const_iterator1_type;
            typedef typename M::iterator1 iterator1_type;
            typedef typename M::const_iterator2 const_iterator2_type;
            typedef typename M::iterator2 iterator2_type;
            typedef typename storage_restrict_traits<typename M::storage_category,
                                                     dense_proxy_tag>::storage_category storage_category;
            typedef typename M::orientation_category orientation_category;
    
            // Construction and destruction
            matrix_range ();
            matrix_range (matrix_type &data, const range &r1, const range &r2);
    
            // Accessors
            size_type start1 () const;
            size_type size1 () const;
            size_type start2() const;
            size_type size2 () const;
            const_matrix_type &data () const;
            matrix_type &data ();
    
    
            // Element access
            const_reference operator () (size_type i, size_type j) const;
            reference operator () (size_type i, size_type j);
    
            matrix_range<matrix_type> project (const range &r1, const range &r2) const;
    
            // Assignment
            matrix_range &operator = (const matrix_range &mr);
            matrix_range &assign_temporary (matrix_range &mr);
            template<class AE>
            matrix_range &operator = (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_range &assign (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_range& operator += (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_range &plus_assign (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_range& operator -= (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_range &minus_assign (const matrix_expression<AE> &ae);
            template<class AT>
            matrix_range& operator *= (const AT &at);
            template<class AT>
            matrix_range& operator /= (const AT &at);
    
            // Swapping
            void swap (matrix_range &mr);
            friend void swap (matrix_range &mr1, matrix_range &mr2);
    
            class const_iterator1;
            class iterator1;
            class const_iterator2;
            class iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base1<iterator1> reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
            typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    
            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            iterator1 find_first1 (int rank, size_type i, size_type j);
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            iterator1 find_last1 (int rank, size_type i, size_type j);
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            iterator2 find_first2 (int rank, size_type i, size_type j);
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
            iterator2 find_last2 (int rank, size_type i, size_type j);
    
            // Iterators simply are pointers.
    
            class const_iterator1:
                public container_const_reference<matrix_range>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename M::const_iterator1::iterator_category iterator_category;
                typedef typename M::const_iterator1::difference_type difference_type;
                typedef typename M::const_iterator1::value_type value_type;
                typedef typename M::const_iterator1::reference reference;
                typedef typename M::const_iterator1::pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;
    
                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_range &mr, const const_iterator1_type &it);
                const_iterator1 (const iterator1 &it);
    
                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;
    
                // Dereference
                reference operator * () const;
    
                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                const_iterator1 &operator = (const const_iterator1 &it);
    
                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };
    
            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;
    
            class iterator1:
                public container_reference<matrix_range>,
                public random_access_iterator_base<iterator1, value_type> {
            public:
                typedef typename M::iterator1::iterator_category iterator_category;
                typedef typename M::iterator1::difference_type difference_type;
                typedef typename M::iterator1::value_type value_type;
                typedef typename M::iterator1::reference reference;
                typedef typename M::iterator1::pointer pointer;
                typedef iterator2 dual_iterator_type;
                typedef reverse_iterator2 dual_reverse_iterator_type;
    
                // Construction and destruction
                iterator1 ();
                iterator1 (matrix_range &mr, const iterator1_type &it);
    
                // Arithmetic
                iterator1 &operator ++ ();
                iterator1 &operator -- ();
                iterator1 &operator += (difference_type n);
                iterator1 &operator -= (difference_type n);
                difference_type operator - (const iterator1 &it) const;
    
                // Dereference
                reference operator * () const;
    
                iterator2 begin () const;
                iterator2 end () const;
                reverse_iterator2 rbegin () const;
                reverse_iterator2 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                iterator1 &operator = (const iterator1 &it);
    
                // Comparison
                bool operator == (const iterator1 &it) const;
                bool operator <(const iterator1 &it) const;
            };
    
            iterator1 begin1 ();
            iterator1 end1 ();
    
            class const_iterator2:
                public container_const_reference<matrix_range>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename M::const_iterator2::iterator_category iterator_category;
                typedef typename M::const_iterator2::difference_type difference_type;
                typedef typename M::const_iterator2::value_type value_type;
                typedef typename M::const_iterator2::reference reference;
                typedef typename M::const_iterator2::pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;
    
                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_range &mr, const const_iterator2_type &it);
                const_iterator2 (const iterator2 &it);
    
                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;
    
                // Dereference
                reference operator * () const;
    
                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                const_iterator2 &operator = (const const_iterator2 &it);
    
                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };
    
            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;
    
            class iterator2:
                public container_reference<matrix_range>,
                public random_access_iterator_base<iterator2, value_type> {
            public:
                typedef typename M::iterator2::iterator_category iterator_category;
                typedef typename M::iterator2::difference_type difference_type;
                typedef typename M::iterator2::value_type value_type;
                typedef typename M::iterator2::reference reference;
                typedef typename M::iterator2::pointer pointer;
                typedef iterator1 dual_iterator_type;
                typedef reverse_iterator1 dual_reverse_iterator_type;
    
                // Construction and destruction
                iterator2 ();
                iterator2 (matrix_range &mr, const iterator2_type &it);
    
                // Arithmetic
                iterator2 &operator ++ ();
                iterator2 &operator -- ();
                iterator2 &operator += (difference_type n);
                iterator2 &operator -= (difference_type n);
                difference_type operator - (const iterator2 &it) const;
    
                // Dereference
                reference operator * () const;
    
                iterator1 begin () const;
                iterator1 end () const;
                reverse_iterator1 rbegin () const;
                reverse_iterator1 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                iterator2 &operator = (const iterator2 &it);
    
                // Comparison
                bool operator == (const iterator2 &it) const;
                bool operator <(const iterator2 &it) const;
            };
    
            iterator2 begin2 ();
            iterator2 end2 ();
    
            // Reverse iterators
    
            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;
    
            reverse_iterator1 rbegin1 ();
            reverse_iterator1 rend1 ();
    
            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
    
            reverse_iterator2 rbegin2 ();
            reverse_iterator2 rend2 ();
        };

    Projections

    Prototypes

        template<class M>
        matrix_range<M> project (M &data, const range &r1, const range &r2);
        template<class M>
        const matrix_range<const M> project (const M &data, const range &r1, const range &r2);
        template<class M>
        matrix_range<M> project (const matrix_range<M> &data, const range &r1, const range &r2);

    Description

    The free project functions support the construction of matrix ranges.

    Definition

    Defined in the header matrix_proxy.hpp.

    Type requirements

  • M is a model of Matrix Expression.
  • Preconditions

    Complexity

    Quadratic depending from the size of the ranges.

    Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i) 
            for (int j = 0; j < m.size2 (); ++ j) 
                project (m, range (0, 3), range (0, 3)) (i, j) = 3 * i + j;
        std::cout << project (m, range (0, 3), range (0, 3)) << std::endl;
    }

    Matrix Slice

    Description

    The templated class matrix_slice<M> allows addressing a sliced sub matrix of a matrix.

    Example

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        matrix_slice<matrix<double> > ms (m, slice (0, 1, 3), slice (0, 1, 3));
        for (int i = 0; i < ms.size1 (); ++ i) 
            for (int j = 0; j < ms.size2 (); ++ j) 
                ms (i, j) = 3 * i + j;
        std::cout << ms << std::endl;
    }

    Definition

    Defined in the header matrix_proxy.hpp.

    Template parameters

    Parameter Description Default
    M The type of matrix referenced.  

    Model of

    Matrix Expression.

    Type requirements

    None, except for those imposed by the requirements of Matrix Expression.

    Public base classes

    matrix_expression<matrix_slice<M> >

    Members

    Member Description
    matrix_slice (matrix_type &data,
     const slice &s1, const slice &s2)
    Constructs a sub matrix.
    size_type size1 () const Returns the number of rows.
    size_type size2 () const Returns the number of columns.
    const_reference operator () (size_type i, size_type j) const Returns the value of the j-th element in the i-th row.
    reference operator () (size_type i, size_type j) Returns a reference of the j-th element in the i-th row.
    matrix_slice &operator = (const matrix_slice &ms) The assignment operator.
    matrix_slice &assign_temporary (matrix_slice &ms) Assigns a temporary. May change the matrix slice ms.
    template<class AE>
    matrix_slice &operator = (const matrix_expression<AE> &ae)
    The extended assignment operator.
    template<class AE>
    matrix_slice &assign (const matrix_expression<AE> &ae)
    Assigns a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_slice &operator += (const matrix_expression<AE> &ae)
    A computed assignment operator. Adds the matrix expression to the sub matrix.
    template<class AE>
    matrix_slice &plus_assign (const matrix_expression<AE> &ae)
    Adds a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AE>
    matrix_slice &operator -= (const matrix_expression<AE> &ae)
    A computed assignment operator. Subtracts the matrix expression from the sub matrix.
    template<class AE>
    matrix_slice &minus_assign (const matrix_expression<AE> &ae)
    Subtracts a matrix expression from the sub matrix. Left and right hand side of the assignment should be independent.
    template<class AT>
    matrix_slice &operator *= (const AT &at)
    A computed assignment operator. Multiplies the sub matrix with a scalar.
    template<class AT>
    matrix_slice &operator /= (const AT &at)
    A computed assignment operator. Multiplies the sub matrix through a scalar.
    void swap (matrix_slice &ms) Swaps the contents of the sub matrices.
    const_iterator1 begin1 () const Returns a const_iterator1 pointing to the beginning of the matrix_slice.
    const_iterator1 end1 () const Returns a const_iterator1 pointing to the end of the matrix_slice.
    iterator1 begin1 () Returns a iterator1 pointing to the beginning of the matrix_slice.
    iterator1 end1 () Returns a iterator1 pointing to the end of the matrix_slice.
    const_iterator2 begin2 () const Returns a const_iterator2 pointing to the beginning of the matrix_slice.
    const_iterator2 end2 () const Returns a const_iterator2 pointing to the end of the matrix_slice.
    iterator2 begin2 () Returns a iterator2 pointing to the beginning of the matrix_slice.
    iterator2 end2 () Returns a iterator2 pointing to the end of the matrix_slice.
    const_reverse_iterator1 rbegin1 () const Returns a const_reverse_iterator1 pointing to the beginning of the reversed matrix_slice.
    const_reverse_iterator1 rend1 () const Returns a const_reverse_iterator1 pointing to the end of the reversed matrix_slice.
    reverse_iterator1 rbegin1 () Returns a reverse_iterator1 pointing to the beginning of the reversed matrix_slice.
    reverse_iterator1 rend1 () Returns a reverse_iterator1 pointing to the end of the reversed matrix_slice.
    const_reverse_iterator2 rbegin2 () const Returns a const_reverse_iterator2 pointing to the beginning of the reversed matrix_slice.
    const_reverse_iterator2 rend2 () const Returns a const_reverse_iterator2 pointing to the end of the reversed matrix_slice.
    reverse_iterator2 rbegin2 () Returns a reverse_iterator2 pointing to the beginning of the reversed matrix_slice.
    reverse_iterator2 rend2 () Returns a reverse_iterator2 pointing to the end of the reversed matrix_slice.

    Interface

        // Matrix based slice class
        template<class M>
        class matrix_slice:
            public matrix_expression<matrix_slice<M> > {
        public:      
            typedef const M const_matrix_type;
            typedef M matrix_type;
            typedef typename M::size_type size_type;
            typedef typename M::difference_type difference_type;
            typedef typename M::value_type value_type;
            typedef typename M::const_reference const_reference;
            typedef typename M::reference reference;
            typedef typename M::const_pointer const_pointer;
            typedef typename M::pointer pointer;
            typedef const matrix_const_reference<const matrix_slice<matrix_type> > const_closure_type;
            typedef matrix_reference<matrix_slice<matrix_type> > closure_type;
            typedef slice::const_iterator const_iterator1_type;
            typedef slice::const_iterator iterator1_type;
            typedef slice::const_iterator const_iterator2_type;
            typedef slice::const_iterator iterator2_type;
            typedef typename storage_restrict_traits<typename M::storage_category,
                                                     dense_proxy_tag>::storage_category storage_category;
            typedef typename M::orientation_category orientation_category;
    
            // Construction and destruction
            matrix_slice ();
            matrix_slice (matrix_type &data, const slice &s1, const slice &s2);
    
            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const_matrix_type &data () const;
            matrix_type &data ();
    
            // Element access
            const_reference operator () (size_type i, size_type j) const;
            reference operator () (size_type i, size_type j);
    
            matrix_slice<matrix_type> project (const range &r1, const range &r2) const;
            matrix_slice<matrix_type> project (const slice &s1, const slice &s2) const;
    
            // Assignment
            matrix_slice &operator = (const matrix_slice &ms);
            matrix_slice &assign_temporary (matrix_slice &ms);
            template<class AE>
            matrix_slice &operator = (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_slice &assign (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_slice& operator += (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_slice &plus_assign (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_slice& operator -= (const matrix_expression<AE> &ae);
            template<class AE>
            matrix_slice &minus_assign (const matrix_expression<AE> &ae);
            template<class AT>
            matrix_slice& operator *= (const AT &at);
            template<class AT>
            matrix_slice& operator /= (const AT &at);
    
            // Swapping
            void swap (matrix_slice &ms);
            friend void swap (matrix_slice &ms1, matrix_slice &ms2);
    
            class const_iterator1;
            class iterator1;
            class const_iterator2;
            class iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base1<iterator1> reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
            typedef reverse_iterator_base2<iterator2> reverse_iterator2;
    
            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            iterator1 find_first1 (int rank, size_type i, size_type j);
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            iterator1 find_last1 (int rank, size_type i, size_type j);
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            iterator2 find_first2 (int rank, size_type i, size_type j);
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
            iterator2 find_last2 (int rank, size_type i, size_type j);
    
            // Iterators simply are indices.
    
            class const_iterator1:
                public container_const_reference<matrix_slice>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename M::const_iterator1::iterator_category iterator_category;
                typedef typename M::const_iterator1::difference_type difference_type;
                typedef typename M::const_iterator1::value_type value_type;
                typedef typename M::const_iterator1::reference reference;
                typedef typename M::const_iterator1::pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;
    
                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_slice &ms, const const_iterator1_type &it1, const const_iterator2_type &it2);
                const_iterator1 (const iterator1 &it);
    
                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;
    
                // Dereference
                reference operator * () const;
    
                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                const_iterator1 &operator = (const const_iterator1 &it);
    
                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };
    
            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;
    
            class iterator1:
                public container_reference<matrix_slice>,
                public random_access_iterator_base<iterator1, value_type> {
            public:
                typedef typename M::iterator1::iterator_category iterator_category;
                typedef typename M::iterator1::difference_type difference_type;
                typedef typename M::iterator1::value_type value_type;
                typedef typename M::iterator1::reference reference;
                typedef typename M::iterator1::pointer pointer;
                typedef iterator2 dual_iterator_type;
                typedef reverse_iterator2 dual_reverse_iterator_type;
    
                // Construction and destruction
                iterator1 ();
                iterator1 (matrix_slice &ms, const iterator1_type &it1, const iterator2_type &it2);
    
                // Arithmetic
                iterator1 &operator ++ ();
                iterator1 &operator -- ();
                iterator1 &operator += (difference_type n);
                iterator1 &operator -= (difference_type n);
                difference_type operator - (const iterator1 &it) const;
    
                // Dereference
                reference operator * () const;
    
                iterator2 begin () const;
                iterator2 end () const;
                reverse_iterator2 rbegin () const;
                reverse_iterator2 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                iterator1 &operator = (const iterator1 &it);
    
                // Comparison
                bool operator == (const iterator1 &it) const;
                bool operator <(const iterator1 &it) const;
            };
    
            iterator1 begin1 ();
            iterator1 end1 ();
    
            class const_iterator2:
                public container_const_reference<matrix_slice>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename M::const_iterator2::iterator_category iterator_category;
                typedef typename M::const_iterator2::difference_type difference_type;
                typedef typename M::const_iterator2::value_type value_type;
                typedef typename M::const_iterator2::reference reference;
                typedef typename M::const_iterator2::pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;
    
                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_slice &ms, const const_iterator1_type &it1, const const_iterator2_type &it2);
                const_iterator2 (const iterator2 &it);
    
                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;
    
                // Dereference
                reference operator * () const;
    
                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                const_iterator2 &operator = (const const_iterator2 &it);
    
                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };
    
            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;
    
            class iterator2:
                public container_reference<matrix_slice>,
                public random_access_iterator_base<iterator2, value_type> {
            public:
                typedef typename M::iterator2::iterator_category iterator_category;
                typedef typename M::iterator2::difference_type difference_type;
                typedef typename M::iterator2::value_type value_type;
                typedef typename M::iterator2::reference reference;
                typedef typename M::iterator2::pointer pointer;
                typedef iterator1 dual_iterator_type;
                typedef reverse_iterator1 dual_reverse_iterator_type;
    
                // Construction and destruction
                iterator2 ();
                iterator2 (matrix_slice &ms, const iterator1_type &it1, const iterator2_type &it2);
    
                // Arithmetic
                iterator2 &operator ++ ();
                iterator2 &operator -- ();
                iterator2 &operator += (difference_type n);
                iterator2 &operator -= (difference_type n);
                difference_type operator - (const iterator2 &it) const;
    
                // Dereference
                reference operator * () const;
    
                iterator1 begin () const;
                iterator1 end () const;
                reverse_iterator1 rbegin () const;
                reverse_iterator1 rend () const;
    
                // Indices
                size_type index1 () const;
                size_type index2 () const;
    
                // Assignment 
                iterator2 &operator = (const iterator2 &it);
    
                // Comparison
                bool operator == (const iterator2 &it) const;
                bool operator <(const iterator2 &it) const;
            };
    
            iterator2 begin2 ();
            iterator2 end2 ();
    
            // Reverse iterators
    
            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;
    
            reverse_iterator1 rbegin1 ();
            reverse_iterator1 rend1 ();
    
            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
    
            reverse_iterator2 rbegin2 ();
            reverse_iterator2 rend2 ();
        };

    Projections

    Prototypes

        template<class M>
        matrix_slice<M> project (const matrix_slice<M> &data, const range &r1, const range &r2);
        template<class M>
        matrix_slice<M> project (M &data, const slice &s1, const slice &s2);
        template<class M>
        const matrix_slice<const M> project (const M &data, const slice &s1, const slice &s2);
        template<class M>
        matrix_slice<M> project (const matrix_slice<M> &data, const slice &s1, const slice &s2);

    Description

    The free project functions support the construction of matrix slices.

    Definition

    Defined in the header matrix_proxy.hpp.

    Type requirements

  • M is a model of Matrix Expression.
  • Preconditions

    Complexity

    Quadratic depending from the size of the slices.

    Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double> m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i) 
            for (int j = 0; j < m.size2 (); ++ j) 
                project (m, slice (0, 1, 3), slice (0, 1, 3)) (i, j) = 3 * i + j;
        std::cout << project (m, slice (0, 1, 3), slice (0, 1, 3)) << std::endl;
    }

    Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
    Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided ``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

    Last revised: 8/3/2002