boost::ubals之vetctor proxies

1 Vector Range

1.1 Description

The templated class vector_range<V> allowsaddressing a sub-range of a vector's element.

1.2 Example
#include <boost/numeric/ublas/vector.hpp> //通过range的范围来确定其子向量。
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    vector<double> v (3);
    vector_range<vector<double> > vr (v, range (0, 3));
    for (unsigned i = 0; i < vr.size (); ++ i)
        vr (i) = i;
    std::cout << vr << std::endl;
}


1.3 Definition

Defined in the header vector_proxy.hpp.

1.4 Template parameters
ParameterDescriptionDefault
VThe type of vector referenced. 
1.5 Model of

Vector Expression.

If the specified range falls outside that of the index range ofthe vector, then the vector_range is not a well formedVector Expression. That is, access to an element which is outsideof index range of the vector is undefined.

1.6 Type requirements

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

1.7 Public base classes

vector_expression<vector_range<V> >

1.8 Members
MemberDescription
vector_range (vector_type &data, const range&r)Constructs a sub vector.
size_type start () constReturns the start of the sub vector.
size_type size () constReturns the size of the sub vector.
const_reference operator () (size_type i)constReturns the value of the i-th element.
reference operator () (size_type i)Returns a reference of the i-th element.
const_reference operator [] (size_type i)constReturns the value of the i-th element.
reference operator [] (size_type i)Returns a reference of the i-th element.
vector_range &operator = (const vector_range&vr)The assignment operator.
vector_range &assign_temporary (vector_range&vr)Assigns a temporary. May change the vector rangevr .
template<class AE>
vector_range &operator = (const vector_expression<AE>&ae)
The extended assignment operator.
template<class AE>
vector_range &assign (const vector_expression<AE>&ae)
Assigns a vector expression to the sub vector. Left and righthand side of the assignment should be independent.
template<class AE>
vector_range &operator += (const vector_expression<AE>&ae)
A computed assignment operator. Adds the vector expression tothe sub vector.
template<class AE>
vector_range &plus_assign (const vector_expression<AE>&ae)
Adds a vector expression to the sub vector. Left and right handside of the assignment should be independent.
template<class AE>
vector_range &operator -= (const vector_expression<AE>&ae)
A computed assignment operator. Subtracts the vector expressionfrom the sub vector.
template<class AE>
vector_range &minus_assign (const vector_expression<AE>&ae)
Subtracts a vector expression from the sub vector. Left andright hand side of the assignment should be independent.
template<class AT>
vector_range &operator *= (const AT &at)
A computed assignment operator. Multiplies the sub vector witha scalar.
template<class AT>
vector_range &operator /= (const AT &at)
A computed assignment operator. Divides the sub vector througha scalar.
void swap (vector_range &vr)Swaps the contents of the sub vectors.
const_iterator begin () constReturns a const_iterator pointing to the beginningof the vector_range.
const_iterator end () constReturns a const_iterator pointing to the end ofthe vector_range.
iterator begin ()Returns a iterator pointing to the beginning ofthe vector_range.
iterator end ()Returns a iterator pointing to the end of thevector_range.
const_reverse_iterator rbegin () constReturns a const_reverse_iterator pointing to thebeginning of the reversed vector_range.
const_reverse_iterator rend () constReturns a const_reverse_iterator pointing to theend of the reversed vector_range.
reverse_iterator rbegin ()Returns a reverse_iterator pointing to thebeginning of the reversed vector_range.
reverse_iterator rend ()Returns a reverse_iterator pointing to the end ofthe reversed vector_range.

1.1 Simple Projections

1.1.1 Description

The free subrange functions support the constructionof vector ranges.

1.1.2 Prototypes
    template<class V>     //说的是如何利用subrange来构造vector_range, 并且subrange为函数
    vector_range<V> subrange (V &data,
       V::size_type start, V::size_type stop);
    template<class V>
    const vector_range<const V> subrange (const V &data,
       V::size_type start, V::size_type stop);

1.2 Generic Projections

1.2.1 Description

The free project functions support the constructionof vector ranges. Existing matrix_range's can be composed with a further range. The resulting range is computed using this existing range's compose function.

1.2.2 Prototypes
    template<class V> //通过投射关系来建立vector_range.
    vector_range<V> project (V &data, const range &r);
    template<class V>
    const vector_range<const V> project (const V &data, const range &r);
    template<class V>
    vector_range<V> project (vector_range<V> &data, const range &r);
    template<class V>
    const vector_range<V> project (const vector_range<V> &data, const range &r);

1.2.3 Definition

Defined in the header vector_proxy.hpp.

1.2.4 Type requirements
1.2.5 Complexity

Linear depending from the size of the range.

1.2.6 Examples
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    vector<double> v (3);
    for (int i = 0; i < 3; ++ i)
        project (v, range (0, 3)) (i) = i; //这是通过投射关系建立vector_range后,并给予其赋值
    std::cout << project (v, range (0, 3)) << std::endl;
}

2 Vector Slice  //下面的slice 调用,和之前的range几乎相同,两者的差异只是slice设置步长以及元素个数

2.1 Description

The templated class vector_slice<V> allowsaddressing a slice of a vector.

2.2 Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    vector<double> v (3);
    vector_slice<vector<double> > vs (v, slice (0, 1, 3));
    for (unsigned i = 0; i < vs.size (); ++ i)
        vs (i) = i;
    std::cout << vs << std::endl;
}
2.3 Definition

Defined in the header vector_proxy.hpp.

2.4 Template parameters
ParameterDescriptionDefault
VThe type of vector referenced. 
2.5 Model of

Vector Expression.

If the specified slice falls outside that of the index range ofthe vector, then the vector_slice is not a well formedVector Expression. That is, access to an element which is outsideof index range of the vector is undefined.

2.6 Type requirements

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

2.7 Public base classes

vector_expression<vector_slice<V> >

2.8 Members
MemberDescription
vector_slice (vector_type &data, const slice&s)Constructs a sub vector.
size_type size () constReturns the size of the sub vector.
const_reference operator () (size_type i)constReturns the value of the i-th element.
reference operator () (size_type i)Returns a reference of the i-th element.
const_reference operator [] (size_type i)constReturns the value of the i-th element.
reference operator [] (size_type i)Returns a reference of the i-th element.
vector_slice &operator = (const vector_slice&vs)The assignment operator.
vector_slice &assign_temporary (vector_slice&vs)Assigns a temporary. May change the vector slicevs .
template<class AE>
vector_slice &operator = (const vector_expression<AE>&ae)
The extended assignment operator.
template<class AE>
vector_slice &assign (const vector_expression<AE>&ae)
Assigns a vector expression to the sub vector. Left and righthand side of the assignment should be independent.
template<class AE>
vector_slice &operator += (const vector_expression<AE>&ae)
A computed assignment operator. Adds the vector expression tothe sub vector.
template<class AE>
vector_slice &plus_assign (const vector_expression<AE>&ae)
Adds a vector expression to the sub vector. Left and right handside of the assignment should be independent.
template<class AE>
vector_slice &operator -= (const vector_expression<AE>&ae)
A computed assignment operator. Subtracts the vector expressionfrom the sub vector.
template<class AE>
vector_slice &minus_assign (const vector_expression<AE>&ae)
Subtracts a vector expression from the sub vector. Left andright hand side of the assignment should be independent.
template<class AT>
vector_slice &operator *= (const AT &at)
A computed assignment operator. Multiplies the sub vector witha scalar.
template<class AT>
vector_slice &operator /= (const AT &at)
A computed assignment operator. Divides the sub vector througha scalar.
void swap (vector_slice &vs)Swaps the contents of the sub vectors.
const_iterator begin () constReturns a const_iterator pointing to the beginningof the vector_slice.
const_iterator end () constReturns a const_iterator pointing to the end ofthe vector_slice.
iterator begin ()Returns a iterator pointing to the beginning ofthe vector_slice.
iterator end ()Returns a iterator pointing to the end of thevector_slice.
const_reverse_iterator rbegin () constReturns a const_reverse_iterator pointing to thebeginning of the reversed vector_slice.
const_reverse_iterator rend () constReturns a const_reverse_iterator pointing to theend of the reversed vector_slice.
reverse_iterator rbegin ()Returns a reverse_iterator pointing to thebeginning of the reversed vector_slice.
reverse_iterator rend ()Returns a reverse_iterator pointing to the end ofthe reversed vector_slice.

2.1 Simple Projections

2.1.1 Description

The free subslice functions support the constructionof vector slices.

2.1.2 Prototypes

   
 template<class V>
    vector_slice<V> subslice (V &data,
       V::size_type start, V::difference_type stride, V::size_type size);
    template<class V>
    const vector_slice<const V> subslice (const V &data,
       V::size_type start, V::difference_type stride, V::size_type size);

2.2 Generic Projections

2.2.1 Description

The free project functions support the constructionof vector slices. Existing vector_slice's can be composed with a further range or slices. The resulting slice is computed using this existing slices's compose function.

2.2.2 Prototypes

   
 
 template<class V>
    vector_slice<V> project (V &data, const slice &s);
    template<class V>
    const vector_slice<const V> project (const V &data, const slice &s);
    template<class V>
    vector_slice<V> project (vector_slice<V> &data, const range &r);
    template<class V>
    const vector_slice<V> project (const vector_slice<V> &data, const range &r);
    template<class V>
    vector_slice<V> project (vector_slice<V> &data, const slice &s);
    template<class V>
    const vector_slice<V> project (const vector_slice<V> &data, const slice &s);




2.2.3 Definition

Defined in the header vector_proxy.hpp.

2.2.4 Type requirements
2.2.5 Complexity

Linear depending from the size of the slice.

2.2.6 Examples
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>

int main () {
    using namespace boost::numeric::ublas;
    vector<double> v (3);
    for (int i = 0; i < 3; ++ i)
        project (v, slice (0, 1, 3)) (i) = i;
    std::cout << project (v, slice (0, 1, 3)) << std::endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值