vector_proxy.hpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Vector proxy classes.
5  *
6  *
7  *
8  * \author O. Krause
9  * \date 2013
10  *
11  *
12  * \par Copyright 1995-2015 Shark Development Team
13  *
14  * <BR><HR>
15  * This file is part of Shark.
16  * <http://image.diku.dk/shark/>
17  *
18  * Shark is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Lesser General Public License as published
20  * by the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * Shark is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
30  *
31  */
32 
33 #ifndef REMORA_VECTOR_PROXY_HPP
34 #define REMORA_VECTOR_PROXY_HPP
35 
36 #include "detail/expression_optimizers.hpp"
37 
38 
39 namespace remora{
40 
41 // ------------------
42 // Vector subrange
43 // ------------------
44 
45 /// \brief Return a subrange of a specified vector, forming a vector for the specified indices between start and stop index.
46 ///
47 /// The vector starts with first index being 0 for the element that is indexed with start in the original vector.
48 template<class V, class Device>
49 temporary_proxy<typename detail::vector_range_optimizer<V>::type>
50 subrange(vector_expression<V, Device>& expression, std::size_t start, std::size_t stop){
51  return detail::vector_range_optimizer<V>::create(expression(), start, stop);
52 }
53 
54 template<class V, class Device>
55 typename detail::vector_range_optimizer<typename const_expression<V>::type>::type
56 subrange(vector_expression<V, Device> const& expression, std::size_t start, std::size_t stop){
57  return detail::vector_range_optimizer<typename const_expression<V>::type>::create(expression(), start, stop);
58 }
59 
60 template<class V>
61 temporary_proxy<typename detail::vector_range_optimizer<V>::type>
62 subrange(temporary_proxy<V> expression, std::size_t start, std::size_t stop){
63  return subrange(static_cast<V&>(expression), start, stop);
64 }
65 
66 // ------------------
67 // Adapt memory as vector
68 // ------------------
69 
70 /// \brief Converts a chunk of memory into a vector of a given size.
71 template <class T>
72 temporary_proxy<dense_vector_adaptor<T> > adapt_vector(std::size_t size, T * expression){
73  return dense_vector_adaptor<T>(expression,size);
74 }
75 
76 /// \brief Converts a C-style array into a vector.
77 template <class T, std::size_t N>
78 temporary_proxy<dense_vector_adaptor<T> > adapt_vector(T (&array)[N]){
79  return dense_vector_adaptor<T>(array,N);
80 }
81 
82 
83 }
84 
85 #endif