1 #ifndef VIENNACL_VECTOR_PROXY_HPP_
2 #define VIENNACL_VECTOR_PROXY_HPP_
38 template<
typename VectorType>
39 class vector_range :
public vector_base<typename VectorType::cpu_value_type>
41 typedef vector_range<VectorType> self_type;
42 typedef vector_base<typename VectorType::cpu_value_type> base_type;
51 typedef typename VectorType::iterator
iterator;
68 using base_type::operator=;
71 template<
typename OtherNumericT>
74 template<
typename OtherNumericT>
77 template<
typename OtherNumericT>
81 template<
typename VectorType>
102 template<
typename VectorType,
typename NumericT>
103 void copy(
const VectorType & cpu_vector,
106 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
108 if (cpu_vector.end() - cpu_vector.begin() > 0)
111 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_vector.end() - cpu_vector.begin()));
112 std::copy(cpu_vector.begin(), cpu_vector.end(), temp_buffer.begin());
123 template<
typename CPUVECTOR,
typename VectorType>
134 template<
typename NumericT,
typename VectorType>
136 VectorType & cpu_vector)
138 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
140 if (cpu_vector.end() > cpu_vector.begin())
142 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_vector.end() - cpu_vector.begin()));
146 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_vector.begin());
156 template<
typename VectorType,
typename CPUVECTOR>
158 CPUVECTOR & cpu_vec )
168 template<
typename VectorType>
174 template<
typename VectorType>
177 assert(r1.
size() <= vec.
size() && bool(
"Size of range invalid!"));
195 template<
typename VectorType>
196 class vector_slice :
public vector_base<typename VectorType::cpu_value_type>
198 typedef vector_slice<VectorType> self_type;
199 typedef vector_base<typename VectorType::cpu_value_type> base_type;
225 using base_type::operator=;
228 template<
typename OtherNumericT>
231 template<
typename OtherNumericT>
234 template<
typename OtherNumericT>
239 template<
typename VectorType>
260 template<
typename VectorType,
typename NumericT>
261 void copy(
const VectorType & cpu_vector,
264 if (cpu_vector.size() > 0)
266 std::vector<NumericT> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
270 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
271 temp_buffer[i * gpu_vector_slice.stride()] = cpu_vector[i];
284 template<
typename VectorType,
typename NumericT>
286 VectorType & cpu_vector)
288 assert(gpu_vector_slice.end() - gpu_vector_slice.begin() >= 0 && bool(
"Range must have nonnegative length!"));
290 if (gpu_vector_slice.end() - gpu_vector_slice.begin() > 0)
292 std::vector<NumericT> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
295 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
296 cpu_vector[i] = temp_buffer[i * gpu_vector_slice.stride()];
307 template<
typename VectorType>
310 assert(s1.
size() <= vec.size() && bool(
"Size of slice larger than vector size!"));
314 template<
typename VectorType>
317 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
323 template<
typename VectorType>
326 assert(r1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
330 template<
typename VectorType>
333 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
viennacl::tools::shared_ptr< char > handle_type
DistanceT difference_type
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
VectorType::handle_type handle_type
VectorType::handle_type handle_type
VectorType::handle_type handle_type
slice::difference_type difference_type
A proxy class for entries in a vector.
This file provides the forward declarations for the main types used within ViennaCL.
vector_slice(VectorType const &v, slice const &entry_slice)
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
base_type & operator=(viennacl::vector_slice< viennacl::vector< OtherNumericT > > const &v)
VectorType::value_type value_type
viennacl::scalar< float > s1
VectorType::const_iterator const_iterator
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(NumericT))
base_type & operator=(viennacl::vector< OtherNumericT > const &v)
vector_range(vector_range< VectorType > const &v, range const &entry_range)
VectorType::value_type value_type
Class for representing non-strided subvectors of a bigger vector x.
vector_range(VectorType const &v, range const &entry_range)
const value_type & const_reference
Class for representing strided subvectors of a bigger vector x.
Common base class for dense vectors, vector ranges, and vector slices.
matrix_range< MatrixType > project(MatrixType const &A, viennacl::range const &r1, viennacl::range const &r2)
self_type & operator=(const self_type &vec)
Assignment operator. Other vector needs to be of the same size, or this vector is not yet initialized...
base_type & operator=(viennacl::vector< OtherNumericT > const &v)
void copy(vector_slice< vector< NumericT > > const &gpu_vector_slice, VectorType &cpu_vector)
VectorType::iterator iterator
base_type & operator=(viennacl::vector_range< viennacl::vector< OtherNumericT > > const &v)
VectorType::const_iterator const_iterator
vector_slice(self_type const &v, slice const &entry_slice)
VectorType::iterator iterator
vector_range(self_type const &other)
vector_range(self_type const &v, range const &entry_range)
VectorType::cpu_value_type cpu_value_type
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Implementation of a slice object for use with proxy objects.
size_type size() const
Returns the length of the vector (cf. std::vector)
vector_range(VectorType const &v, range const &entry_range)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
vector_slice(VectorType const &v, slice const &entry_slice)
range::size_type size_type
slice::size_type size_type
Implementation of a range object for use with proxy objects.
DistanceT difference_type
base_type & operator=(viennacl::vector_range< viennacl::vector< OtherNumericT > > const &v)
VectorType::handle_type handle_type
size_type start() const
Returns the offset within the buffer.
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
const value_type & const_reference
range::difference_type difference_type
const handle_type & handle() const
Returns the memory handle.
base_type & operator=(viennacl::vector_slice< viennacl::vector< OtherNumericT > > const &v)
vector_slice(vector_slice< VectorType > const &v, slice const &entry_slice)
VectorType::cpu_value_type cpu_value_type
vector_slice(self_type const &other)
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)