| 36 | namespace py = pybind11; |
| 37 | |
| 38 | class Tensor |
| 39 | : public Resource |
| 40 | , public nvcv::Tensor |
| 41 | { |
| 42 | public: |
| 43 | static Tensor Create(const nvcv::TensorShape &tshape, nvcv::DataType dtype, int rowalign = 0) |
| 44 | { |
| 45 | PyObject *otensor = capi().Tensor_Create(tshape.size(), &tshape[0], static_cast<NVCVDataType>(dtype), |
| 46 | static_cast<NVCVTensorLayout>(tshape.layout()), rowalign); |
| 47 | CheckCAPIError(); |
| 48 | NVCV_ASSERT(otensor != nullptr); |
| 49 | py::object pytensor = py::reinterpret_steal<py::object>(otensor); |
| 50 | |
| 51 | return Tensor(pytensor); |
| 52 | } |
| 53 | |
| 54 | static Tensor Create(const Shape &shape, nvcv::DataType dtype, nvcv::TensorLayout layout = nvcv::TENSOR_NONE, |
| 55 | int rowalign = 0) |
| 56 | { |
| 57 | return Create(CreateNVCVTensorShape(shape, layout), dtype, rowalign); |
| 58 | } |
| 59 | |
| 60 | static Tensor CreateForImageBatch(int numImages, nvcv::Size2D size, nvcv::ImageFormat fmt, int rowalign = 0) |
| 61 | { |
| 62 | PyObject *otensor |
| 63 | = capi().Tensor_CreateForImageBatch(numImages, size.w, size.h, static_cast<NVCVImageFormat>(fmt), rowalign); |
| 64 | CheckCAPIError(); |
| 65 | NVCV_ASSERT(otensor != nullptr); |
| 66 | py::object pytensor = py::reinterpret_steal<py::object>(otensor); |
| 67 | |
| 68 | return Tensor(pytensor); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | friend struct py::detail::type_caster<Tensor>; |
| 73 | |
| 74 | Tensor() = default; |
| 75 | |
| 76 | explicit Tensor(py::object obj) |
| 77 | : Resource(obj) |
| 78 | , nvcv::Tensor(FromHandle(CheckCAPIError(capi().Tensor_GetHandle(this->ptr())), true)) |
| 79 | { |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | } // namespace nvcvpy |
| 84 |
no outgoing calls
no test coverage detected