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

Method Export

python/mod_cvcuda/nvcv/Array.cpp:329–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329void Array::Export(py::module &m)
330{
331 using namespace py::literals;
332
333 using CreateFromLengthPtr = std::shared_ptr<Array> (*)(int64_t, nvcv::DataType);
334 using CreateFromShapePtr = std::shared_ptr<Array> (*)(const Shape &, nvcv::DataType);
335
336 using ResizeLengthPtr = std::shared_ptr<Array> (Array::*)(int64_t DataType);
337 using ResizeShapePtr = std::shared_ptr<Array> (Array::*)(Shape);
338
339 using ResizeArrayLengthPtr = std::shared_ptr<Array> (*)(Array &, int64_t DataType);
340 using ResizeArrayShapePtr = std::shared_ptr<Array> (*)(Array &, Shape);
341
342 py::class_<Array, std::shared_ptr<Array>, Container>(m, "Array", "Array")
343 .def(py::init(static_cast<CreateFromLengthPtr>(&Array::Create)), "length"_a, "dtype"_a,
344 "Create a Array object with the given length and data type.")
345 .def(py::init(static_cast<CreateFromShapePtr>(&Array::Create)), "shape"_a, "dtype"_a,
346 "Create a Array object with the given shape and data type.")
347 .def_property_readonly("shape", &Array::shape, "The shape of the Array.")
348 .def_property_readonly("dtype", &Array::dtype, "The data type of the Array.")
349 // numpy and others use ndim, let's be consistent with them in python.
350 // It's not a requirement to be consistent between NVCV Python and C/C++.
351 // Each language use whatever is appropriate (and expected) in their environment.
352 .def_property_readonly("ndim", &Array::rank, "The number of dimensions of the Array.")
353 .def("cuda", &Array::cuda, "Reference to the Array on the CUDA device.")
354 .def("resize", static_cast<ResizeLengthPtr>(&Array::Resize), "length"_a,
355 "Produces an array pointing to the same data but with a new length.")
356 .def("resize", static_cast<ResizeShapePtr>(&Array::Resize), "shape"_a,
357 "Produces an array pointing to the same data but with a new shape.")
358 .def("__repr__", &util::ToString<Array>, "Return the string representation of the Array object.");
359
360 m.def("as_array", &Array::Wrap, "buffer"_a, "Wrap an existing buffer into a Array object with the given layout.");
361 m.def("resize", static_cast<ResizeArrayLengthPtr>(&Array::ResizeArray), "array"_a, "length"_a,
362 "Produces an array pointing to the same data but with a new length.");
363 m.def("resize", static_cast<ResizeArrayShapePtr>(&Array::ResizeArray), "array"_a, "shape"_a,
364 "Produces an array pointing to the same data but with a new shape.");
365}
366
367} // namespace nvcvpy::priv

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected