28 py::class_<TensorList> tensorlist(
30 "A TensorList is an extendable tensor at the 0-th dimension.");
33 tensorlist.def(py::init([](
const SizeVector& element_shape,
35 return new TensorList(element_shape, dtype, device);
37 "element_shape"_a,
"dtype"_a,
"device"_a);
38 tensorlist.def(py::init([](
const std::vector<Tensor>& tensors) {
42 tensorlist.def(py::init([](
const TensorList& other) {
56 tensorlist.def(
"__getitem__",
57 [](
TensorList& tl, int64_t index) {
return tl[index]; });
58 tensorlist.def(
"__setitem__",
62 tensorlist.def(
"as_tensor",
64 tensorlist.def(
"__repr__",
66 tensorlist.def(
"__str__",
73 tensorlist.def(
"__iadd__", &TensorList::operator+=);
74 tensorlist.def(
"__add__", &TensorList::operator+);
84 tensorlist.def_property_readonly(
"element_shape",
Tensor AsTensor() const
Return the reference of the contained valid tensors with shared memory.
void CopyFrom(const TensorList &other)
static TensorList Concatenate(const TensorList &a, const TensorList &b)
std::string ToString() const
SizeVector GetElementShape() const
static TensorList FromTensor(const Tensor &tensor, bool inplace=false)
void Extend(const TensorList &other)
void Resize(int64_t new_size)
void PushBack(const Tensor &tensor)
void pybind_core_tensorlist(py::module &m)
Generic file read and write utility for python interface.