| 698 | } |
| 699 | |
| 700 | static handle cast(const Type &src, return_value_policy /* policy */, handle /* parent */) { |
| 701 | const_cast<Type &>(src).makeCompressed(); |
| 702 | |
| 703 | object matrix_type |
| 704 | = module_::import("scipy.sparse").attr(rowMajor ? "csr_matrix" : "csc_matrix"); |
| 705 | |
| 706 | array data(src.nonZeros(), src.valuePtr()); |
| 707 | array outerIndices((rowMajor ? src.rows() : src.cols()) + 1, src.outerIndexPtr()); |
| 708 | array innerIndices(src.nonZeros(), src.innerIndexPtr()); |
| 709 | |
| 710 | return matrix_type(pybind11::make_tuple( |
| 711 | std::move(data), std::move(innerIndices), std::move(outerIndices)), |
| 712 | pybind11::make_tuple(src.rows(), src.cols())) |
| 713 | .release(); |
| 714 | } |
| 715 | |
| 716 | PYBIND11_TYPE_CASTER(Type, |
| 717 | const_name<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", |
no test coverage detected