Векторные посредники (proxies)

Диапазон вектора

Описание

Шаблонный класс vector_range<V> позволяет работать с поддиапазоном вектора.

Пример

#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_range<vector<double> > vr (v, range (0, 3));
    for (unsigned i = 0; i < vr.size (); ++ i)
        vr (i) = i;
    std::cout << vr << std::endl;
}

Будет выведено на экран:

[3](0,1,2)

Определение

Определен в заголовочном файле vector_proxy.hpp.

Параметры шаблона

Параметр Описание Значение по-умолчанию
V Тип связанного вектора.

Является моделью

Vector Expression .

Требования к типам данных

Для которых базовый класс Vector Expression .

Базовый класс

vector_expression<vector_range<V> >

Функции-члены

Приведенные ниже функции-члены в основном аналогичны функциям, перевод которым дан в разделе разряженный вектор. Характерные только для vector_range функции-члены переведены в таблице ниже.

Функция-член Описание
vector_range (vector_type &data, const range &r) Создание подвектора.
size_type start () const Возвращает номер начального элемента подвектора.
size_type size () const Возвращает размер подвектора.
const_reference operator () (size_type i) const Returns 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) const Returns 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 range vr .
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 right hand 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 to the 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 hand side of the assignment should be independent.
template<class AE>
vector_range &operator -= (const vector_expression<AE> &ae)
A computed assignment operator. Subtracts the vector expression from the sub vector.
template<class AE>
vector_range &minus_assign (const vector_expression<AE> &ae)
Subtracts a vector expression from the sub vector. Left and right 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 with a scalar.
template<class AT>
vector_range &operator /= (const AT &at)
A computed assignment operator. Divides the sub vector through a scalar.
void swap (vector_range &vr) Swaps the contents of the sub vectors.
const_iterator begin () const Returns a const_iterator pointing to the beginning of the vector_range.
const_iterator end () const Returns a const_iterator pointing to the end of the vector_range.
iterator begin () Returns a iterator pointing to the beginning of the vector_range.
iterator end () Returns a iterator pointing to the end of the vector_range.
const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the reversed vector_range.
const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed vector_range.
reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed vector_range.
reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed vector_range.

Простые проекции (Simple Projections)

Описание

Независимые функции subrange обеспечивают создание диапазонов векторов.


    vector_range<V> subrange (V &data, V::size_type start, V::size_type stop);

    const vector_range<const V> subrange (const V &data, V::size_type start, V::size_type stop);

Настраиваемые проекции (Generic Projections)

Описание

Независимые функции project обеспечивают создание диапазонов векторов. Существующие vector_range могут составляться с последующим диапазоном. Конечный диапазон вычисляется при помощи функций диапазонов compose.


    vector_range<V> project (V &data, const range &r);
    
    const vector_range<const V> project (const V &data, const range &r);

    vector_range<V> project (vector_range<V> &data, const range &r);

    const vector_range<V> project (const vector_range<V> &data, const range &r);

Определение

Определены в заголовочном файле vector_proxy.hpp.

Пример

#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;
    std::cout << project (v, range (0, 3)) << std::endl;
}

Будет выведено на экран:

[3](0,1,2)

Выборка вектора

Описание

Шаблонный класс vector_slice<V> позволяет работать с выборкой вектора.

Пример

#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;
}

Будет выведено на экран:

[3](0,1,2)

Определение

Определен в заголовочном файле vector_proxy.hpp.

Параметры шаблона

Параметр Описание Значение по-умолчанию
V Тип связанного вектора.

Функции-члены

Приведенные ниже функции-члены аналогичны функциям, перевод которым дан выше в разделах диапазон вектора и разряженный вектор.

Функция-член Описание
vector_slice (vector_type &data, const slice &s) Constructs a sub vector.
size_type size () const Returns the size of the sub vector.
const_reference operator () (size_type i) const Returns 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) const Returns 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 slice vs .
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 right hand 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 to the 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 hand side of the assignment should be independent.
template<class AE>
vector_slice &operator -= (const vector_expression<AE> &ae)
A computed assignment operator. Subtracts the vector expression from the sub vector.
template<class AE>
vector_slice &minus_assign (const vector_expression<AE> &ae)
Subtracts a vector expression from the sub vector. Left and right 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 with a scalar.
template<class AT>
vector_slice &operator /= (const AT &at)
A computed assignment operator. Divides the sub vector through a scalar.
void swap (vector_slice &vs) Swaps the contents of the sub vectors.
const_iterator begin () const Returns a const_iterator pointing to the beginning of the vector_slice.
const_iterator end () const Returns a const_iterator pointing to the end of the vector_slice.
iterator begin () Returns a iterator pointing to the beginning of the vector_slice.
iterator end () Returns a iterator pointing to the end of the vector_slice.
const_reverse_iterator rbegin () const Returns a const_reverse_iterator pointing to the beginning of the reversed vector_slice.
const_reverse_iterator rend () const Returns a const_reverse_iterator pointing to the end of the reversed vector_slice.
reverse_iterator rbegin () Returns a reverse_iterator pointing to the beginning of the reversed vector_slice.
reverse_iterator rend () Returns a reverse_iterator pointing to the end of the reversed vector_slice.

Простые проекции (Simple Projections)

Описание

Независимые функции subrange обеспечивают создание выборок векторов.


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

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

Настраиваемые проекции (Generic Projections)

Описание

Независимые функции project обеспечивают создание выборок векторов. Существующие vector_slice могут составляться с последующим диапазоном или выборкой. Конечная выборка вычисляется при помощи функций выборок compose.


    vector_slice<V> project (V &data, const slice &s);

    const vector_slice<const V> project (const V &data, const slice &s);

    vector_slice<V> project (vector_slice<V> &data, const range &r);

    const vector_slice<V> project (const vector_slice<V> &data, const range &r);

    vector_slice<V> project (vector_slice<V> &data, const slice &s);

    const vector_slice<V> project (const vector_slice<V> &data, const slice &s);

Определение

Определен в заголовочном файле vector_proxy.hpp.

Пример

#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;
}

Будет выведено на экран:

[3](0,1,2)

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided ``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Перевод с оригинала: Кулиш. В. И. 2006 год.