18 #include <c10/util/SmallVector.h> 19 #include <c10/util/C++17.h> 20 #include <c10/util/Exception.h> 21 #include <c10/util/Deprecated.h> 45 using size_type = size_t;
47 using reverse_iterator = std::reverse_iterator<iterator>;
61 constexpr
ArrayRef() : Data(nullptr), Length(0) {}
65 constexpr
ArrayRef(
const T& OneElt) : Data(&OneElt), Length(1) {}
69 : Data(data), Length(length) {}
73 : Data(begin), Length(end - begin) {}
80 : Data(Vec.data()), Length(Vec.
size()) {}
85 : Data(Vec.data()), Length(Vec.
size()) {}
89 constexpr
ArrayRef(
const std::array<T, N>& Arr)
90 : Data(Arr.data()), Length(N) {}
94 constexpr
ArrayRef(
const T (&Arr)[N]) : Data(Arr), Length(N) {}
97 constexpr
ArrayRef(
const std::initializer_list<T>& Vec)
98 : Data(Vec.begin() == Vec.end() ? static_cast<
T*>(nullptr) : Vec.begin()),
105 constexpr iterator begin()
const {
108 constexpr iterator end()
const {
109 return Data + Length;
114 constexpr const_iterator cbegin()
const {
117 constexpr const_iterator cend()
const {
118 return Data + Length;
121 constexpr reverse_iterator rbegin()
const {
122 return reverse_iterator(end());
124 constexpr reverse_iterator rend()
const {
125 return reverse_iterator(begin());
133 constexpr
const T* data()
const {
138 constexpr
size_t size()
const {
143 AT_CPP14_CONSTEXPR
const T&
front()
const {
144 AT_CHECK(!
empty(),
"ArrayRef: attempted to access front() of empty list");
149 AT_CPP14_CONSTEXPR
const T&
back()
const {
150 AT_CHECK(!
empty(),
"ArrayRef: attempted to access back() of empty list");
151 return Data[Length - 1];
156 return Length == RHS.Length && std::equal(begin(), end(), RHS.begin());
164 "ArrayRef: invalid slice, N = ",
181 constexpr
const T& operator[](
size_t Index)
const {
186 AT_CPP14_CONSTEXPR
const T&
at(
size_t Index)
const {
189 "ArrayRef: invalid index Index = ",
200 template <
typename U>
201 typename std::enable_if<std::is_same<U, T>::value,
ArrayRef<T>>::type&
208 template <
typename U>
209 typename std::enable_if<std::is_same<U, T>::value,
ArrayRef<T>>::type&
210 operator=(std::initializer_list<U>) =
delete;
215 std::vector<T> vec()
const {
216 return std::vector<T>(Data, Data + Length);
222 template <
typename T>
223 std::ostream& operator<<(std::ostream & out, ArrayRef<T> list) {
239 template <
typename T>
244 template <
typename T>
249 template <
typename T>
254 template <
typename T>
259 template <
typename T>
264 template <
typename T>
std::enable_if< std::is_same< U, T >::value, ArrayRef< T > >::type & operator=(U &&Temporary)=delete
Disallow accidental assignment from a temporary.
constexpr ArrayRef(const std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
AT_CPP14_CONSTEXPR const T & front() const
front - Get the first element.
constexpr ArrayRef(const std::initializer_list< T > &Vec)
Construct an ArrayRef from a std::initializer_list.
constexpr ArrayRef(const T(&Arr)[N])
Construct an ArrayRef from a C array.
ArrayRef(const std::vector< T, A > &Vec)
Construct an ArrayRef from a std::vector.
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD...
AT_CPP14_CONSTEXPR const T & back() const
back - Get the last element.
constexpr ArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
AT_CPP14_CONSTEXPR ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
constexpr bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
constexpr size_t size() const
size - Get the array size.
constexpr ArrayRef()
Construct an empty ArrayRef.
ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)
Construct an ArrayRef from a SmallVector.
constexpr ArrayRef(const T *begin, const T *end)
Construct an ArrayRef from a range.
constexpr bool empty() const
empty - Check if the array is empty.
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AT_CPP14_CONSTEXPR const T & at(size_t Index) const
Vector compatibility.
constexpr ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
constexpr ArrayRef(const T *data, size_t length)
Construct an ArrayRef from a pointer and length.