📄 symmetric.hpp
字号:
reverse_iterator2 rend2 () {
return reverse_iterator2 (begin2 ());
}
private:
size_type size_;
array_type data_;
};
// Symmetric matrix adaptor class
template<class M, class F>
class symmetric_adaptor:
public matrix_expression<symmetric_adaptor<M, F> > {
public:
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
BOOST_UBLAS_USING matrix_expression<symmetric_adaptor<M, F> >::operator ();
#endif
typedef const M const_matrix_type;
typedef M matrix_type;
typedef F functor_type;
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 symmetric_adaptor<M, F> const_self_type;
typedef symmetric_adaptor<M, F> 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_iterator1_type;
typedef typename M::iterator1 iterator1_type;
typedef typename M::const_iterator2 const_iterator2_type;
typedef typename M::iterator2 iterator2_type;
#else
typedef typename M::const_iterator1 const_iterator1_type;
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_iterator1,
typename M::iterator1>::type iterator1_type;
typedef typename M::const_iterator2 const_iterator2_type;
typedef typename boost::mpl::if_c<boost::is_const<M>::value,
typename M::const_iterator2,
typename M::iterator2>::type iterator2_type;
#endif
typedef typename storage_restrict_traits<typename M::storage_category,
packed_proxy_tag>::storage_category storage_category;
typedef typename F::packed_category packed_category;
typedef typename M::orientation_category orientation_category;
// Construction and destruction
BOOST_UBLAS_INLINE
symmetric_adaptor ():
matrix_expression<self_type> (),
data_ (nil_) {
BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
}
BOOST_UBLAS_INLINE
symmetric_adaptor (matrix_type &data):
matrix_expression<self_type> (),
data_ (data) {
BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
}
BOOST_UBLAS_INLINE
symmetric_adaptor (const symmetric_adaptor &m):
matrix_expression<self_type> (),
data_ (m.data_) {
BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
}
// Accessors
BOOST_UBLAS_INLINE
size_type size1 () const {
return data_.size1 ();
}
BOOST_UBLAS_INLINE
size_type size2 () const {
return data_.size2 ();
}
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) {
BOOST_UBLAS_CHECK (data.size1 () == data.size2 (), bad_size ());
// References are not retargetable.
// Thanks to Michael Stevens for spotting this.
// data_ = data;
data_.reset (data);
}
#endif
// Element access
#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
BOOST_UBLAS_INLINE
const_reference operator () (size_type i, size_type j) const {
BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
if (functor_type::other (i, j))
return data () (i, j);
else
return data () (j, i);
}
BOOST_UBLAS_INLINE
reference operator () (size_type i, size_type j) {
BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
if (functor_type::other (i, j))
return data () (i, j);
else
return data () (j, i);
}
#else
BOOST_UBLAS_INLINE
reference operator () (size_type i, size_type j) const {
BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
if (functor_type::other (i, j))
return data () (i, j);
else
return data () (j, i);
}
#endif
// Assignment
BOOST_UBLAS_INLINE
symmetric_adaptor &operator = (const symmetric_adaptor &m) {
matrix_assign (scalar_assign<reference, value_type> (), *this, m, functor_type ());
return *this;
}
BOOST_UBLAS_INLINE
symmetric_adaptor &assign_temporary (symmetric_adaptor &m) {
*this = m;
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor &operator = (const matrix_expression<AE> &ae) {
matrix_assign (scalar_assign<reference, value_type> (), *this, matrix<value_type> (ae), functor_type ());
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor &assign (const matrix_expression<AE> &ae) {
matrix_assign (scalar_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae, functor_type ());
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor& operator += (const matrix_expression<AE> &ae) {
matrix_assign (scalar_assign<reference, value_type> (), *this, matrix<value_type> (*this + ae), functor_type ());
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor &plus_assign (const matrix_expression<AE> &ae) {
matrix_assign (scalar_plus_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae, functor_type ());
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor& operator -= (const matrix_expression<AE> &ae) {
matrix_assign (scalar_assign<reference, value_type> (), *this, matrix<value_type> (*this - ae), functor_type ());
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
symmetric_adaptor &minus_assign (const matrix_expression<AE> &ae) {
matrix_assign (scalar_minus_assign<reference, BOOST_UBLAS_TYPENAME AE::value_type> (), *this, ae, functor_type ());
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
symmetric_adaptor& operator *= (const AT &at) {
matrix_assign_scalar (scalar_multiplies_assign<reference, AT> (), *this, at);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
symmetric_adaptor& operator /= (const AT &at) {
matrix_assign_scalar (scalar_divides_assign<reference, AT> (), *this, at);
return *this;
}
// Comparison
bool operator == (const symmetric_adaptor &sa) const {
return (*this).data () == sa.data ();
}
// Swapping
BOOST_UBLAS_INLINE
void swap (symmetric_adaptor &m) {
// Too unusual semantic
// BOOST_UBLAS_CHECK (this != &m, external_logic ());
if (this != &m)
matrix_swap (scalar_swap<reference, reference> (), *this, m, functor_type ());
}
#ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS
BOOST_UBLAS_INLINE
friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) {
m1.swap (m2);
}
#endif
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
#else
class const_iterator1;
class iterator1;
class const_iterator2;
class iterator2;
#endif
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base1<const_iterator1, value_type, const_reference> const_reverse_iterator1;
typedef reverse_iterator_base1<iterator1, value_type, reference> reverse_iterator1;
typedef reverse_iterator_base2<const_iterator2, value_type, const_reference> const_reverse_iterator2;
typedef reverse_iterator_base2<iterator2, value_type, reference> reverse_iterator2;
#else
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;
#endif
// Element lookup
BOOST_UBLAS_INLINE
const_iterator1 find1 (int rank, size_type i, size_type j) const {
if (functor_type::other (i, j)) {
if (functor_type::other (size1 (), j)) {
return const_iterator1 (*this, 0, 0,
data ().find1 (rank, i, j), data ().find1 (rank, size1 (), j),
data ().find2 (rank, size2 (), size1 ()), data ().find2 (rank, size2 (), size1 ()));
} else {
return const_iterator1 (*this, 0, 1,
data ().find1 (rank, i, j), data ().find1 (rank, j, j),
data ().find2 (rank, j, j), data ().find2 (rank, j, size1 ()));
}
} else {
if (functor_type::other (size1 (), j)) {
return const_iterator1 (*this, 1, 0,
data ().find1 (rank, j, j), data ().find1 (rank, size1 (), j),
data ().find2 (rank, j, i), data ().find2 (rank, j, j));
} else {
return const_iterator1 (*this, 1, 1,
data ().find1 (rank, size1 (), size2 ()), data ().find1 (rank, size1 (), size2 ()),
data ().find2 (rank, j, i), data ().find2 (rank, j, size1 ()));
}
}
}
BOOST_UBLAS_INLINE
iterator1 find1 (int rank, size_type i, size_type j) {
if (rank == 1)
i = functor_type::restrict1 (i, j);
return iterator1 (*this, data ().find1 (rank, i, j));
}
BOOST_UBLAS_INLINE
const_iterator2 find2 (int rank, size_type i, size_type j) const {
if (functor_type::other (i, j)) {
if (functor_type::other (i, size2 ())) {
return const_iterator2 (*this, 1, 1,
data ().find1 (rank, size2 (), size1 ()), data ().find1 (rank, size2 (), size1 ()),
data ().find2 (rank, i, j), data ().find2 (rank, i, size2 ()));
} else {
return const_iterator2 (*this, 1, 0,
data ().find1 (rank, i, i), data ().find1 (rank, size2 (), i),
data ().find2 (rank, i, j), data ().find2 (rank, i, i));
}
} else {
if (functor_type::other (i, size2 ())) {
return const_iterator2 (*this, 0, 1,
data ().find1 (rank, j, i), data ().find1 (rank, i, i),
data ().find2 (rank, i, i), data ().find2 (rank, i, size2 ()));
} else {
return const_iterator2 (*this, 0, 0,
data ().find1 (rank, j, i), data ().find1 (rank, size2 (), i),
data ().find2 (rank, size1 (), size2 ()), data ().find2 (rank, size2 (), size2 ()));
}
}
}
BOOST_UBLAS_INLINE
iterator2 find2 (int rank, size_type i, size_type j) {
if (rank == 1)
j = functor_type::restrict2 (i, j);
return iterator2 (*this, data ().find2 (rank, i, j));
}
// Iterators simply are indices.
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -