|
@@ -4,6 +4,54 @@ |
|
|
using namespace ngla; |
|
|
|
|
|
|
|
|
template<typename T> |
|
|
void ExportSparseMatrix(py::module m) |
|
|
{ |
|
|
py::class_<SparseMatrix<T>, shared_ptr<SparseMatrix<T>>, BaseSparseMatrix, S_BaseMatrix<typename mat_traits<T>::TSCAL>> |
|
|
(m, (string("SparseMatrix") + typeid(T).name()).c_str(), |
|
|
"a sparse matrix in CSR storage") |
|
|
.def("__getitem__", |
|
|
[](const SparseMatrix<T> & self, py::tuple t) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
return self(row,col); |
|
|
}) |
|
|
.def("__setitem__", |
|
|
[](SparseMatrix<T> & self, py::tuple t, T value) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
self(row,col) = value; |
|
|
}) |
|
|
|
|
|
.def("COO", [] (SparseMatrix<T> * sp) -> py::object |
|
|
{ |
|
|
size_t nze = sp->NZE(); |
|
|
Array<int> ri(nze), ci(nze); |
|
|
Vector<T> vals(nze); |
|
|
for (size_t i = 0, ii = 0; i < sp->Height(); i++) |
|
|
{ |
|
|
FlatArray<int> ind = sp->GetRowIndices(i); |
|
|
FlatVector<T> rv = sp->GetRowValues(i); |
|
|
for (int j = 0; j < ind.Size(); j++, ii++) |
|
|
{ |
|
|
ri[ii] = i; |
|
|
ci[ii] = ind[j]; |
|
|
vals[ii] = rv[j]; |
|
|
} |
|
|
} |
|
|
|
|
|
py::object pyri = py::cast(std::move(ri)); |
|
|
py::object pyci = py::cast(std::move(ci)); |
|
|
py::object pyvals = py::cast(std::move(vals)); |
|
|
return py::make_tuple (pyri, pyci, pyvals); |
|
|
}) |
|
|
; |
|
|
|
|
|
py::class_<SparseMatrixSymmetric<T>, shared_ptr<SparseMatrixSymmetric<T>>, SparseMatrix<T>> |
|
|
(m, (string("SparseMatrixSymmetric") + typeid(T).name()).c_str()); |
|
|
} |
|
|
|
|
|
void NGS_DLL_HEADER ExportNgla(py::module &m) { |
|
|
|
|
@@ -445,101 +493,16 @@ void NGS_DLL_HEADER ExportNgla(py::module &m) { |
|
|
; |
|
|
|
|
|
py::class_<S_BaseMatrix<double>, shared_ptr<S_BaseMatrix<double>>, BaseMatrix> |
|
|
(m, "S_BaseMatrixD", "base sparse matrix double") |
|
|
; |
|
|
(m, "S_BaseMatrixD", "base sparse matrix"); |
|
|
py::class_<S_BaseMatrix<Complex>, shared_ptr<S_BaseMatrix<Complex>>, BaseMatrix> |
|
|
(m, "S_BaseMatrixC", "base sparse matrix complex") |
|
|
; |
|
|
|
|
|
py::class_<SparseMatrix<double>, shared_ptr<SparseMatrix<double>>, BaseSparseMatrix, S_BaseMatrix<double> > |
|
|
(m, "SparseMatrixD", |
|
|
"a sparse matrix in CSR storage, entries are real") |
|
|
.def("__getitem__", |
|
|
[](const SparseMatrix<double> & self, py::tuple t) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
return self(row,col); |
|
|
}) |
|
|
.def("__setitem__", |
|
|
[](SparseMatrix<double> & self, py::tuple t, double value) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
self(row,col) = value; |
|
|
}) |
|
|
|
|
|
.def("COO", [] (SparseMatrix<double> * sp) -> py::object |
|
|
{ |
|
|
size_t nze = sp->NZE(); |
|
|
Array<int> ri(nze), ci(nze); |
|
|
Vector<double> vals(nze); |
|
|
for (size_t i = 0, ii = 0; i < sp->Height(); i++) |
|
|
{ |
|
|
FlatArray<int> ind = sp->GetRowIndices(i); |
|
|
FlatVector<double> rv = sp->GetRowValues(i); |
|
|
for (int j = 0; j < ind.Size(); j++, ii++) |
|
|
{ |
|
|
ri[ii] = i; |
|
|
ci[ii] = ind[j]; |
|
|
vals[ii] = rv[j]; |
|
|
} |
|
|
} |
|
|
|
|
|
py::object pyri = py::cast(std::move(ri)); |
|
|
py::object pyci = py::cast(std::move(ci)); |
|
|
py::object pyvals = py::cast(std::move(vals)); |
|
|
return py::make_tuple (pyri, pyci, pyvals); |
|
|
}) |
|
|
; |
|
|
|
|
|
py::class_<SparseMatrix<Complex>, shared_ptr<SparseMatrix<Complex>>, BaseSparseMatrix, S_BaseMatrix<Complex>> |
|
|
(m, "SparseMatrixC", |
|
|
"a sparse matrix in CSR storage, entries are complex") |
|
|
.def("__getitem__", |
|
|
[](const SparseMatrix<Complex> & self, py::tuple t) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
return self(row,col); |
|
|
}) |
|
|
.def("__setitem__", |
|
|
[](SparseMatrix<Complex> & self, py::tuple t, Complex value) |
|
|
{ |
|
|
size_t row = t[0].cast<size_t>(); |
|
|
size_t col = t[1].cast<size_t>(); |
|
|
self(row,col) = value; |
|
|
}) |
|
|
.def("COO", [] (SparseMatrix<Complex> * spc) -> py::object |
|
|
{ |
|
|
size_t nze = spc->NZE(); |
|
|
Array<int> ri(nze), ci(nze); |
|
|
Vector<Complex> vals(nze); |
|
|
for (size_t i = 0, ii = 0; i < spc->Height(); i++) |
|
|
{ |
|
|
FlatArray<int> ind = spc->GetRowIndices(i); |
|
|
FlatVector<Complex> rv = spc->GetRowValues(i); |
|
|
for (int j = 0; j < ind.Size(); j++, ii++) |
|
|
{ |
|
|
ri[ii] = i; |
|
|
ci[ii] = ind[j]; |
|
|
vals[ii] = rv[j]; |
|
|
} |
|
|
} |
|
|
py::object pyri = py::cast(std::move(ri)); |
|
|
py::object pyci = py::cast(std::move(ci)); |
|
|
py::object pyvals = py::cast(std::move(vals)); |
|
|
return py::make_tuple (pyri, pyci, pyvals); |
|
|
}) |
|
|
; |
|
|
|
|
|
|
|
|
py::class_<SparseMatrixSymmetric<double>, shared_ptr<SparseMatrixSymmetric<double>>, SparseMatrix<double>> |
|
|
(m, "SparseMatrixSymmetricD"); |
|
|
|
|
|
py::class_<SparseMatrixSymmetric<Complex>, shared_ptr<SparseMatrixSymmetric<Complex>>, SparseMatrix<Complex>> |
|
|
(m, "SparseMatrixSymmetricC"); |
|
|
|
|
|
(m, "S_BaseMatrixC", "base sparse matrix"); |
|
|
|
|
|
ExportSparseMatrix<double>(m); |
|
|
ExportSparseMatrix<Complex>(m); |
|
|
ExportSparseMatrix<Mat<2,2,double>>(m); |
|
|
ExportSparseMatrix<Mat<2,2,Complex>>(m); |
|
|
ExportSparseMatrix<Mat<3,3,double>>(m); |
|
|
ExportSparseMatrix<Mat<3,3,Complex>>(m); |
|
|
|
|
|
py::class_<BaseBlockJacobiPrecond, shared_ptr<BaseBlockJacobiPrecond>, BaseMatrix> |
|
|
(m, "BlockSmoother", |
|
|