38 #ifndef SHARK_DATA_DATAVIEW_H 39 #define SHARK_DATA_DATAVIEW_H 59 template <
class DatasetType>
63 typedef typename std::remove_const<DatasetType>::type dataset_type;
64 typedef typename dataset_type::element_type value_type;
66 typedef typename dataset_type::batch_type batch_type;
69 typedef typename boost::mpl::if_<
70 std::is_const<DatasetType>,
71 typename dataset_type::const_element_reference,
72 typename dataset_type::element_reference
76 typedef typename boost::mpl::if_<
77 std::is_const<DatasetType>,
78 typename dataset_type::const_batch_range,
79 typename dataset_type::batch_range
81 template<
class Reference,
class View>
82 class IteratorBase:
public SHARK_ITERATOR_FACADE<
83 IteratorBase<Reference,View>,
85 std::random_access_iterator_tag,
91 IteratorBase(View& view, std::size_t position)
92 : mpe_view(&view),m_position(position) {}
94 template<
class R,
class V>
95 IteratorBase(IteratorBase<R,V>
const& other)
96 : mpe_view(other.mpe_view),m_position(other.position){}
101 std::size_t
index()
const{
102 return mpe_view->index(m_position);
106 friend class SHARK_ITERATOR_CORE_ACCESS;
107 template <
class,
class>
friend class IteratorBase;
116 void advance(std::ptrdiff_t n){
120 template<
class R,
class V>
121 std::ptrdiff_t distance_to(IteratorBase<R,V>
const& other)
const{
122 return (std::ptrdiff_t)other.m_position - (std::ptrdiff_t)m_position;
125 template<
class R,
class V>
126 bool equal(IteratorBase<R,V>
const& other)
const{
127 return m_position == other.m_position;
129 Reference dereference()
const {
130 return (*mpe_view)[m_position];
134 std::size_t m_position;
137 typedef IteratorBase<reference,DataView<DatasetType> >
iterator;
138 typedef IteratorBase<const_reference, DataView<DatasetType>
const >
const_iterator;
142 :m_dataset(dataset),m_indices(dataset.numberOfElements())
144 std::size_t
index = 0;
145 for(std::size_t i = 0; i != dataset.numberOfBatches(); ++i){
148 m_indices[
index].batch = i;
149 m_indices[
index].positionInBatch = j;
156 template<
class IndexRange>
158 :m_dataset(view.m_dataset),m_indices(indices.
size())
160 for(std::size_t i = 0; i != m_indices.size(); ++i)
161 m_indices[i] = view.m_indices[indices[i]];
166 Index
const&
index = m_indices[position];
167 return getBatchElement(m_dataset.batch(index.batch),index.positionInBatch);
171 Index
const&
index = m_indices[position];
172 return getBatchElement(m_dataset.batch(index.batch),index.positionInBatch);
185 return (*
this)[
size()-1];
189 return (*
this)[
size()-1];
196 std::size_t
index(std::size_t position)
const{
197 return m_indices[position].datasetIndex;
201 std::size_t
batch(std::size_t position)
const {
202 return m_indices[position].batch;
207 return m_indices[position].positionInBatch;
211 return m_indices.size();
223 const_iterator
end()
const{
231 dataset_type m_dataset;
237 std::size_t datasetIndex;
239 std::vector<Index> m_indices;
246 template<
class DatasetType,
class IndexRange>
256 template<
class DatasetType>
258 std::vector<std::size_t> indices(view.
size());
259 std::iota(indices.begin(),indices.end(),0);
261 return subset(view,boost::make_iterator_range(indices.begin(),indices.begin()+
size));
268 template<
class DatasetType,
class IndexRange>
269 typename DataView<DatasetType>::batch_type
subBatch(
271 IndexRange
const& indizes
284 template<
class DatasetType>
289 std::vector<std::size_t> indices(view.
size());
290 std::iota(indices.begin(),indices.end(),0);
292 return subBatch(view,boost::make_iterator_range(indices.begin(),indices.begin()+
size));
300 template<
class DatasetType>
313 typename DataView<T>::dataset_type
316 return typename DataView<T>::dataset_type();
318 std::size_t elements = view.
size();
320 std::copy(view.
begin(),view.
end(),dataset.elements().begin());
326 template <
class DatasetType>
332 template <
class DatasetType>
337 template <
class DatasetType>
343 template <
class DatasetType>