# tensorflow::Tensor

`#include <tensor.h>`

Represents an n-dimensional array of values.

## Summary

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aebe57070a84f43b98e63671f52a117fe()` Creates a 1-dimensional, 0-element float tensor. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a08e32d524ca560888c76a57e6fab5466(DataType type, const TensorShape & shape)` Creates a [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of the given `type` and `shape`. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aec608b828b3807c153616598822fa555(Allocator *a, DataType type, const TensorShape & shape)` Creates a tensor with the input `type` and `shape`, using the allocator `a` to allocate the underlying buffer. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a55de61e27b842b06b29c954b2c3bf3f3(Allocator *a, DataType type, const TensorShape & shape, const AllocationAttributes & allocation_attr)` Creates a tensor with the input `type` and `shape`, using the allocator `a` and the specified "allocation_attr" to allocate the underlying buffer. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac57b0c5223af0068c3de94e0f9fdba2c(DataType type, const TensorShape & shape, https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor-buffer#classtensorflow_1_1_tensor_buffer *buf)` Creates a tensor with the input datatype, shape and buf. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6bb96a5472af5913183741f78b90a857(DataType type, TensorShape shape, core::RefCountPtr< https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor-buffer#classtensorflow_1_1_tensor_buffer > buf)` Creates a tensor with the input datatype, shape and buf. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a306a1c30a4ed610837c775aed23f2a10(DataType type)` Creates an empty [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of the given data type. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1af8969ead84ed648963ae46e691547e9e(float scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a5d5e5d7b4a4177f7373b029131bc423b(double scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a5601f452904e18cad4aac9e8248ec264(int32_t scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad6998eeb293c0556b7235130e4e30f28(uint32 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a1fa38a7929a9c42f1e85bde0bbb8f8a6(uint16 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ae4cca32e1273ab339a7c45644131f79d(uint8 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a7655927ab8a4550fb477164b93317617(int16_t scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a114dda8b130cbd51012d27508ed55c32(int8_t scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a76915adb56e0e75fb6ffe310a136dc26(tstring scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac4eebf0208aafd7bb871662330fa0164(complex64 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a9d29b0abca4b31db30c0b10a9f9cbc5f(complex128 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1abe2d538fbf66d908e55e6f28d63c0559(int64_t scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a1c765a977eb9cfd864586d7afa48a5f0(uint64 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aaf55b6346cd86757991d140d9f0708ad(bool scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ae82fabedfb3355965bfa6c950a4d0088(qint8 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a709b3d5127f6daeae56ebe4231a4ff0b(quint8 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa019552e7ea5d3f350b905829b0d5199(qint16 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a418411132eecce8c0a526df8d7cceaeb(quint16 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1af304024fec2e58bec0f93bea580d0be7(qint32 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1acbf215151f87c2a19364f15bd69618ad(bfloat16 scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ab478fb0c62ce0e56a12f0812642bc16c(Eigen::half scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a473a4c38498e06f8e7d1125401cefdea(ResourceHandle scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a3da694b6697a62217d01b9c5a4ecfb3d(const char *scalar_value)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6379ca55abf3e9f475a5fd0615d863d5(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & other)` Copy constructor. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a9ce0ef052f796ecaad68e2000853f339(https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor && other)` Move constructor. ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a1be48c77fc8291b99b8cfb763f6e3255(T *t)` ||
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a212bdf999f5deef11504d781cf2ab855()` ||

| ### Friend classes ||
|---|---|
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aef436d3b7e66d1410ead8b7aedcbe18c` | `friend std::ostream &` |

| ### Public functions ||
|---|---|
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a3c21e0423f7577a32583eb96d2a3a5ec() const ` | `size_t` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a55198b51aab7ca4ef312416c2b742eec(TensorProto *proto) const ` | `void` Fills in `proto` with `*this` tensor's content. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a4b9855ed8179d0611e9bced54dfa3aad(TensorProto *proto) const ` | `void` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a76ab5c0e7b5f7dc9b12be46e02f9f957(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & other, DataType dtype, const TensorShape & shape)` | `Status` Copy the other tensor into this tensor, reshape it and reinterpret the buffer's datatype. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1acf6199c97175185c91ccd350e8a6e19c(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & other, const TensorShape & shape) TF_MUST_USE_RESULT` | `bool` Copy the other tensor into this tensor and reshape it. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a227f8e3940b1be0a7c21c2fdccac631b(int num_values) const ` | `std::string` A human-readable summary of the tensor suitable for debugging. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a69eba2eecb66ff8dc04d7a88c68223f8() const ` | `std::string` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad9e2aacd5689cdfa001fa497ee68919e() const ` | `std::string` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a04b83c98a70a80676c94fe1294faa6e1(TensorDescription *description) const ` | `void` Fill in the `TensorDescription` proto with metadata about the tensor that is useful for monitoring and debugging. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad7cd0d781683c4cc7e66bd9e1da6fe57(const TensorProto & other) TF_MUST_USE_RESULT` | `bool` Parse `other` and construct the tensor. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aea7f15d9d7432ee6ab82c8b1730ab804(Allocator *a, const TensorProto & other) TF_MUST_USE_RESULT` | `bool` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad1260f69b3d0ba06de362f51bb98bb36() const ` | `AllocatorMemoryType` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aec1fa00d85d569b344a55ad89f915ce9() const ` | `bool` Returns true iff this tensor is aligned. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa44336c38c4baf3ed69f63aee131ba87() const ` | `bool` If necessary, has this [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) been initialized? |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a2e0df4f1c6996097c49822d112f0678f(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & b) const ` | `bool` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ae187c661b3add739bd7604b8ac053918() const ` | `int64_t` Convenience accessor for the tensor shape. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a42e5e3f3a2bbc60a9c8c451515604a08() const ` | `int` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a43490147346ba4d73aab4477dae9c37d() const ` | `bool` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a9b9acd3759bc39a23d4691816b2ba05c(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & b) const ` | `bool` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a5f6fa12cd72397c5dcc6d9a01ebeef7e(int64_t dim0_start, int64_t dim0_limit) const ` | `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Slice this tensor along the 1st dimension. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ae2601c8003fb28b4c3a156510ae15e3f(int64_t index) const ` | `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Select a subslice from this tensor along the 1st dimension. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a4516f8fe1bbc948e603418caad29ad5d(int64_t max_entries, bool print_v2) const ` | `std::string` Render the first `max_entries` values in `*this` into a string. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ab2c0b13287edd6d8dec1bbc59794e81c() const ` | `size_t` Returns the estimated memory usage of this tensor. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a8fab7661ec78cfda7b02a85680070d20(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & other, DataType dtype, const TensorShape & shape)` | `void` Like BitcastFrom, but CHECK fails if any preconditions are not met. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1add9b77889365997588f586f84783933d(gtl::ArraySlice< int64_t > new_sizes)` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Return the tensor data to an `Eigen::Tensor` with the new shape specified in `new_sizes` and cast to a new dtype `T`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a94c3839fd0321644fee9512cf913d3a5(gtl::ArraySlice< int64_t > new_sizes) const ` | `TTypes< T, NDIMS >::ConstTensor` Return the tensor data to an `Eigen::Tensor` with the new shape specified in `new_sizes` and cast to a new dtype `T`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ab479fc449ce2e5da1a99d4cae8f6e47a()` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Return the tensor data to an `Eigen::Tensor` with the same size but a bitwise cast to the specified dtype `T`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1afced940422a1e726d9487cb3cb039630() const ` | `TTypes< T, NDIMS >::ConstTensor` Return the tensor data to an `Eigen::Tensor` with the same size but a bitwise cast to the specified dtype `T`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a8232f7ab745e48a3b22a8396f7d96e28() const ` | `void *` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6d84417cd610be15a4e61ce44b9edee6(int d) const ` | `int64_t` Convenience accessor for the tensor shape. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9() const ` | `int` Convenience accessor for the tensor shape. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a16a9c0fa93491bbc44377cd7eb58b3c6() const ` | `DataType` Returns the data type. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a67ce62becce1e70454d9756d1d5ed996()` | `TTypes< T >::Flat` Return the tensor data as an `Eigen::Tensor` of the data type and a specified shape. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1adfe83abc7c7b4834dc9d73ec3ec38f43() const ` | `TTypes< T >::ConstFlat` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6f5bf51d9c7f2ebf21d56aa8313a8b5f()` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing all [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions but the last NDIMS-1 into the first dimension of the result. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a2941fc6005d4f9e0197ffe478eac6bc6() const ` | `TTypes< T, NDIMS >::ConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a07cc1b89360a9a0d090045b008afbbd4(int64_t begin)` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing the first 'begin' [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions into the first dimension of the result and the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions of the last [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) - 'begin' - NDIMS into the last dimension of the result. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac09b416216de9fef0de65712f221283a(int64_t begin) const ` | `TTypes< T, NDIMS >::ConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a290876f00cea56107eeecc49af671c54()` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing all [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions but the first NDIMS-1 into the last dimension of the result. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a49513c7e2fa9c4644760e0d579eb2607() const ` | `TTypes< T, NDIMS >::ConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6afab48885080a80ff0b52437959d929()` | `TTypes< T >::Matrix` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a4005578d5a8b62e0d6deb86569b6eb14() const ` | `TTypes< T >::ConstMatrix` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6582b22e47d0ed025ba96698be491225(const https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor & other)` | `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor &` Assign operator. This tensor shares other's underlying storage. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ab1669f9097b60559467424f901bf3211(https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor && other)` | `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor &` Move operator. See move constructor for details. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a775ff735c4ec85176bc317f3d2f3e9f1()` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` Return the tensor data to an `Eigen::Tensor` with the last dimension elements converted into single elements of a larger type. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a1c1d8fcb22c6ce7aaefe98b28466a02f() const ` | `TTypes< T, NDIMS >::ConstTensor` Return the tensor data to an `Eigen::Tensor` with the last dimension elements converted into single elements of a larger type. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aacce92855f6b83eea728203de8016c78()` | `TTypes< T >::Scalar` Return the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) data as a `TensorMap` of fixed size 1: `TensorMap>`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a6d20a479e87d6ef5af2c7f3364e22858() const ` | `TTypes< T >::ConstScalar` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad0065facf49e31e4f48f07dd41528119() const ` | `const TensorShape &` Returns the shape of the tensor. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a470ad77392d8611095d0097833239ffb(gtl::ArraySlice< int64_t > new_sizes)` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1abac0dc6fa26202b35dd66a5bcab1071f(gtl::ArraySlice< int64_t > new_sizes) const ` | `TTypes< T, NDIMS >::ConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ad3887e7bc409e3385509a4cca75fdd20() TF_ATTRIBUTE_NOINLINE` | `TTypes< T, NDIMS >::https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a23094d649c829b90d0477423fcf0d4bf() const TF_ATTRIBUTE_NOINLINE` | `TTypes< T, NDIMS >::ConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aec0a1c04f8bc4c469453a0c13668b968() const ` | `StringPiece` Returns a `StringPiece` mapping the current tensor's buffer. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a93908c637764bdec8bfd08da5fe49a06()` | `TTypes< T >::UnalignedFlat` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a52f9619663d80a05a933d8ee96074b35() const ` | `TTypes< T >::UnalignedConstFlat` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1af44433e657d62dd45d85549fa52de162(gtl::ArraySlice< int64_t > new_sizes)` | `TTypes< T, NDIMS >::UnalignedTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a3300cdb52656e610f907241e737aeafe(gtl::ArraySlice< int64_t > new_sizes) const ` | `TTypes< T, NDIMS >::UnalignedConstTensor` |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a8714205b3a82f0338c53c31ee93eab95()` | `TTypes< T >::Vec` Return the tensor data as an `Eigen::Tensor` with the type and sizes of this `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor`. |
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a0834fadcc0428f68c9d13bd32a1b20d9() const ` | `TTypes< T >::ConstVec` Const versions of all the methods above. |

| ### Public static functions ||
|---|---|
| `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa4ad1471d84dac07998b889b70172f4f(DataType type, const TensorShape & shape, https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor *out_tensor)` | `Status` Initializes a tensor with the input `type` and `shape`, or returns an error and leaves `out_tensor` unmodified. |

## Friend classes

### operator\<\<

```
friend std::ostream & operator<<(std::ostream &out, const Tensor &tensor)
```

## Public functions

### AllocatedBytes

```
size_t AllocatedBytes() const 
```

### AsProtoField

```
void AsProtoField(
  TensorProto *proto
) const 
```
Fills in `proto` with `*this` tensor's content.

`https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a55198b51aab7ca4ef312416c2b742eec` fills in the repeated field for `proto.dtype()`, while `AsProtoTensorContent()` encodes the content in `proto.tensor_content()` in a compact form.

### AsProtoTensorContent

```
void AsProtoTensorContent(
  TensorProto *proto
) const 
```

### BitcastFrom

```
Status BitcastFrom(
  const Tensor & other,
  DataType dtype,
  const TensorShape & shape
)
```
Copy the other tensor into this tensor, reshape it and reinterpret the buffer's datatype.

If an ok Status is returned, the two tensors now share the same underlying storage.

This call requires that the `other` tensor and the given type and shape are "compatible" (i.e. they occupy the same number of bytes).

Specifically:

shape.num_elements() \* DataTypeSize(type)

must equal

other.num_elements() \* DataTypeSize(other.dtype())

In addition, this function requires:

- DataTypeSize(other.dtype()) != 0
- DataTypeSize(type) != 0

<br />

If any of the requirements are not met, errors::InvalidArgument is returned.

### CopyFrom

```
bool CopyFrom(
  const Tensor & other,
  const TensorShape & shape
) TF_MUST_USE_RESULT
```
Copy the other tensor into this tensor and reshape it.

This tensor shares other's underlying storage. Returns `true` iff `other.shape()` has the same number of elements of the given `shape`.

### DebugString

```
std::string DebugString(
  int num_values
) const 
```
A human-readable summary of the tensor suitable for debugging.

### DebugString

```
std::string DebugString() const 
```

### DeviceSafeDebugString

```
std::string DeviceSafeDebugString() const 
```

### FillDescription

```
void FillDescription(
  TensorDescription *description
) const 
```
Fill in the `TensorDescription` proto with metadata about the tensor that is useful for monitoring and debugging.

### FromProto

```
bool FromProto(
  const TensorProto & other
) TF_MUST_USE_RESULT
```
Parse `other` and construct the tensor.

Returns `true` iff the parsing succeeds. If the parsing fails, the state of `*this` is unchanged.

### FromProto

```
bool FromProto(
  Allocator *a,
  const TensorProto & other
) TF_MUST_USE_RESULT
```

### GetMemoryType

```
AllocatorMemoryType GetMemoryType() const 
```

### IsAligned

```
bool IsAligned() const 
```
Returns true iff this tensor is aligned.

### IsInitialized

```
bool IsInitialized() const 
```
If necessary, has this [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) been initialized?

Zero-element Tensors are always considered initialized, even if they have never been assigned to and do not have any memory allocated.

### IsSameSize

```
bool IsSameSize(
  const Tensor & b
) const 
```

### NumElements

```
int64_t NumElements() const 
```
Convenience accessor for the tensor shape.

### RefCount

```
int RefCount() const 
```

### RefCountIsOne

```
bool RefCountIsOne() const 
```

### SharesBufferWith

```
bool SharesBufferWith(
  const Tensor & b
) const 
```

### Slice

```
Tensor Slice(
  int64_t dim0_start,
  int64_t dim0_limit
) const 
```
Slice this tensor along the 1st dimension.

I.e., the returned tensor satisfies returned\[i, ...\] == this\[dim0_start + i, ...\]. The returned tensor shares the underlying tensor buffer with this tensor.

NOTE: The returned tensor may not satisfy the same alignment requirement as this tensor depending on the shape. The caller must check the returned tensor's alignment before calling certain methods that have alignment requirement (e.g., `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a67ce62becce1e70454d9756d1d5ed996`, `tensor()`).

NOTE: When fed with an N-dimensional tensor, this method returns a tensor also with N dimensions. If you want to select a sub tensor, see SubSlice.

REQUIRES: `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9` \>= 1 REQUIRES: `0 <= dim0_start <= dim0_limit <= dim_size(0)`

### SubSlice

```
Tensor SubSlice(
  int64_t index
) const 
```
Select a subslice from this tensor along the 1st dimension.

When fed with an N-dimensional tensor, this method returns a tensor with N-1 dimensions, where the returned tensor is a subslice of the input tensor along the first dimension. The N-1 dimensions of the returned tensor are the last N-1 dimensions of the input tensor.

NOTE: The returned tensor may not satisfy the same alignment requirement as this tensor depending on the shape. The caller must check the returned tensor's alignment before calling certain methods that have alignment requirement (e.g., `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1a67ce62becce1e70454d9756d1d5ed996`, `tensor()`).

REQUIRES: `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9` \>= 1 REQUIRES: `0 <= index < dim_size(0)`

### SummarizeValue

```
std::string SummarizeValue(
  int64_t max_entries,
  bool print_v2
) const 
```
Render the first `max_entries` values in `*this` into a string.

### Tensor

```
 Tensor()
```
Creates a 1-dimensional, 0-element float tensor.

The returned [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) is not a scalar (shape {}), but is instead an empty one-dimensional [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) (shape {0}, [NumElements()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ae187c661b3add739bd7604b8ac053918) == 0). Since it has no elements, it does not need to be assigned a value and is initialized by default ([IsInitialized()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa44336c38c4baf3ed69f63aee131ba87) is true). If this is undesirable, consider creating a one-element scalar which does require initialization:


```
Tensor(DT_FLOAT, TensorShape({}))
```

<br />


```

```

<br />

### Tensor

```
 Tensor(
  DataType type,
  const TensorShape & shape
)
```
Creates a [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of the given `type` and `shape`.

If LogMemory::IsEnabled() the allocation is logged as coming from an unknown kernel and step. Calling the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) constructor directly from within an Op is deprecated: use the OpKernelConstruction/OpKernelContext allocate_\* methods to allocate a new tensor, which record the kernel and step.

The underlying buffer is allocated using a `CPUAllocator`.

### Tensor

```
 Tensor(
  Allocator *a,
  DataType type,
  const TensorShape & shape
)
```
Creates a tensor with the input `type` and `shape`, using the allocator `a` to allocate the underlying buffer.

If LogMemory::IsEnabled() the allocation is logged as coming from an unknown kernel and step. Calling the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) constructor directly from within an Op is deprecated: use the OpKernelConstruction/OpKernelContext allocate_\* methods to allocate a new tensor, which record the kernel and step.

`a` must outlive the lifetime of this [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor).

### Tensor

```
 Tensor(
  Allocator *a,
  DataType type,
  const TensorShape & shape,
  const AllocationAttributes & allocation_attr
)
```
Creates a tensor with the input `type` and `shape`, using the allocator `a` and the specified "allocation_attr" to allocate the underlying buffer.

If the kernel and step are known allocation_attr.allocation_will_be_logged should be set to true and LogMemory::RecordTensorAllocation should be called after the tensor is constructed. Calling the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) constructor directly from within an Op is deprecated: use the OpKernelConstruction/OpKernelContext allocate_\* methods to allocate a new tensor, which record the kernel and step.

`a` must outlive the lifetime of this [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor).

### Tensor

```
 Tensor(
  DataType type,
  const TensorShape & shape,
  TensorBuffer *buf
)
```
Creates a tensor with the input datatype, shape and buf.

Acquires a ref on buf that belongs to this [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor).

### Tensor

```
 Tensor(
  DataType type,
  TensorShape shape,
  core::RefCountPtr< TensorBuffer > buf
)
```
Creates a tensor with the input datatype, shape and buf.

Takes an ownership of the bufffer from the reference counted pointer.

### Tensor

```
 Tensor(
  DataType type
)
```
Creates an empty [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of the given data type.

Like [Tensor()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aebe57070a84f43b98e63671f52a117fe), returns a 1-dimensional, 0-element [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) with [IsInitialized()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa44336c38c4baf3ed69f63aee131ba87) returning True. See the [Tensor()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aebe57070a84f43b98e63671f52a117fe) documentation for details.

### Tensor

```
 Tensor(
  float scalar_value
)
```

### Tensor

```
 Tensor(
  double scalar_value
)
```

### Tensor

```
 Tensor(
  int32_t scalar_value
)
```

### Tensor

```
 Tensor(
  uint32 scalar_value
)
```

### Tensor

```
 Tensor(
  uint16 scalar_value
)
```

### Tensor

```
 Tensor(
  uint8 scalar_value
)
```

### Tensor

```
 Tensor(
  int16_t scalar_value
)
```

### Tensor

```
 Tensor(
  int8_t scalar_value
)
```

### Tensor

```
 Tensor(
  tstring scalar_value
)
```

### Tensor

```
 Tensor(
  complex64 scalar_value
)
```

### Tensor

```
 Tensor(
  complex128 scalar_value
)
```

### Tensor

```
 Tensor(
  int64_t scalar_value
)
```

### Tensor

```
 Tensor(
  uint64 scalar_value
)
```

### Tensor

```
 Tensor(
  bool scalar_value
)
```

### Tensor

```
 Tensor(
  qint8 scalar_value
)
```

### Tensor

```
 Tensor(
  quint8 scalar_value
)
```

### Tensor

```
 Tensor(
  qint16 scalar_value
)
```

### Tensor

```
 Tensor(
  quint16 scalar_value
)
```

### Tensor

```
 Tensor(
  qint32 scalar_value
)
```

### Tensor

```
 Tensor(
  bfloat16 scalar_value
)
```

### Tensor

```
 Tensor(
  Eigen::half scalar_value
)
```

### Tensor

```
 Tensor(
  ResourceHandle scalar_value
)
```

### Tensor

```
 Tensor(
  const char *scalar_value
)
```

### Tensor

```
 Tensor(
  const Tensor & other
)
```
Copy constructor.

### Tensor

```
 Tensor(
  Tensor && other
)
```
Move constructor.

After this call, is safely destructible can be assigned to, and [IsInitialized()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aa44336c38c4baf3ed69f63aee131ba87) can be called and will return false. Other calls on (e.g. shape manipulation) are not valid.

### Tensor

```
 Tensor(
  T *t
)=delete
```

### TotalBytes

```
size_t TotalBytes() const 
```
Returns the estimated memory usage of this tensor.

### UnsafeCopyFromInternal

```
void UnsafeCopyFromInternal(
  const Tensor & other,
  DataType dtype,
  const TensorShape & shape
)
```
Like BitcastFrom, but CHECK fails if any preconditions are not met.

Deprecated. Use BitcastFrom instead and check the returned Status.

### bit_casted_shaped

```
TTypes< T, NDIMS >::Tensor bit_casted_shaped(
  gtl::ArraySlice< int64_t > new_sizes
)
```
Return the tensor data to an `Eigen::Tensor` with the new shape specified in `new_sizes` and cast to a new dtype `T`.

Using a bitcast is useful for move and copy operations. The allowed bitcast is the only difference from `shaped()`.

### bit_casted_shaped

```
TTypes< T, NDIMS >::ConstTensor bit_casted_shaped(
  gtl::ArraySlice< int64_t > new_sizes
) const 
```
Return the tensor data to an `Eigen::Tensor` with the new shape specified in `new_sizes` and cast to a new dtype `T`.

Using a bitcast is useful for move and copy operations. The allowed bitcast is the only difference from `shaped()`.

### bit_casted_tensor

```
TTypes< T, NDIMS >::Tensor bit_casted_tensor()
```
Return the tensor data to an `Eigen::Tensor` with the same size but a bitwise cast to the specified dtype `T`.

Using a bitcast is useful for move and copy operations. NOTE: this is the same as `tensor()` except a bitcast is allowed.

### bit_casted_tensor

```
TTypes< T, NDIMS >::ConstTensor bit_casted_tensor() const 
```
Return the tensor data to an `Eigen::Tensor` with the same size but a bitwise cast to the specified dtype `T`.

Using a bitcast is useful for move and copy operations. NOTE: this is the same as `tensor()` except a bitcast is allowed.

### data

```
void * data() const 
```

### dim_size

```
int64_t dim_size(
  int d
) const 
```
Convenience accessor for the tensor shape.

### dims

```
int dims() const 
```
Convenience accessor for the tensor shape.

For all shape accessors, see comments for relevant methods of `TensorShape` in `tensor_shape.h`.

### dtype

```
DataType dtype() const 
```
Returns the data type.

### flat

```
TTypes< T >::Flat flat()
```
Return the tensor data as an `Eigen::Tensor` of the data type and a specified shape.

These methods allow you to access the data with the dimensions and sizes of your choice. You do not need to know the number of dimensions of the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) to call them. However, they `CHECK` that the type matches and the dimensions requested creates an `Eigen::Tensor` with the same number of elements as the tensor.

Example:


```
  
    typedef float T;
    Tensor my_ten(...built with Shape{planes: 4, rows: 3, cols: 5}...);
    // 1D Eigen::Tensor, size 60:
    auto flat = my_ten.flat();
    // 2D Eigen::Tensor 12 x 5:
    auto inner = my_ten.flat_inner_dims();
    // 2D Eigen::Tensor 4 x 15:
    auto outer = my_ten.shaped, 2="">({4, 15});
    // CHECK fails, bad num elements:
    auto outer = my_ten.shaped, 2="">({4, 8});
    // 3D Eigen::Tensor 6 x 5 x 2:
    auto weird = my_ten.shaped, 3="">({6, 5, 2});
    // CHECK fails, type mismatch:
    auto bad   = my_ten.flat();</t,></t,></t,>
```

<br />


```

```

<br />

### flat

```
TTypes< T >::ConstFlat flat() const 
```

### flat_inner_dims

```
TTypes< T, NDIMS >::Tensor flat_inner_dims()
```
Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing all [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions but the last NDIMS-1 into the first dimension of the result.

If NDIMS \> [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) then leading dimensions of size 1 will be added to make the output rank NDIMS.

### flat_inner_dims

```
TTypes< T, NDIMS >::ConstTensor flat_inner_dims() const 
```

### flat_inner_outer_dims

```
TTypes< T, NDIMS >::Tensor flat_inner_outer_dims(
  int64_t begin
)
```
Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing the first 'begin' [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions into the first dimension of the result and the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions of the last [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) - 'begin' - NDIMS into the last dimension of the result.

If 'begin' \< 0 then the \|'begin'\| leading dimensions of size 1 will be added. If 'begin' + NDIMS \> [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) then 'begin' + NDIMS - [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) trailing dimensions of size 1 will be added.

### flat_inner_outer_dims

```
TTypes< T, NDIMS >::ConstTensor flat_inner_outer_dims(
  int64_t begin
) const 
```

### flat_outer_dims

```
TTypes< T, NDIMS >::Tensor flat_outer_dims()
```
Returns the data as an Eigen::Tensor with NDIMS dimensions, collapsing all [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) dimensions but the first NDIMS-1 into the last dimension of the result.

If NDIMS \> [dims()](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1ac8a173cc6c97184139bfd81ff45e7da9) then trailing dimensions of size 1 will be added to make the output rank NDIMS.

### flat_outer_dims

```
TTypes< T, NDIMS >::ConstTensor flat_outer_dims() const 
```

### matrix

```
TTypes< T >::Matrix matrix()
```

### matrix

```
TTypes< T >::ConstMatrix matrix() const 
```

### operator=

```
Tensor & operator=(
  const Tensor & other
)
```
Assign operator. This tensor shares other's underlying storage.

### operator=

```
Tensor & operator=(
  Tensor && other
)
```
Move operator. See move constructor for details.

### reinterpret_last_dimension

```
TTypes< T, NDIMS >::Tensor reinterpret_last_dimension()
```
Return the tensor data to an `Eigen::Tensor` with the last dimension elements converted into single elements of a larger type.

For example, this is useful for kernels that can treat NCHW_VECT_C int8 tensors as NCHW int32 tensors. The sizeof(T) should equal the size of the original element type \* num elements in the original last dimension. NDIMS should be 1 less than the original number of dimensions.

### reinterpret_last_dimension

```
TTypes< T, NDIMS >::ConstTensor reinterpret_last_dimension() const 
```
Return the tensor data to an `Eigen::Tensor` with the last dimension elements converted into single elements of a larger type.

For example, this is useful for kernels that can treat NCHW_VECT_C int8 tensors as NCHW int32 tensors. The sizeof(T) should equal the size of the original element type \* num elements in the original last dimension. NDIMS should be 1 less than the original number of dimensions.

### scalar

```
TTypes< T >::Scalar scalar()
```
Return the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) data as a `TensorMap` of fixed size 1: `TensorMap>`.

Using `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor_1aacce92855f6b83eea728203de8016c78` allows the compiler to perform optimizations as the size of the tensor is known at compile time.

### scalar

```
TTypes< T >::ConstScalar scalar() const 
```

### shape

```
const TensorShape & shape() const 
```
Returns the shape of the tensor.

### shaped

```
TTypes< T, NDIMS >::Tensor shaped(
  gtl::ArraySlice< int64_t > new_sizes
)
```

### shaped

```
TTypes< T, NDIMS >::ConstTensor shaped(
  gtl::ArraySlice< int64_t > new_sizes
) const 
```

### tensor

```
TTypes< T, NDIMS >::Tensor tensor() TF_ATTRIBUTE_NOINLINE
```

### tensor

```
TTypes< T, NDIMS >::ConstTensor tensor() const TF_ATTRIBUTE_NOINLINE
```

### tensor_data

```
StringPiece tensor_data() const 
```
Returns a `StringPiece` mapping the current tensor's buffer.

The returned `StringPiece` may point to memory location on devices that the CPU cannot address directly.

NOTE: The underlying tensor buffer is refcounted, so the lifetime of the contents mapped by the `StringPiece` matches the lifetime of the buffer; callers should arrange to make sure the buffer does not get destroyed while the `StringPiece` is still used.

REQUIRES: `DataTypeCanUseMemcpy(dtype())`.

### unaligned_flat

```
TTypes< T >::UnalignedFlat unaligned_flat()
```

### unaligned_flat

```
TTypes< T >::UnalignedConstFlat unaligned_flat() const 
```

### unaligned_shaped

```
TTypes< T, NDIMS >::UnalignedTensor unaligned_shaped(
  gtl::ArraySlice< int64_t > new_sizes
)
```

### unaligned_shaped

```
TTypes< T, NDIMS >::UnalignedConstTensor unaligned_shaped(
  gtl::ArraySlice< int64_t > new_sizes
) const 
```

### vec

```
TTypes< T >::Vec vec()
```
Return the tensor data as an `Eigen::Tensor` with the type and sizes of this `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor`.

Use these methods when you know the data type and the number of dimensions of the [Tensor](https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) and you want an `Eigen::Tensor` automatically sized to the `https://www.tensorflow.org/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` sizes. The implementation check fails if either type or sizes mismatch.

Example:


```
  
    typedef float T;
    Tensor my_mat(...built with Shape{rows: 3, cols: 5}...);
    auto mat = my_mat.matrix();    // 2D Eigen::Tensor, 3 x 5.
    auto mat = my_mat.tensor, 2="">(); // 2D Eigen::Tensor, 3 x 5.
    auto vec = my_mat.vec();       // CHECK fails as my_mat is 2D.
    auto vec = my_mat.tensor, 3="">(); // CHECK fails as my_mat is 2D.
    auto mat = my_mat.matrix();// CHECK fails as type mismatch.</t,></t,>
```

<br />


```

```

<br />

### vec

```
TTypes< T >::ConstVec vec() const 
```
Const versions of all the methods above.

### \~Tensor

```
 ~Tensor()
```

## Public static functions

### BuildTensor

```
Status BuildTensor(
  DataType type,
  const TensorShape & shape,
  Tensor *out_tensor
)
```
Initializes a tensor with the input `type` and `shape`, or returns an error and leaves `out_tensor` unmodified.

This factory method should be used instead of the corresponding constructor if calling code cannot validate that the `DataType` is valid and supported.

The underlying buffer is allocated using a `CPUAllocator`.