lsst.afw  13.0-92-g8ecf155+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
leastSquares.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <pybind11/pybind11.h>
24 //#include <pybind11/operators.h>
25 //#include <pybind11/stl.h>
26 
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
29 #include "ndarray/converter.h"
30 //#include "ndarray/eigen.h"
31 
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 using namespace lsst::afw::math;
38 
39 template <typename T1, typename T2, int C1, int C2>
40 void declareLeastSquares(py::module &mod) {
41  py::class_<LeastSquares> cls(mod, "LeastSquares");
42  py::enum_<LeastSquares::Factorization>(cls, "Factorization")
43  .value("NORMAL_EIGENSYSTEM", LeastSquares::Factorization::NORMAL_EIGENSYSTEM)
44  .value("NORMAL_CHOLESKY", LeastSquares::Factorization::NORMAL_CHOLESKY)
45  .value("DIRECT_SVD", LeastSquares::Factorization::DIRECT_SVD)
46  .export_values();
47  cls.def_static("fromDesignMatrix",
48  (LeastSquares(*)(ndarray::Array<T1, 2, C1> const &, ndarray::Array<T2, 1, C2> const &,
50  LeastSquares::fromDesignMatrix<T1, T2, C1, C2>,
51  "design"_a, "data"_a, "factorization"_a = LeastSquares::NORMAL_EIGENSYSTEM);
52  cls.def_static("fromNormalEquations",
53  (LeastSquares(*)(ndarray::Array<T1, 2, C1> const &, ndarray::Array<T2, 1, C2> const &,
55  LeastSquares::fromNormalEquations<T1, T2, C1, C2>,
56  "fisher"_a, "rhs"_a, "factorization"_a = LeastSquares::NORMAL_EIGENSYSTEM);
57  cls.def("getRank", &LeastSquares::getRank);
58  cls.def("setDesignMatrix",
59  (void (LeastSquares::*)(ndarray::Array<T1, 2, C1> const &, ndarray::Array<T2, 1, C2> const &)) &
60  LeastSquares::setDesignMatrix<T1, T2, C1, C2>);
61  cls.def("getDimension", &LeastSquares::getDimension);
62  cls.def("setNormalEquations",
63  (void (LeastSquares::*)(ndarray::Array<T1, 2, C1> const &, ndarray::Array<T2, 1, C2> const &)) &
64  LeastSquares::setNormalEquations<T1, T2, C1, C2>);
65  cls.def("getSolution", &LeastSquares::getSolution);
66  cls.def("getFisherMatrix", &LeastSquares::getFisherMatrix);
67  cls.def("getCovariance", &LeastSquares::getCovariance);
68  cls.def("getFactorization", &LeastSquares::getFactorization);
69  cls.def("getDiagnostic", &LeastSquares::getDiagnostic);
70  cls.def("getThreshold", &LeastSquares::getThreshold);
71  cls.def("setThreshold", &LeastSquares::setThreshold);
72 };
73 
74 PYBIND11_PLUGIN(_leastSquares) {
75  py::module mod("_leastSquares", "Python wrapper for afw _leastSquares library");
76 
77  if (_import_array() < 0) {
78  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
79  return nullptr;
80  };
81 
82  declareLeastSquares<double, double, 0, 0>(mod);
83 
84  /* Module level */
85 
86  /* Member types and enums */
87 
88  /* Constructors */
89 
90  /* Operators */
91 
92  /* Members */
93 
94  return mod.ptr();
95 }
Solver for linear least-squares problems.
Definition: LeastSquares.h:67
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
void declareLeastSquares(py::module &mod)
Definition: leastSquares.cc:40
double const _a
Definition: RandomImage.cc:77
Factorization
Private implementation; forward-declared publicly so we can inherit from it in .cc.
Definition: LeastSquares.h:71