| 150 | typename Layout_ |
| 151 | > |
| 152 | class TensorRef { |
| 153 | public: |
| 154 | /// Data type of individual access |
| 155 | using Element = Element_; |
| 156 | |
| 157 | /// Mapping function from logical coordinate to linear memory |
| 158 | using Layout = Layout_; |
| 159 | |
| 160 | /// Reference type to an element |
| 161 | using Reference = typename platform::conditional< |
| 162 | sizeof_bits<Element>::value >= 8, |
| 163 | Element &, |
| 164 | SubbyteReference<Element> |
| 165 | >::type; |
| 166 | |
| 167 | /// Logical rank of tensor index space |
| 168 | static int const kRank = Layout::kRank; |
| 169 | |
| 170 | /// Index type |
| 171 | using Index = typename Layout::Index; |
| 172 | |
| 173 | /// Long index used for pointer offsets |
| 174 | using LongIndex = typename Layout::LongIndex; |
| 175 | |
| 176 | /// Coordinate in logical tensor space |
| 177 | using TensorCoord = typename Layout::TensorCoord; |
| 178 | |
| 179 | /// Layout's stride vector |
| 180 | using Stride = typename Layout::Stride; |
| 181 | |
| 182 | /// TensorRef to constant data |
| 183 | using ConstTensorRef = TensorRef< |
| 184 | typename platform::remove_const<Element>::type const, |
| 185 | Layout>; |
| 186 | |
| 187 | /// TensorRef to non-constant data |
| 188 | using NonConstTensorRef = TensorRef< |
| 189 | typename platform::remove_const<Element>::type, |
| 190 | Layout>; |
| 191 | |
| 192 | /// Require at least rank=1. Mathematically, a rank=0 tensor would be considered to be a |
| 193 | /// scalar, but degenerate cases such as these are difficult to accommodate without |
| 194 | /// extensive C++ metaprogramming or support for zero-length arrays. |
| 195 | static_assert(kRank > 0, "Cannot define a zero-rank TensorRef"); |
| 196 | |
| 197 | private: |
| 198 | |
| 199 | /// Pointer |
| 200 | Element* ptr_; |
| 201 | |
| 202 | /// Layout object maps logical coordinates to linear offsets |
| 203 | Layout layout_; |
| 204 | |
| 205 | public: |
| 206 | |
| 207 | // |
| 208 | // Methods |
| 209 | // |
no test coverage detected