📄 matrix_proxy.hpp
字号:
return it_.index2 ();
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator &operator = (const const_iterator &it) {
container_const_reference<self_type>::assign (&it ());
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const const_iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return it_ == it.it_;
}
BOOST_UBLAS_INLINE
bool operator < (const const_iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return it_ < it.it_;
}
private:
const_iterator_type it_;
};
#endif
BOOST_UBLAS_INLINE
const_iterator begin () const {
return find (0);
}
BOOST_UBLAS_INLINE
const_iterator end () const {
return find (size ());
}
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
class iterator:
public container_reference<matrix_row>,
#ifdef BOOST_UBLAS_USE_ITERATOR_BASE_TRAITS
public iterator_base_traits<typename iterator_type::iterator_category>::template
iterator_base<iterator, value_type>::type {
#else
public random_access_iterator_base<typename iterator_type::iterator_category,
iterator, value_type> {
#endif
public:
typedef typename iterator_type::iterator_category iterator_category;
typedef typename iterator_type::difference_type difference_type;
typedef typename iterator_type::value_type value_type;
typedef typename iterator_type::reference reference;
typedef typename iterator_type::pointer pointer;
// Construction and destruction
BOOST_UBLAS_INLINE
iterator ():
container_reference<self_type> (), it_ () {}
BOOST_UBLAS_INLINE
iterator (self_type &mr, const iterator_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) () == it (), external_logic ());
return it_ - it.it_;
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
return *it_;
}
// 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) () == it (), external_logic ());
return it_ == it.it_;
}
BOOST_UBLAS_INLINE
bool operator < (const iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return it_ < it.it_;
}
private:
iterator_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
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base<const_iterator, value_type, const_reference> const_reverse_iterator;
#else
typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
#endif
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 ());
}
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base<iterator, value_type, reference> reverse_iterator;
#else
typedef reverse_iterator_base<iterator> reverse_iterator;
#endif
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_;
static matrix_type nil_;
};
template<class M>
typename matrix_row<M>::matrix_type matrix_row<M>::nil_;
// Projections
template<class M>
BOOST_UBLAS_INLINE
matrix_row<M> row (M &data, std::size_t i) {
return matrix_row<M> (data, i);
}
template<class M>
BOOST_UBLAS_INLINE
matrix_row<const M> row_const (const M &data, std::size_t i) {
return matrix_row<const M> (data, i);
}
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template<class M>
BOOST_UBLAS_INLINE
matrix_row<M> row (const M &data, std::size_t i) {
return matrix_row<M> (const_cast<M &> (data), i);
}
#endif
// Matrix based column vector class
template<class M>
class matrix_column:
public vector_expression<matrix_column<M> > {
public:
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
BOOST_UBLAS_USING vector_expression<matrix_column<M> >::operator ();
#endif
typedef const M const_matrix_type;
typedef M matrix_type;
typedef typename M::simd_category simd_category;
typedef typename M::size_type size_type;
typedef typename M::difference_type difference_type;
typedef typename M::value_type value_type;
#ifndef BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS
typedef typename M::const_reference const_reference;
typedef typename M::reference reference;
typedef typename M::const_pointer const_pointer;
typedef typename M::pointer pointer;
#else
typedef typename M::const_reference const_reference;
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_reference,
typename M::reference>::type reference;
typedef typename M::const_pointer const_pointer;
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_pointer,
typename M::pointer>::type pointer;
#endif
#ifndef BOOST_UBLAS_CT_PROXY_CLOSURE_TYPEDEFS
typedef typename M::closure_type matrix_closure_type;
#else
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_closure_type,
typename M::closure_type>::type matrix_closure_type;
#endif
typedef const matrix_column<matrix_type> const_self_type;
typedef matrix_column<matrix_type> self_type;
typedef const_self_type const_closure_type;
typedef self_type closure_type;
#ifndef BOOST_UBLAS_CT_PROXY_BASE_TYPEDEFS
typedef typename M::const_iterator1 const_iterator_type;
typedef typename M::iterator1 iterator_type;
#else
typedef typename M::const_iterator1 const_iterator_type;
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_iterator1,
typename M::iterator1>::type iterator_type;
#endif
typedef typename storage_restrict_traits<typename M::storage_category,
dense_proxy_tag>::storage_category storage_category;
// Construction and destruction
BOOST_UBLAS_INLINE
matrix_column ():
data_ (nil_), j_ () {}
BOOST_UBLAS_INLINE
matrix_column (matrix_type &data, size_type j):
data_ (data), j_ (j) {
// Early checking of preconditions.
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_;
}
BOOST_UBLAS_INLINE
const matrix_closure_type &data () const {
return data_;
}
BOOST_UBLAS_INLINE
matrix_closure_type &data () {
return data_;
}
#ifdef BOOST_UBLAS_DEPRECATED
// Resetting
BOOST_UBLAS_INLINE
void reset (matrix_type &data) {
// data_ = data;
data_.reset (data);
}
BOOST_UBLAS_INLINE
void reset (matrix_type &data, size_type j) {
// data_ = data;
data_.reset (data);
j_ = j;
}
#endif
// 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) {
// FIXME: the columns could be differently sized.
// std::copy (mc.begin (), mc.end (), begin ());
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (mc));
return *this;
}
BOOST_UBLAS_INLINE
matrix_column &assign_temporary (matrix_column &mc) {
// FIXME: this is suboptimal.
// return *this = mc;
vector_assign (scalar_assign<reference, value_type> (), *this, mc);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_column &operator = (const vector_expression<AE> &ae) {
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (ae));
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -