Rate this Page

Program Listing for File ArrayRef.h#

Return to documentation for file (c10/util/ArrayRef.h)

//===--- ArrayRef.h - Array Reference Wrapper -------------------*- C++ -*-===//////                     The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===//// ATen: modified from llvm::ArrayRef.// removed llvm-specific functionality// removed some implicit const -> non-const conversions that rely on// complicated std::enable_if meta-programming// removed a bunch of slice variants for simplicity...#pragma once#include<c10/macros/Macros.h>#include<c10/util/Exception.h>#include<c10/util/SmallVector.h>#include<torch/headeronly/util/HeaderOnlyArrayRef.h>#include<array>#include<cstddef>#include<cstdint>#include<initializer_list>#include<iterator>#include<ostream>#include<type_traits>#include<vector>namespacec10{template<typenameT>// ArrayRef cannot be derived from. Normally, we would use `final`// specifier to force this constraint at compile time.  However, Intel// compiler does not recognize ArrayRef as a class template (which is// required in the definition of at::TensorAccessor, for instance)// when `final` specifier is used. So, we cannot define ArrayRef as// final because of the Intel compiler issue.classArrayRef:publicHeaderOnlyArrayRef<T>{public:usingHeaderOnlyArrayRef<T>::HeaderOnlyArrayRef;template<typenameU>/* implicit */ArrayRef(constSmallVectorTemplateCommon<T,U>&Vec):HeaderOnlyArrayRef<T>(Vec.data(),Vec.size()){}constexprconstT&front()const{TORCH_CHECK(!this->empty(),"ArrayRef: attempted to access front() of empty list");returnthis->Data[0];}constexprconstT&back()const{TORCH_CHECK(!this->empty(),"ArrayRef: attempted to access back() of empty list");returnthis->Data[this->Length-1];}constexprArrayRef<T>slice(size_tN,size_tM)const{TORCH_CHECK(N+M<=this->size(),"ArrayRef: invalid slice, N = ",N,"; M = ",M,"; size = ",this->size());returnArrayRef<T>(this->data()+N,M);}constexprArrayRef<T>slice(size_tN)const{TORCH_CHECK(N<=this->size(),"ArrayRef: invalid slice, N = ",N,"; size = ",this->size());returnslice(N,this->size()-N);// should this slice be this->slice?}constexprconstT&at(size_tIndex)const{TORCH_CHECK(Index<this->Length,"ArrayRef: invalid index Index = ",Index,"; Length = ",this->Length);returnthis->Data[Index];}template<typenameU>std::enable_if_t<std::is_same_v<U,T>,ArrayRef<T>>&operator=(// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)U&&Temporary)=delete;template<typenameU>std::enable_if_t<std::is_same_v<U,T>,ArrayRef<T>>&operator=(std::initializer_list<U>)=delete;};// Single element constructortemplate<typenameT>ArrayRef(constT&)->ArrayRef<T>;// Pointer and length constructortemplate<typenameT>ArrayRef(constT*,size_t)->ArrayRef<T>;// Range constructor (begin, end)template<typenameT>ArrayRef(constT*,constT*)->ArrayRef<T>;// Generic container constructor (anything with .data() and .size())template<typenameContainer>ArrayRef(constContainer&)->ArrayRef<std::remove_pointer_t<decltype(std::declval<Container>().data())>>;// std::vector constructortemplate<typenameT,typenameA>ArrayRef(conststd::vector<T,A>&)->ArrayRef<T>;// std::array constructortemplate<typenameT,size_tN>ArrayRef(conststd::array<T,N>&)->ArrayRef<T>;// C array constructortemplate<typenameT,size_tN>ArrayRef(constT(&)[N])->ArrayRef<T>;// std::initializer_list constructortemplate<typenameT>ArrayRef(conststd::initializer_list<T>&)->ArrayRef<T>;template<typenameT>std::ostream&operator<<(std::ostream&out,ArrayRef<T>list){inti=0;out<<'[';for(constauto&e:list){if(i++>0)out<<", ";out<<e;}out<<']';returnout;}template<typenameT>ArrayRef<T>makeArrayRef(constT&OneElt){returnOneElt;}template<typenameT>ArrayRef<T>makeArrayRef(constT*data,size_tlength){returnArrayRef<T>(data,length);}template<typenameT>ArrayRef<T>makeArrayRef(constT*begin,constT*end){returnArrayRef<T>(begin,end);}template<typenameT>ArrayRef<T>makeArrayRef(constSmallVectorImpl<T>&Vec){returnVec;}template<typenameT,unsignedN>ArrayRef<T>makeArrayRef(constSmallVector<T,N>&Vec){returnVec;}template<typenameT>ArrayRef<T>makeArrayRef(conststd::vector<T>&Vec){returnVec;}template<typenameT,std::size_tN>ArrayRef<T>makeArrayRef(conststd::array<T,N>&Arr){returnArr;}template<typenameT>ArrayRef<T>makeArrayRef(constArrayRef<T>&Vec){returnVec;}template<typenameT>ArrayRef<T>&makeArrayRef(ArrayRef<T>&Vec){returnVec;}template<typenameT,size_tN>// NOLINTNEXTLINE(*c-arrays*)ArrayRef<T>makeArrayRef(constT(&Arr)[N]){returnArrayRef<T>(Arr);}// WARNING: Template instantiation will NOT be willing to do an implicit// conversions to get you to an c10::ArrayRef, which is why we need so// many overloads.template<typenameT>booloperator==(c10::ArrayRef<T>a1,c10::ArrayRef<T>a2){returna1.equals(a2);}template<typenameT>booloperator!=(c10::ArrayRef<T>a1,c10::ArrayRef<T>a2){return!a1.equals(a2);}template<typenameT>booloperator==(conststd::vector<T>&a1,c10::ArrayRef<T>a2){returnc10::ArrayRef<T>(a1).equals(a2);}template<typenameT>booloperator!=(conststd::vector<T>&a1,c10::ArrayRef<T>a2){return!c10::ArrayRef<T>(a1).equals(a2);}template<typenameT>booloperator==(c10::ArrayRef<T>a1,conststd::vector<T>&a2){returna1.equals(c10::ArrayRef<T>(a2));}template<typenameT>booloperator!=(c10::ArrayRef<T>a1,conststd::vector<T>&a2){return!a1.equals(c10::ArrayRef<T>(a2));}usingIntArrayRef=ArrayRef<int64_t>;usingIntList[[deprecated("This alias is deprecated because it doesn't make ownership semantics obvious. Use IntArrayRef instead!")]]=ArrayRef<int64_t>;}// namespace c10