1 #include "AllClassWrappers.h"
27 #include <pybind11/pybind11.h>
28 #include <pybind11/stl.h>
29 #include <pybind11/eigen.h>
30 #include <pybind11/iostream.h>
47 py::class_<LinearOperator, ModPiece, WorkPiece, std::shared_ptr<LinearOperator>> lo(m,
"LinearOperator");
49 .def(
"rows", &LinearOperator::rows)
50 .def(
"cols", &LinearOperator::cols)
51 .def(
"GetMatrix", &LinearOperator::GetMatrix);
53 py::class_<AffineOperator, ModPiece, WorkPiece, std::shared_ptr<AffineOperator>>(m,
"AffineOperator")
54 .def(py::init([](Eigen::MatrixXd
const& Ain, Eigen::VectorXd
const& bIn) {
55 return std::make_shared<AffineOperator>(Ain, bIn);;
57 .def(py::init<std::shared_ptr<LinearOperator>,Eigen::VectorXd>())
63 py::class_<EigenLinearOperator<Eigen::MatrixXd>,
LinearOperator,
ModPiece,
WorkPiece, std::shared_ptr<EigenLinearOperator<Eigen::MatrixXd>>> elo(m,
"DenseLinearOperator");
65 .def(py::init<Eigen::MatrixXd>())
66 .def(
"Apply", &EigenLinearOperator<Eigen::MatrixXd>::Apply)
67 .def(
"ApplyTranspose", &EigenLinearOperator<Eigen::MatrixXd>::ApplyTranspose);
69 py::class_<IdentityOperator, LinearOperator, ModPiece, WorkPiece, std::shared_ptr<IdentityOperator>> io(m,
"IdentityOperator");
71 .def(py::init<unsigned int>())
85 py::class_<BlockDiagonalOperator, LinearOperator, std::shared_ptr<BlockDiagonalOperator>> bdOp(m,
"BlockDiagonalOperator");
87 .def(py::init<std::vector<std::shared_ptr<LinearOperator>>
const&>())
94 py::class_<BlockRowOperator, LinearOperator, std::shared_ptr<BlockRowOperator>> brOp(m,
"BlockRowOperator");
96 .def(py::init<std::vector<std::shared_ptr<LinearOperator>>
const&>())
103 py::class_<CompanionMatrix, LinearOperator, std::shared_ptr<CompanionMatrix>> compMat(m,
"CompanionMatrix");
105 .def(py::init<Eigen::VectorXd const&>())
110 py::class_<ConcatenateOperator, LinearOperator, std::shared_ptr<ConcatenateOperator>> concatOp(m,
"ConcatenateOperator");
112 .def(py::init<std::vector<std::shared_ptr<LinearOperator>>
const&,
const int>())
119 py::class_<DiagonalOperator, LinearOperator, std::shared_ptr<DiagonalOperator>> diagOp(m,
"DiagonalOperator");
121 .def(py::init<Eigen::VectorXd const&>())
126 py::class_<KroneckerProductOperator, LinearOperator, std::shared_ptr<KroneckerProductOperator>> kpOp(m,
"KroneckerProductOperator");
128 .def(py::init<std::shared_ptr<LinearOperator>, std::shared_ptr<LinearOperator>>())
132 py::class_<ProductOperator, LinearOperator, std::shared_ptr<ProductOperator>> prOp(m,
"ProductOperator");
134 .def(py::init<std::shared_ptr<LinearOperator>, std::shared_ptr<LinearOperator>>())
139 py::class_<SumOperator, LinearOperator, std::shared_ptr<SumOperator>> sumOp(m,
"SumOperator");
141 .def(py::init<std::shared_ptr<LinearOperator>, std::shared_ptr<LinearOperator>>())
146 py::class_<ZeroOperator, LinearOperator, std::shared_ptr<ZeroOperator>> zeroOp(m,
"ZeroOperator");
148 .def(py::init<int, int>())
152 py::class_<SliceOperator, LinearOperator, std::shared_ptr<SliceOperator>>(m,
"SliceOperator")
153 .def(py::init<int, int,int,int>())
157 py::class_<HessianOperator, LinearOperator, std::shared_ptr<HessianOperator>>(m,
"HessianOperator")
158 .def(py::init<std::shared_ptr<ModPiece>
const&, std::vector<Eigen::VectorXd>
const&,
unsigned int,
unsigned int,
unsigned int, Eigen::VectorXd
const&,
double,
double>(),
165 py::arg(
"scaleIn")=1.0,
166 py::arg(
"nuggetIn")=0.0)
170 py::class_<GaussNewtonOperator, LinearOperator, std::shared_ptr<GaussNewtonOperator>>(m,
"GaussNewtonOperator")
171 .def(py::init<std::shared_ptr<ModPiece>
const&, std::shared_ptr<ModPiece>
const&, std::vector<Eigen::VectorXd>
const&,
unsigned int,
double,
double>(),
172 py::arg(
"forwardModelIn"),
173 py::arg(
"noiseModelIn"),
176 py::arg(
"scaleIn")=1.0,
177 py::arg(
"nuggetIn")=0.0)
181 py::class_<GeneralizedEigenSolver, std::shared_ptr<GeneralizedEigenSolver>>(m,
"GeneralizedEigenSolver")
185 py::class_<StochasticEigenSolver, GeneralizedEigenSolver, std::shared_ptr<StochasticEigenSolver>>(m,
"StochasticEigenSolver")
186 .def(py::init<int,double,double,int,int,int,int>(),
187 py::arg(
"numEigsIn"),
188 py::arg(
"eigRelTolIn")=0.0,
189 py::arg(
"eigAbsTolIn")=0.0,
190 py::arg(
"expectedRankIn")=-1,
191 py::arg(
"samplingFactorIn")=-1,
192 py::arg(
"blockSize=10"),
193 py::arg(
"verbosityIn")=0)
195 .def(
"compute", &
StochasticEigenSolver::compute, py::arg(
"A"), py::arg(
"B")=
nullptr, py::arg(
"Binv")=
nullptr, py::call_guard<py::scoped_ostream_redirect,
196 py::scoped_estream_redirect>());
std::shared_ptr< LinearOperator > Linear() const
Eigen::VectorXd const & Offset() const
std::vector< std::shared_ptr< LinearOperator > > const & GetBlocks() const
virtual Eigen::MatrixXd GetMatrix() override
std::shared_ptr< LinearOperator > GetBlock(int i) const
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
std::vector< std::shared_ptr< LinearOperator > > const & GetBlocks() const
virtual Eigen::MatrixXd GetMatrix() override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
std::shared_ptr< LinearOperator > GetBlock(int i) const
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd GetMatrix() override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
static std::shared_ptr< ConcatenateOperator > HStack(std::shared_ptr< LinearOperator > Ain, std::shared_ptr< LinearOperator > Bin)
static std::shared_ptr< ConcatenateOperator > VStack(std::shared_ptr< LinearOperator > Ain, std::shared_ptr< LinearOperator > Bin)
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd GetMatrix() override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd GetMatrix() override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
Eigen::VectorXd const & eigenvalues() const
Eigen::MatrixXd const & eigenvectors() const
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x)
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x)
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
Generic linear operator base class.
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x)=0
Provides an abstract interface for defining vector-valued model components.
virtual Eigen::MatrixXd GetMatrix() override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
Two-pass stochastic algorithm for computing generalized eigenvalues from matrix products.
virtual StochasticEigenSolver & compute(std::shared_ptr< LinearOperator > const &A, std::shared_ptr< LinearOperator > B=nullptr, std::shared_ptr< LinearOperator > Binv=nullptr)
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd GetMatrix() override
Base class for MUQ's modelling envronment.
virtual Eigen::MatrixXd ApplyTranspose(Eigen::Ref< const Eigen::MatrixXd > const &x) override
virtual Eigen::MatrixXd Apply(Eigen::Ref< const Eigen::MatrixXd > const &x) override
void LinearOperatorWrapper(pybind11::module &m)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)