| 35 | namespace py = pybind11; |
| 36 | |
| 37 | class Array |
| 38 | : public Resource |
| 39 | , public nvcv::Array |
| 40 | { |
| 41 | public: |
| 42 | static Array Create(int64_t length, nvcv::DataType dtype) |
| 43 | { |
| 44 | PyObject *oarray = capi().Array_Create(length, dtype); |
| 45 | CheckCAPIError(); |
| 46 | NVCV_ASSERT(oarray == nullptr); |
| 47 | py::object pyarray = py::reinterpret_steal<py::object>(oarray); |
| 48 | return Array(pyarray); |
| 49 | } |
| 50 | |
| 51 | static Array Create(const Shape &shape, nvcv::DataType dtype) |
| 52 | { |
| 53 | return Create(LengthIf1D(shape), dtype); |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | friend struct py::detail::type_caster<Array>; |
| 58 | |
| 59 | Array() = default; |
| 60 | |
| 61 | explicit Array(py::object obj) |
| 62 | : Resource(obj) |
| 63 | , nvcv::Array(FromHandle(CheckCAPIError(capi().Array_GetHandle(this->ptr())), true)) |
| 64 | { |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | } // namespace nvcvpy |
| 69 | |