Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
152 lines (119 loc) · 4.93 KB

File metadata and controls

152 lines (119 loc) · 4.93 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// -*- c++ -*-
/*
* Copyright (c) 2010-2012, Jim Bosch
* All rights reserved.
*
* ndarray is distributed under a simple BSD-like license;
* see the LICENSE file that should be present in the root
* of the source distribution, or alternately available at:
* https://github.com/ndarray/ndarray
*/
#ifndef NDARRAY_views_h_INCLUDED
#define NDARRAY_views_h_INCLUDED
/**
* \file ndarray/views.h @brief Public interface for arbitrary views into arrays.
*/
#include <boost/fusion/include/push_back.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/fusion/include/mpl.hpp>
#include "ndarray_fwd.h"
namespace ndarray {
namespace index {
/**
* @brief Simple structure defining a noncontiguous range of indices.
*/
struct Slice {
Size start;
Size stop;
Offset step;
Slice(Size start_, Size stop_, Offset step_) : start(start_), stop(stop_), step(step_) {}
Size computeSize() const { return (step > 1) ? (stop - start + 1) / step : stop - start; }
};
/**
* @brief Simple structure defining a contiguous range of indices.
*/
struct Range {
Size start;
Size stop;
Range(Size start_, Size stop_) : start(start_), stop(stop_) {}
};
/**
* @brief Empty structure marking a view of an entire dimension.
*/
struct Full {};
/**
* @brief Structure marking a single element of a dimension.
*/
struct Scalar {
Size n;
explicit Scalar(Size n_) : n(n_) {}
};
} // namespace index
/**
* @brief A template meta-sequence that defines an arbitrary view into an unspecified array.
*
* A View is constructed from a call to the global view() function
* and subsequent chained calls to operator().
*/
template <typename Seq_ = boost::fusion::vector<> >
struct View {
typedef Seq_ Sequence; ///< A boost::fusion sequence type
Sequence _seq; ///< A boost::fusion sequence of index objects.
explicit View(Sequence seq) : _seq(seq) {}
template <typename OtherSequence>
explicit View(OtherSequence const & other) : _seq(other) {}
template <typename OtherSequence>
View(View<OtherSequence> const & other) : _seq(other._seq) {}
/// @brief The View that results from chaining an full dimension index <b><tt>()</tt></b> to this.
typedef View<typename boost::fusion::result_of::push_back<Sequence const,index::Full>::type> Full;
/// @brief The View that results from chaining a range <b><tt>(start,stop)</tt></b> to this.
typedef View<typename boost::fusion::result_of::push_back<Sequence const,index::Range>::type> Range;
/// @brief The View that results from chaining a slice <b><tt>(start,stop,step)</tt></b> to this.
typedef View<typename boost::fusion::result_of::push_back<Sequence const,index::Slice>::type> Slice;
/// @brief The View that results from chaining a scalar <b><tt>(n)</tt></b> to this.
typedef View<typename boost::fusion::result_of::push_back<Sequence const,index::Scalar>::type> Scalar;
/// @brief Chain the full next dimension to this.
Full operator()() const { return Full(boost::fusion::push_back(_seq, index::Full())); }
/// @brief Chain a contiguous range of the next dimension to this.
Range operator()(Size start, Size stop) const {
return Range(boost::fusion::push_back(_seq, index::Range(start, stop)));
}
/// @brief Chain a noncontiguous slice of the next dimension to this.
Slice operator()(Size start, Size stop, Offset step) const {
return Slice(boost::fusion::push_back(_seq, index::Slice(start, stop, step)));
}
/// @brief Chain a single element of the next dimension to this.
Scalar operator()(Size n) const {
return Scalar(boost::fusion::push_back(_seq, index::Scalar(n)));
}
};
/// @addtogroup ndarrayMainGroup
/// @{
/** @brief Start a view definition that includes the entire first dimension. */
inline View< boost::fusion::vector1<index::Full> > view() {
return View< boost::fusion::vector1<index::Full> >(
boost::fusion::make_vector(index::Full())
);
}
/** @brief Start a view definition that selects a contiguous range in the first dimension. */
inline View< boost::fusion::vector1<index::Range> > view(Size start, Size stop) {
return View< boost::fusion::vector1<index::Range> >(
boost::fusion::make_vector(index::Range(start, stop))
);
}
/** @brief Start a view definition that selects a noncontiguous slice of the first dimension. */
inline View< boost::fusion::vector1<index::Slice> > view(Size start, Size stop, Offset step) {
return View< boost::fusion::vector1<index::Slice> >(
boost::fusion::make_vector(index::Slice(start, stop, step))
);
}
/** @brief Start a view definition that selects single element from the first dimension. */
inline View< boost::fusion::vector1<index::Scalar> > view(Size n) {
return View< boost::fusion::vector1<index::Scalar> >(
boost::fusion::make_vector(index::Scalar(n))
);
}
/// @}
} // namespace ndarray
#endif // !NDARRAY_views_h_INCLUDED
Morty Proxy This is a proxified and sanitized view of the page, visit original site.