📄 matrix_proxy.hpp
字号:
typedef typename subiterator_type::difference_type difference_type;
typedef typename subiterator_type::reference reference;
typedef typename subiterator_type::pointer pointer;
// Construction and destruction
BOOST_UBLAS_INLINE
iterator ():
container_reference<self_type> (), it_ () {}
BOOST_UBLAS_INLINE
iterator (self_type &mr, const subiterator_type &it):
container_reference<self_type> (mr), it_ (it) {}
// Arithmetic
BOOST_UBLAS_INLINE
iterator &operator ++ () {
++ it_;
return *this;
}
BOOST_UBLAS_INLINE
iterator &operator -- () {
-- it_;
return *this;
}
BOOST_UBLAS_INLINE
iterator &operator += (difference_type n) {
it_ += n;
return *this;
}
BOOST_UBLAS_INLINE
iterator &operator -= (difference_type n) {
it_ -= n;
return *this;
}
BOOST_UBLAS_INLINE
difference_type operator - (const iterator &it) const {
BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
return it_ - it.it_;
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
return *it_;
}
BOOST_UBLAS_INLINE
reference operator [] (difference_type n) const {
return *(*this + n);
}
// Index
BOOST_UBLAS_INLINE
size_type index () const {
return it_.index2 ();
}
// Assignment
BOOST_UBLAS_INLINE
iterator &operator = (const iterator &it) {
container_reference<self_type>::assign (&it ());
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const iterator &it) const {
BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
return it_ == it.it_;
}
BOOST_UBLAS_INLINE
bool operator < (const iterator &it) const {
BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
return it_ < it.it_;
}
private:
subiterator_type it_;
friend class const_iterator;
};
#endif
BOOST_UBLAS_INLINE
iterator begin () {
return find (0);
}
BOOST_UBLAS_INLINE
iterator end () {
return find (size ());
}
// Reverse iterator
typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
typedef reverse_iterator_base<iterator> reverse_iterator;
BOOST_UBLAS_INLINE
const_reverse_iterator rbegin () const {
return const_reverse_iterator (end ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator rend () const {
return const_reverse_iterator (begin ());
}
BOOST_UBLAS_INLINE
reverse_iterator rbegin () {
return reverse_iterator (end ());
}
BOOST_UBLAS_INLINE
reverse_iterator rend () {
return reverse_iterator (begin ());
}
private:
matrix_closure_type data_;
size_type i_;
};
// Projections
template<class M>
BOOST_UBLAS_INLINE
matrix_row<M> row (M &data, typename M::size_type i) {
return matrix_row<M> (data, i);
}
template<class M>
BOOST_UBLAS_INLINE
const matrix_row<const M> row (const M &data, typename M::size_type i) {
return matrix_row<const M> (data, i);
}
// Specialize temporary
template <class M>
struct vector_temporary_traits< matrix_row<M> >
: vector_temporary_traits< M > {} ;
template <class M>
struct vector_temporary_traits< const matrix_row<M> >
: vector_temporary_traits< M > {} ;
// Matrix based column vector class
template<class M>
class matrix_column:
public vector_expression<matrix_column<M> > {
typedef matrix_column<M> self_type;
public:
#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
using vector_expression<self_type>::operator ();
#endif
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 boost::mpl::if_<boost::is_const<M>,
typename M::const_reference,
typename M::reference>::type reference;
typedef typename boost::mpl::if_<boost::is_const<M>,
typename M::const_closure_type,
typename M::closure_type>::type matrix_closure_type;
typedef const self_type const_closure_type;
typedef self_type closure_type;
typedef typename storage_restrict_traits<typename M::storage_category,
dense_proxy_tag>::storage_category storage_category;
// Construction and destruction
BOOST_UBLAS_INLINE
matrix_column (matrix_type &data, size_type j):
data_ (data), j_ (j) {
// Early checking of preconditions here.
// BOOST_UBLAS_CHECK (j_ < data_.size2 (), bad_index ());
}
// Accessors
BOOST_UBLAS_INLINE
size_type size () const {
return data_.size1 ();
}
BOOST_UBLAS_INLINE
size_type index () const {
return j_;
}
// Storage accessors
BOOST_UBLAS_INLINE
const matrix_closure_type &data () const {
return data_;
}
BOOST_UBLAS_INLINE
matrix_closure_type &data () {
return data_;
}
// Element access
#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
BOOST_UBLAS_INLINE
const_reference operator () (size_type i) const {
return data_ (i, j_);
}
BOOST_UBLAS_INLINE
reference operator () (size_type i) {
return data_ (i, j_);
}
BOOST_UBLAS_INLINE
const_reference operator [] (size_type i) const {
return (*this) (i);
}
BOOST_UBLAS_INLINE
reference operator [] (size_type i) {
return (*this) (i);
}
#else
BOOST_UBLAS_INLINE
reference operator () (size_type i) const {
return data_ (i, j_);
}
BOOST_UBLAS_INLINE
reference operator [] (size_type i) const {
return (*this) (i);
}
#endif
// Assignment
BOOST_UBLAS_INLINE
matrix_column &operator = (const matrix_column &mc) {
// ISSUE need a temporary, proxy can be overlaping alias
vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mc));
return *this;
}
BOOST_UBLAS_INLINE
matrix_column &assign_temporary (matrix_column &mc) {
// assign elements, proxied container remains the same
vector_assign<scalar_assign> (*this, mc);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &operator = (const vector_expression<AE> &ae) {
vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &assign (const vector_expression<AE> &ae) {
vector_assign<scalar_assign> (*this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &operator += (const vector_expression<AE> &ae) {
vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &plus_assign (const vector_expression<AE> &ae) {
vector_assign<scalar_plus_assign> (*this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &operator -= (const vector_expression<AE> &ae) {
vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &minus_assign (const vector_expression<AE> &ae) {
vector_assign<scalar_minus_assign> (*this, ae);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
matrix_column &operator *= (const AT &at) {
vector_assign_scalar<scalar_multiplies_assign> (*this, at);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
matrix_column &operator /= (const AT &at) {
vector_assign_scalar<scalar_divides_assign> (*this, at);
return *this;
}
// Closure comparison
BOOST_UBLAS_INLINE
bool same_closure (const matrix_column &mc) const {
return (*this).data_.same_closure (mc.data_);
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const matrix_column &mc) const {
return (*this).data_ == mc.data_ && index () == mc.index ();
}
// Swapping
BOOST_UBLAS_INLINE
void swap (matrix_column mc) {
if (this != &mc) {
BOOST_UBLAS_CHECK (size () == mc.size (), bad_size ());
// Sparse ranges may be nonconformant now.
// std::swap_ranges (begin (), end (), mc.begin ());
vector_swap<scalar_swap> (*this, mc);
}
}
BOOST_UBLAS_INLINE
friend void swap (matrix_column mc1, matrix_column mc2) {
mc1.swap (mc2);
}
// Iterator types
private:
typedef typename M::const_iterator1 const_subiterator_type;
typedef typename boost::mpl::if_<boost::is_const<M>,
typename M::const_iterator1,
typename M::iterator1>::type subiterator_type;
public:
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
typedef indexed_iterator<matrix_column<matrix_type>,
typename subiterator_type::iterator_category> iterator;
typedef indexed_const_iterator<matrix_column<matrix_type>,
typename const_subiterator_type::iterator_category> const_iterator;
#else
class const_iterator;
class iterator;
#endif
// Element lookup
BOOST_UBLAS_INLINE
const_iterator find (size_type i) const {
const_subiterator_type it1 (data_.find1 (1, i, j_));
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
return const_iterator (*this, it1.index1 ());
#else
return const_iterator (*this, it1);
#endif
}
BOOST_UBLAS_INLINE
iterator find (size_type i) {
subiterator_type it1 (data_.find1 (1, i, j_));
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
return iterator (*this, it1.index1 ());
#else
return iterator (*this, it1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -