Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Class template vector

Boost , Chapter 1. Boost.Compute , Reference

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class template vector

boost::compute::vector — A resizable array of values.

Synopsis

// In header: <boost/compute/container/vector.hpp>
template<typename T, typename Alloc = buffer_allocator<T> > 
class vector {
public:
  // types
  typedef T                                       value_type;            
  typedef Alloc                                   allocator_type;        
  typedef allocator_type::size_type               size_type;             
  typedef allocator_type::difference_type         difference_type;       
  typedef unspecified                             reference;             
  typedef unspecified                             const_reference;       
  typedef allocator_type::pointer                 pointer;               
  typedef allocator_type::const_pointer           const_pointer;         
  typedef buffer_iterator< T >                    iterator;              
  typedef buffer_iterator< T >                    const_iterator;        
  typedef std::reverse_iterator< iterator >       reverse_iterator;      
  typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
  // construct/copy/destruct
  explicit vector(const context & = system::default_context());
  explicit vector(size_type, const context & = system::default_context());
  vector(size_type, const T &, command_queue & = system::default_queue());
  template<typename InputIterator> 
    vector(InputIterator, InputIterator, 
           command_queue & = system::default_queue());
  vector(const vector &, command_queue & = system::default_queue());
  template<typename OtherAlloc> 
    vector(const vector< T, OtherAlloc > &, 
           command_queue & = system::default_queue());
  template<typename OtherAlloc> 
    vector(const std::vector< T, OtherAlloc > &, 
           command_queue & = system::default_queue());
  vector(std::initializer_list< T >, 
         command_queue & = system::default_queue());
  vector(vector &&);
  vector & operator=(const vector &);
  template<typename OtherAlloc> 
    vector & operator=(const vector< T, OtherAlloc > &);
  template<typename OtherAlloc> 
    vector & operator=(const std::vector< T, OtherAlloc > &);
  vector & operator=(vector &&);
  ~vector();
  // public member functions
  iterator begin();
  const_iterator begin() const;
  const_iterator cbegin() const;
  iterator end();
  const_iterator end() const;
  const_iterator cend() const;
  reverse_iterator rbegin();
  const_reverse_iterator rbegin() const;
  const_reverse_iterator crbegin() const;
  reverse_iterator rend();
  const_reverse_iterator rend() const;
  const_reverse_iterator crend() const;
  size_type size() const;
  size_type max_size() const;
  void resize(size_type, command_queue &);
  void resize(size_type);
  bool empty() const;
  size_type capacity() const;
  void reserve(size_type, command_queue &);
  void reserve(size_type);
  void shrink_to_fit(command_queue &);
  void shrink_to_fit();
  reference operator[](size_type);
  const_reference operator[](size_type) const;
  reference at(size_type);
  const_reference at(size_type) const;
  reference front();
  const_reference front() const;
  reference back();
  const_reference back() const;
  template<typename InputIterator> 
    void assign(InputIterator, InputIterator, command_queue &);
  template<typename InputIterator> void assign(InputIterator, InputIterator);
  void assign(size_type, const T &, command_queue &);
  void assign(size_type, const T &);
  void push_back(const T &, command_queue &);
  void push_back(const T &);
  void pop_back(command_queue &);
  void pop_back();
  iterator insert(iterator, const T &, command_queue &);
  iterator insert(iterator, const T &);
  void insert(iterator, size_type, const T &, command_queue &);
  void insert(iterator, size_type, const T &);
  template<typename InputIterator> 
    void insert(iterator, InputIterator, InputIterator, command_queue &);
  template<typename InputIterator> 
    void insert(iterator, InputIterator, InputIterator);
  iterator erase(iterator, command_queue &);
  iterator erase(iterator);
  iterator erase(iterator, iterator, command_queue &);
  iterator erase(iterator, iterator);
  void swap(vector &);
  void clear();
  allocator_type get_allocator() const;
  const buffer & get_buffer() const;
};

Description

Классvectorхранит динамический массив значений. Внутренне данные хранятся в буферном объекте OpenCL.

Векторный класс является предпочтительным контейнером для хранения и доступа к данным на вычислительном устройстве. В большинстве случаев его следует использовать вместо непосредственного обращения с буферными объектами. Если требуется буфер для удаления, к нему можно получить доступ с помощью метода get_buffer().

Внутреннее хранилище выделяется в определенном контексте OpenCL, который передается в качестве аргумента конструктору при создании вектора.

Например, для создания вектора на устройстве, содержащем пространство для десяти<int>значений:

boost::compute::vector<int> vec(10, context);

Выделение и передача данных также могут быть выполнены в один этап:

// values on the host
int data[] = { 1, 2, 3, 4 };
// create a vector of size four and copy the values from data
boost::compute::vector<int> vec(data, data + 4, queue);

Boost.Compute скачать<vector>класс обеспечивает STL-подобный API и моделируется после класса<std::vector>из стандартной библиотеки C++. Он может быть использован с любым из STL-подобных алгоритмов, предоставляемых Boost.<copy()>,<transform()>и<sort()>(среди многих других).

Например:

// a vector on a compute device
boost::compute::vector<float> vec = ...
// copy data to the vector from a host std:vector
boost::compute::copy(host_vec.begin(), host_vec.end(), vec.begin(), queue);
// copy data from the vector to a host std::vector
boost::compute::copy(vec.begin(), vec.end(), host_vec.begin(), queue);
// sort the values in the vector
boost::compute::sort(vec.begin(), vec.end(), queue);
// calculate the sum of the values in the vector (also see reduce())
float sum = boost::compute::accumulate(vec.begin(), vec.end(), 0, queue);
// reverse the values in the vector
boost::compute::reverse(vec.begin(), vec.end(), queue);
// fill the vector with ones
boost::compute::fill(vec.begin(), vec.end(), 1, queue);

Смотрите также:

array, буфер

vector public construct/copy/destruct

  1. explicitvector(constcontext&context=system::default_context());
    Создает пустой вектор вcontext.
  2. explicit vector(size_type count, 
                    const context & context = system::default_context());

    Creates a vector with space for count elements in context.

    Note that unlike std::vector's constructor, this will not initialize the values in the container. Either call the vector constructor which takes a value to initialize with or use the fill() algorithm to set the initial values.

    Например:

    // create a vector on the device with space for ten ints
    boost::compute::vector<int> vec(10, context);
    

  3. vector(size_type count, const T & value, 
           command_queue & queue = system::default_queue());

    Creates a vector with space for count elements and sets each equal to value.

    Например:

    // creates a vector with four values set to nine (e.g. [9, 9, 9, 9]).
    boost::compute::vector<int> vec(4, 9, queue);
    

  4. Составляет вектор с пространством для значений в диапазоне [first, last) и копирует их в вектор с queue.

    Например:

    // values on the host
    int data[] = { 1, 2, 3, 4 };
    // create a vector of size four and copy the values from data
    boost::compute::vector<int> vec(data, data + 4, queue);
    

    Например:

    // values on the host
    int data[] = { 1, 2, 3, 4 };
    // create a vector of size four and copy the values from data
    boost::compute::vector<int> vec(data, data + 4, queue);
    

    [ORIG_END] -->
  5. vector(constvector&other,command_queue&queue=system::default_queue());
    Создает новый вектор и копирует значения изother.
  6. <
    template<typenameOtherAlloc>
     vector(constvector<T,OtherAlloc>&other,
            command_queue&queue=system::default_queue());
    >Создает новый вектор и копирует значения<other>.
  7. template<typenameOtherAlloc>
     vector(conststd::vector<T,OtherAlloc>&vector,
            command_queue&queue=system::default_queue());
    Создает новый вектор и копирует значения изvector.
  8. <
    vector(std::initializer_list<T>list,
          command_queue&queue=system::default_queue());
    >
  9. vector(vector&&other);
    Построение нового вектора изother.
  10. <
    vector&operator=(constvector&other);
    >
  11. <
    template<typenameOtherAlloc>
     vector&operator=(constvector<T,OtherAlloc>&other);
    >
  12. <
    template<typenameOtherAlloc>
     vector&operator=(conststd::vector<T,OtherAlloc>&vector);
    >
  13. vector&operator=(vector&&other);
    Переносит данные сotherна*this.
  14. ~vector();
    Уничтожает векторный объект.

vector public member functions

  1. <
    iteratorbegin();
    >
  2. <
    const_iteratorbegin()const;
    >
  3. <
    const_iteratorcbegin()const;
    >
  4. <
    iteratorend();
    >
  5. <
    const_iteratorend()const;
    >
  6. <
    const_iteratorcend()const;
    >
  7. <
    reverse_iteratorrbegin();
    >
  8. <
    const_reverse_iteratorrbegin()const;
    >
  9. <
    const_reverse_iteratorcrbegin()const;
    >
  10. <
    reverse_iteratorrend();
    >
  11. <
    const_reverse_iteratorrend()const;
    >
  12. <
    const_reverse_iteratorcrend()const;
    >
  13. size_typesize()const;
    Возвращает число элементов в векторе.
  14. <
    size_typemax_size()const;
    >
  15. voidresize(size_typesize,command_queue&queue);
    Размеры вектораsize.
  16. voidresize(size_typesize);

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

  17. boolempty()const;
    Возвращаетсяtrue, если вектор пуст.
  18. size_typecapacity()const;
    Возвращает емкость вектора.
  19. <
    voidreserve(size_typesize,command_queue&queue);
    >
  20. <
    voidreserve(size_typesize);
    >
  21. <
    voidshrink_to_fit(command_queue&queue);
    >
  22. <
    voidshrink_to_fit();
    >
  23. <
    referenceoperator[](size_typeindex);
    >
  24. <
    const_referenceoperator[](size_typeindex)const;
    >
  25. <
    referenceat(size_typeindex);
    >
  26. <
    const_referenceat(size_typeindex)const;
    >
  27. <
    referencefront();
    >
  28. <
    const_referencefront()const;
    >
  29. <
    referenceback();
    >
  30. <
    const_referenceback()const;
    >
  31. <
    template<typenameInputIterator>
     voidassign(InputIteratorfirst,InputIteratorlast,command_queue&queue);
    >
  32. <
    template<typenameInputIterator>
     voidassign(InputIteratorfirst,InputIteratorlast);
    >
  33. <
    voidassign(size_typen,constT&value,command_queue&queue);
    >
  34. <
    voidassign(size_typen,constT&value);
    >
  35. voidpush_back(constT&value,command_queue&queue);

    Вставляетvalueв конце вектора (размер, если необходимо).

    Обратите внимание, что вызовpush_back()для вставки значений данных по одному за раз неэффективен, поскольку при выполнении передачи данных на устройство имеются нетривиальные накладные расходы. Обычно лучше хранить набор значений на хосте (например, вstd::vector), а затем передавать их оптом с помощью методаinsert()или алгоритма копирования ().

  36. voidpush_back(constT&value);

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

  37. <
    voidpop_back(command_queue&queue);
    >
  38. <
    voidpop_back();
    >
  39. <
    iteratorinsert(iteratorposition,constT&value,command_queue&queue);
    >
  40. <
    iteratorinsert(iteratorposition,constT&value);
    >
  41. <
    voidinsert(iteratorposition,size_typecount,constT&value,
               command_queue&queue);
    >
  42. <
    voidinsert(iteratorposition,size_typecount,constT&value);
    >
  43. template<typenameInputIterator>
     voidinsert(iteratorposition,InputIteratorfirst,InputIteratorlast,
                 command_queue&queue);

    Вставляет значения в диапазонеfirst,lastв вектор приpositionс использованиемqueue.

  44. template<typenameInputIterator>
     voidinsert(iteratorposition,InputIteratorfirst,InputIteratorlast);

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

  45. <
    iteratorerase(iteratorposition,command_queue&queue);
    >
  46. <
    iteratorerase(iteratorposition);
    >
  47. <
    iteratorerase(iteratorfirst,iteratorlast,command_queue&queue);
    >
  48. <
    iteratorerase(iteratorfirst,iteratorlast);
    >
  49. voidswap(vector&other);
    Содержимое*thisизменяется наother.
  50. voidclear();
    Удаляет все элементы из вектора.
  51. <
    allocator_typeget_allocator()const;
    >
  52. <
    constbuffer&get_buffer()const;
    >Возвращает основной буфер.

PrevUpHomeNext

Статья Class template vector раздела Chapter 1. Boost.Compute Reference может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Reference ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-19 21:14:36/0.032159090042114/1