From 35f635d8ff9a4800ef8ef56f6526b833936ecfaf Mon Sep 17 00:00:00 2001 From: Jiuqiang Tang Date: Fri, 4 Nov 2022 16:37:14 -0700 Subject: [PATCH] Add an argument to packet_creator.create_matrix to allow the input matrix to be transposed first. PiperOrigin-RevId: 486258078 --- mediapipe/python/pybind/packet_creator.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mediapipe/python/pybind/packet_creator.cc b/mediapipe/python/pybind/packet_creator.cc index 421ac44d3..b36fa306a 100644 --- a/mediapipe/python/pybind/packet_creator.cc +++ b/mediapipe/python/pybind/packet_creator.cc @@ -602,8 +602,11 @@ void PublicPacketCreators(pybind11::module* m) { // TODO: Should take "const Eigen::Ref&" // as the input argument. Investigate why bazel non-optimized mode // triggers a memory allocation bug in Eigen::internal::aligned_free(). - [](const Eigen::MatrixXf& matrix) { + [](const Eigen::MatrixXf& matrix, bool transpose) { // MakePacket copies the data. + if (transpose) { + return MakePacket(matrix.transpose()); + } return MakePacket(matrix); }, R"doc(Create a MediaPipe Matrix Packet from a 2d numpy float ndarray. @@ -613,6 +616,8 @@ void PublicPacketCreators(pybind11::module* m) { Args: matrix: A 2d numpy float ndarray. + transpose: A boolean to indicate if the input matrix needs to be transposed. + Default to False. Returns: A MediaPipe Matrix Packet. @@ -625,6 +630,7 @@ void PublicPacketCreators(pybind11::module* m) { np.array([[.1, .2, .3], [.4, .5, .6]]) matrix = mp.packet_getter.get_matrix(packet) )doc", + py::arg("matrix"), py::arg("transpose") = false, py::return_value_policy::move); } // NOLINT(readability/fn_size)