| 395 | } |
| 396 | |
| 397 | void Tensor::Export(py::module &m) |
| 398 | { |
| 399 | using namespace py::literals; |
| 400 | |
| 401 | py::class_<nvcv::TensorLayout>(m, "TensorLayout") |
| 402 | .def(py::init<const char *>()) |
| 403 | #define NVCV_DETAIL_DEF_TLAYOUT(LAYOUT) .def_readonly_static(#LAYOUT, &nvcv::TENSOR_##LAYOUT) |
| 404 | #include <nvcv/TensorLayoutDef.inc> |
| 405 | #undef NVCV_DETAIL_DEF_TLAYOUT |
| 406 | .def(py::self == py::self, "Check if two TensorLayout objects are equal.") |
| 407 | .def(py::self != py::self, "Check if two TensorLayout objects are not equal.") |
| 408 | .def("__repr__", &TensorLayoutToString, "Return the string representation of the TensorLayout object."); |
| 409 | |
| 410 | py::implicitly_convertible<py::str, nvcv::TensorLayout>(); |
| 411 | |
| 412 | py::class_<Tensor, std::shared_ptr<Tensor>, Container>(m, "Tensor", "Tensor") |
| 413 | .def(py::init(&Tensor::CreateForImageBatch), "nimages"_a, "imgsize"_a, "format"_a, "rowalign"_a = 0, |
| 414 | "Create a Tensor object for an ImageBatch.") |
| 415 | .def(py::init(&Tensor::Create), "shape"_a, "dtype"_a, "layout"_a = std::nullopt, "rowalign"_a = 0, |
| 416 | "Create a Tensor object with the given shape, data type and layout.") |
| 417 | .def_property_readonly("layout", &Tensor::layout, "The TensorLayout of the Tensor.") |
| 418 | .def_property_readonly("shape", &Tensor::shape, "The shape of the Tensor.") |
| 419 | .def_property_readonly("dtype", &Tensor::dtype, "The data type of the Tensor.") |
| 420 | // numpy and others use ndim, let's be consistent with them in python. |
| 421 | // It's not a requirement to be consistent between NVCV Python and C/C++. |
| 422 | // Each language use whatever is appropriate (and expected) in their environment. |
| 423 | .def_property_readonly("ndim", &Tensor::rank, "The number of dimensions of the Tensor.") |
| 424 | .def("cuda", &Tensor::cuda, "Reference to the Tensor on the CUDA device.") |
| 425 | .def("reshape", &Tensor::Reshape, "shape"_a, "layout"_a = std::nullopt, |
| 426 | "Produces a tensor pointing to the same data but with a new shape and layout.") |
| 427 | .def("__repr__", &util::ToString<Tensor>, "Return the string representation of the Tensor object."); |
| 428 | |
| 429 | m.def("as_tensor", &Tensor::Wrap, "buffer"_a, "layout"_a = std::nullopt, |
| 430 | "Wrap an existing buffer into a Tensor object with the given layout."); |
| 431 | m.def("as_tensor", &Tensor::WrapImage, "image"_a, "Wrap an existing image into a Tensor object."); |
| 432 | m.def("reshape", &Tensor::ReshapeTensor, "tensor"_a, "shape"_a, "layout"_a = std::nullopt, |
| 433 | "Produces a tensor pointing to the same data but with a new shape and layout."); |
| 434 | } |
| 435 | |
| 436 | } // namespace nvcvpy::priv |
nothing calls this directly
no outgoing calls
no test coverage detected