📄 matrix_proxy.hpp
字号:
template<class M>
typename matrix_column<M>::matrix_type matrix_column<M>::nil_;
// Projections
template<class M>
BOOST_UBLAS_INLINE
matrix_column<M> column (M &data, std::size_t j) {
return matrix_column<M> (data, j);
}
template<class M>
BOOST_UBLAS_INLINE
matrix_column<const M> column_const (const M &data, std::size_t j) {
return matrix_column<const M> (data, j);
}
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template<class M>
BOOST_UBLAS_INLINE
matrix_column<M> column (const M &data, std::size_t j) {
return matrix_column<M> (const_cast<M &> (data), j);
}
#endif
// Matrix based vector range class
template<class M>
class matrix_vector_range:
public vector_expression<matrix_vector_range<M> > {
public:
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
BOOST_UBLAS_USING vector_expression<matrix_vector_range<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_vector_range<matrix_type> const_self_type;
typedef matrix_vector_range<matrix_type> self_type;
typedef const_self_type const_closure_type;
typedef self_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
BOOST_UBLAS_INLINE
matrix_vector_range ():
data_ (nil_), r1_ (), r2_ () {}
BOOST_UBLAS_INLINE
matrix_vector_range (matrix_type &data, const range &r1, const range &r2):
data_ (data), r1_ (r1.preprocess (data.size1 ())), r2_ (r2.preprocess (data.size2 ())) {
// Early checking of preconditions.
BOOST_UBLAS_CHECK (r1_.start () <= data_.size1 () &&
r1_.start () + r1_.size () <= data_.size1 (), bad_index ());
BOOST_UBLAS_CHECK (r2_.start () <= data_.size2 () &&
r2_.start () + r2_.size () <= data_.size2 (), bad_index ());
BOOST_UBLAS_CHECK (r1_.size () == r2_.size (), bad_size ());
}
// Accessors
BOOST_UBLAS_INLINE
size_type start1 () const {
return r1_.start ();
}
BOOST_UBLAS_INLINE
size_type start2 () const {
return r2_.start ();
}
BOOST_UBLAS_INLINE
size_type size () const {
return BOOST_UBLAS_SAME (r1_.size (), r2_.size ());
}
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, const range &r1, const range &r2) {
// data_ = data;
data_.reset (data);
r1_ = r1;
r2_ = r2;
}
#endif
// Element access
#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
BOOST_UBLAS_INLINE
const_reference operator () (size_type i) const {
return data () (r1_ (i), r2_ (i));
}
BOOST_UBLAS_INLINE
reference operator () (size_type i) {
return data () (r1_ (i), r2_ (i));
}
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 () (r1_ (i), r2_ (i));
}
BOOST_UBLAS_INLINE
reference operator [] (size_type i) const {
return (*this) (i);
}
#endif
// Assignment
BOOST_UBLAS_INLINE
matrix_vector_range &operator = (const matrix_vector_range &mvr) {
// FIXME: the ranges could be differently sized.
// std::copy (mvr.begin (), mvr.end (), begin ());
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (mvr));
return *this;
}
BOOST_UBLAS_INLINE
matrix_vector_range &assign_temporary (matrix_vector_range &mvr) {
// FIXME: this is suboptimal.
// return *this = mvr;
vector_assign (scalar_assign<reference, value_type> (), *this, mvr);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &operator = (const vector_expression<AE> &ae) {
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &assign (const vector_expression<AE> &ae) {
vector_assign (scalar_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &operator += (const vector_expression<AE> &ae) {
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (*this + ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &plus_assign (const vector_expression<AE> &ae) {
vector_assign (scalar_plus_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &operator -= (const vector_expression<AE> &ae) {
vector_assign (scalar_assign<reference, value_type> (), *this, vector<value_type> (*this - ae));
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
matrix_vector_range &minus_assign (const vector_expression<AE> &ae) {
vector_assign (scalar_minus_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
matrix_vector_range &operator *= (const AT &at) {
vector_assign_scalar (scalar_multiplies_assign<reference, AT> (), *this, at);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
matrix_vector_range &operator /= (const AT &at) {
vector_assign_scalar (scalar_divides_assign<reference, AT> (), *this, at);
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const matrix_vector_range &mvr) const {
return (*this).data () == mvr.data () && r1_ == mvr.r1_ && r2_ == mvr.r2_;
}
// Swapping
BOOST_UBLAS_INLINE
void swap (matrix_vector_range mvr) {
// Too unusual semantic.
// BOOST_UBLAS_CHECK (this != &mvr, external_logic ());
if (this != &mvr) {
BOOST_UBLAS_CHECK (size () == mvr.size (), bad_size ());
// Sparse ranges may be nonconformant now.
// std::swap_ranges (begin (), end (), mvr.begin ());
vector_swap (scalar_swap<reference, reference> (), *this, mvr);
}
}
#ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS
BOOST_UBLAS_INLINE
friend void swap (matrix_vector_range mvr1, matrix_vector_range mvr2) {
mvr1.swap (mvr2);
}
#endif
class const_iterator;
class iterator;
// Element lookup
BOOST_UBLAS_INLINE
const_iterator find (size_type i) const {
return const_iterator (*this, r1_.begin () + i, r2_.begin () + i);
}
BOOST_UBLAS_INLINE
iterator find (size_type i) {
return iterator (*this, r1_.begin () + i, r2_.begin () + i);
}
// Iterators simply are indices.
class const_iterator:
public container_const_reference<matrix_vector_range>,
#ifdef BOOST_UBLAS_USE_ITERATOR_BASE_TRAITS
public iterator_base_traits<typename iterator_restrict_traits<typename M::const_iterator1::iterator_category,
typename M::const_iterator2::iterator_category>::iterator_category>::template
iterator_base<const_iterator, value_type>::type {
#else
public random_access_iterator_base<typename iterator_restrict_traits<typename M::const_iterator1::iterator_category,
typename M::const_iterator2::iterator_category>::iterator_category,
const_iterator, value_type> {
#endif
public:
typedef typename iterator_restrict_traits<typename M::const_iterator1::iterator_category,
typename M::const_iterator2::iterator_category>::iterator_category iterator_category;
#ifdef BOOST_MSVC_STD_ITERATOR
typedef const_reference reference;
#else
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;
#endif
// Construction and destruction
BOOST_UBLAS_INLINE
const_iterator ():
container_const_reference<self_type> (), it1_ (), it2_ () {}
BOOST_UBLAS_INLINE
const_iterator (const self_type &mvr, const const_iterator1_type &it1, const const_iterator2_type &it2):
container_const_reference<self_type> (mvr), it1_ (it1), it2_ (it2) {}
#ifndef BOOST_UBLAS_QUALIFIED_TYPENAME
BOOST_UBLAS_INLINE
const_iterator (const iterator &it):
container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
#else
BOOST_UBLAS_INLINE
const_iterator (const typename self_type::iterator &it):
container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
#endif
// Arithmetic
BOOST_UBLAS_INLINE
const_iterator &operator ++ () {
++ it1_;
++ it2_;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator -- () {
-- it1_;
-- it2_;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator += (difference_type n) {
it1_ += n;
it2_ += n;
return *this;
}
BOOST_UBLAS_INLINE
const_iterator &operator -= (difference_type n) {
it1_ -= n;
it2_ -= n;
return *this;
}
BOOST_UBLAS_INLINE
difference_type operator - (const const_iterator &it) const {
BOOST_UBLAS_CHECK ((*this) () == it (), external_logic ());
return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
return (*this) ().data () (*it1_, *it2_);
}
// Index
BOOST_UBLAS_INLINE
size_type index () const {
return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator &operator = (const const_iterator &it) {
container_const_reference<self_type>::assign (&it ());
it1_ = it.it1_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -