| 47 | } |
| 48 | |
| 49 | nanobind::object cmat_to_numpy(complex_matrix &cmat) { |
| 50 | auto rows = cmat.rows(); |
| 51 | auto cols = cmat.cols(); |
| 52 | auto *data = cmat.get_data(complex_matrix::order::row_major); |
| 53 | |
| 54 | // Use .cast() to force immediate creation of the numpy array. |
| 55 | // Since no owner is specified, rv_policy::automatic will copy the data, |
| 56 | // making this safe even when cmat is a temporary (e.g. in get_unitary). |
| 57 | return nanobind::ndarray<nanobind::numpy, std::complex<double>, |
| 58 | nanobind::shape<-1, -1>>(data, {rows, cols}, |
| 59 | nanobind::handle()) |
| 60 | .cast(); |
| 61 | }; |
| 62 | |
| 63 | } // namespace cudaq::detail |
no test coverage detected