Rate this Page

Template Class ArrayRef#

Inheritance Relationships#

Base Type#

  • public HeaderOnlyArrayRef< T >

Class Documentation#

template<typename T>
class ArrayRef : public HeaderOnlyArrayRef<T>#

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory), i.e.

a start pointer and a length. It allows various APIs to take consecutive elements easily and conveniently.

This class does not own the underlying data, it is expected to be used in situations where the data resides in some other buffer, whose lifetime extends past that of the ArrayRef. For this reason, it is not in general safe to store an ArrayRef.

This is intended to be trivially copyable, so it should be passed by value.

NOTE: We have refactored out the headeronly parts of the ArrayRef struct into HeaderOnlyArrayRef. As adding virtual would change the performance of the underlying constexpr calls, we rely on apparent-type dispatch for inheritance. This should be fine because their memory format is the same, and it is never incorrect for ArrayRef to call HeaderOnlyArrayRef methods. However, you should prefer to use ArrayRef when possible, because its use of TORCH_CHECK will lead to better user-facing error messages.

Constructors, all inherited from HeaderOnlyArrayRef except for

SmallVector.

As inherited constructors won’t work with class template argument deduction (CTAD) until C++23, we add deduction guides after the class definition to enable CTAD.

template<typename U>
inline ArrayRef(const SmallVectorTemplateCommon<T, U> &Vec)#

Construct an ArrayRef from a SmallVector.

This is templated in order to avoid instantiating SmallVectorTemplateCommon<T> whenever we copy-construct an ArrayRef. NOTE: this is the only constructor that is not inherited from HeaderOnlyArrayRef.

Simple Operations, mostly inherited from HeaderOnlyArrayRef

inline constexpr const T &front() const#

front - Get the first element.

We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK

inline constexpr const T &back() const#

back - Get the last element.

We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK

inline constexpr ArrayRef<T> slice(size_t N, size_t M) const#

slice(n, m) - Take M elements of the array starting at element N We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK

inline constexpr ArrayRef<T> slice(size_t N) const#

slice(n) - Chop off the first N elements of the array.

We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK

Operator Overloads

inline constexpr const T &at(size_t Index) const#

Vector compatibility We deviate from HeaderOnlyArrayRef by using TORCH_CHECK instead of STD_TORCH_CHECK.

template<typename U>
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &operator=(U &&Temporary) = delete#

Disallow accidental assignment from a temporary.

The declaration here is extra complicated so that “arrayRef = {}” continues to select the move assignment operator.

template<typename U>
std::enable_if_t<std::is_same_v<U, T>, ArrayRef<T>> &operator=(std::initializer_list<U>) = delete#

Disallow accidental assignment from a temporary.

The declaration here is extra complicated so that “arrayRef = {}” continues to select the move assignment operator.