66 :
TensorList(tensors.begin(), tensors.end()) {}
92 :
TensorList(tensors.begin(), tensors.end()) {}
99 template <
class InputIterator>
101 int64_t
size = std::distance(begin, end);
104 "Empty input tensors cannot initialize a tensorlist.");
113 std::for_each(begin, end, [&](
const Tensor& tensor) ->
void {
116 "Tensors must have the same shape {}, but got {}.",
117 element_shape_, tensor.GetShape());
122 Dtype dtype = begin->GetDtype();
123 std::for_each(begin, end, [&](
const Tensor& tensor) ->
void {
126 "Tensors must have the same dtype {}, but got {}.",
127 dtype.ToString(), tensor.GetDtype().ToString());
132 Device device = begin->GetDevice();
133 std::for_each(begin, end, [&](
const Tensor& tensor) ->
void {
136 "Tensors must have the same device {}, but got {}.",
137 device.ToString(), tensor.GetDevice().ToString());
146 for (
auto iter = begin; iter != end; ++iter, ++i) {
198 void Resize(int64_t new_size);
246 "TensorList has element shape {}, but is expected to have "
255 "TensorList has device {}, but is expected to be {}.",
276 int64_t reserved_size,
277 const Tensor& internal_tensor,
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
TensorList(const SizeVector element_shape, int64_t size, int64_t reserved_size, const Tensor &internal_tensor, bool is_resizable)
Fully specified constructor.
Tensor AsTensor() const
Return the reference of the contained valid tensors with shared memory.
TensorList()
Useful to support operator[] in a map.
void CopyFrom(const TensorList &other)
static TensorList Concatenate(const TensorList &a, const TensorList &b)
TensorList(TensorList &&other)=default
std::string ToString() const
void AssertElementShape(const SizeVector &expected_element_shape) const
SizeVector GetElementShape() const
TensorList(int64_t size, const SizeVector &element_shape, Dtype dtype, const Device &device=Device("CPU:0"))
TensorList(const std::vector< Tensor > &tensors)
TensorList(const SizeVector &element_shape, Dtype dtype, const Device &device=Device("CPU:0"))
TensorList & operator=(const TensorList &other) &=default
TensorList & operator+=(const TensorList &other)
TensorList operator+(const TensorList &other) const
Concatenate two tensorlists.
int64_t GetReservedSize() const
TensorList & operator=(TensorList &&other) &=default
static TensorList FromTensor(const Tensor &tensor, bool inplace=false)
TensorList(const TensorList &other)=default
Tensor internal_tensor_
The internal tensor for data storage.
void Extend(const TensorList &other)
TensorList(const std::initializer_list< Tensor > &tensors)
void Resize(int64_t new_size)
SizeVector element_shape_
The shape for each element tensor in the tensorlist.
void ResizeWithExpand(int64_t new_size)
void PushBack(const Tensor &tensor)
TensorList(InputIterator begin, InputIterator end)
Tensor operator[](int64_t index) const
static int64_t ComputeReserveSize(int64_t size)
void AssertDevice(const Device &expected_device) const
Device GetDevice() const override
SizeVector GetShape() const
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
Generic file read and write utility for python interface.