MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / Export

Method Export

python/mod_cvcuda/nvcv/TensorBatch.cpp:239–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239void TensorBatch::Export(py::module &m)
240{
241 using namespace py::literals;
242
243 py::class_<TensorBatch, std::shared_ptr<TensorBatch>, Container>(
244 m, "TensorBatch",
245 "Container for a batch of tensors.\n"
246 "The capacity of the container must be specified upfront in the batch initialization.\n"
247 "The tensors in the batch may differ in shapes but they must have "
248 "a uniform dimensionality, data type and layout.")
249 .def(py::init(&TensorBatch::Create), "capacity"_a,
250 "Create a new TensorBatch object with the specified capacity.")
251 .def_property_readonly("layout", &TensorBatch::layout,
252 "Layout of the tensors in the tensor batch."
253 " None if the batch is empty.")
254 .def_property_readonly("dtype", &TensorBatch::dtype,
255 "Data type of tensors in the tensor batch."
256 " None if the batch is empty.")
257 .def_property_readonly("capacity", &TensorBatch::capacity, "Capacity of the tensor batch.")
258 .def_property_readonly("ndim", &TensorBatch::rank,
259 "Return the number of dimensions of the tensors or -1 for an empty batch")
260 .def("__len__", &TensorBatch::numTensors, "Return the number of tensors.")
261 .def(
262 "__iter__", [](const TensorBatch &batch) { return py::make_iterator(batch); },
263 "Return an iterator over the tensors in the TensorBatch.")
264 .def("__setitem__", &TensorBatch::set_at, "Set tensor at a given index.")
265 .def("__getitem__", &TensorBatch::at, "Get a tensor at a given index.")
266 .def("pushback", &TensorBatch::pushBack, "Add a new image to the end of the TensorBatch.")
267 .def("pushback", &TensorBatch::pushBackMany, "Add multiple images to the end of the TensorBatch.")
268 .def("popback", &TensorBatch::popBack, "count"_a = 1,
269 "Remove one or more images from the end of the TensorBatch.")
270 .def("clear", &TensorBatch::clear, "Remove all images from the TensorBatch.");
271
272 m.def("as_tensors", &TensorBatch::WrapExternalBufferVector, "buffers"_a = std::vector<py::object>{},
273 "layout"_a = std::nullopt, py::keep_alive<0, 1>(),
274 "Wrap a list of external buffers as a batch of tensors, and tie the buffers lifetime to it");
275}
276
277} // namespace nvcvpy::priv

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected