Verified Commit 6ef0924a authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: return by ref when possible

parent bc99ed26
......@@ -61,13 +61,15 @@ namespace eigenpy
.def(bp::init<Matrix3>
((bp::arg("self"),bp::arg("rotation matrix")),
"Initialize from a rotation matrix"))
.def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quaternion")),"Initialize from a quaternion."))
.def(bp::init<AngleAxis>((bp::arg("self"),bp::arg("copy")),"Copy constructor."))
.def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quaternion")),
"Initialize from a quaternion."))
.def(bp::init<AngleAxis>((bp::arg("self"),bp::arg("copy")),
"Copy constructor."))
/* --- Properties --- */
.add_property("axis",
bp::make_function((const Vector3 & (AngleAxis::*)()const)&AngleAxis::axis,
bp::return_value_policy<bp::copy_const_reference>()),
bp::make_function((Vector3 & (AngleAxis::*)())&AngleAxis::axis,
bp::return_internal_reference<>()),
&AngleAxisVisitor::setAxis,"The rotation axis.")
.add_property("angle",
(Scalar (AngleAxis::*)()const)&AngleAxis::angle,
......@@ -138,7 +140,7 @@ namespace eigenpy
bp::no_init)
.def(AngleAxisVisitor<AngleAxis>());
// Cast to Eigen::RotationBase and vice-versa
// Cast to Eigen::RotationBase
bp::implicitly_convertible<AngleAxis,RotationBase>();
}
......
......@@ -6,6 +6,7 @@
#define __eigenpy_decomposition_eigen_solver_hpp__
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
......@@ -37,31 +38,30 @@ namespace eigenpy
.def("eigenvalues",&Solver::eigenvalues,bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("eigenvectors",&Solver::eigenvectors,bp::arg("self"),
"Returns the eigenvectors of given matrix.",
bp::return_value_policy<bp::return_by_value>())
"Returns the eigenvectors of given matrix.")
.def("compute",&EigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self","matrix"),
"Computes the eigendecomposition of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix, bool))&Solver::compute,
bp::args("self","matrix","compute_eigen_vectors"),
"Computes the eigendecomposition of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("getMaxIterations",&Solver::getMaxIterations,bp::arg("self"),
"Returns the maximum number of iterations.")
.def("setMaxIterations",&Solver::setMaxIterations,bp::args("self","max_iter"),
"Sets the maximum number of iterations allowed.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("pseudoEigenvalueMatrix",&Solver::pseudoEigenvalueMatrix,bp::arg("self"),
"Returns the block-diagonal matrix in the pseudo-eigendecomposition.")
.def("pseudoEigenvectors",&Solver::pseudoEigenvectors ,bp::arg("self"),
"Returns the pseudo-eigenvectors of given matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
......
......@@ -53,22 +53,22 @@ namespace eigenpy
.def("matrixLDLT",&Solver::matrixLDLT,bp::arg("self"),
"Returns the LDLT decomposition matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("rankUpdate",(Solver & (Solver::*)(const Eigen::MatrixBase<VectorType> &, const RealScalar &))&Solver::template rankUpdate<VectorType>,
bp::args("self","vector","sigma"),
bp::return_value_policy<bp::reference_existing_object>() )
bp::return_self<>())
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("adjoint",&Solver::adjoint,bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition itself as if the underlying matrix is self-adjoint.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
#endif
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::compute,
bp::args("self","matrix"),
"Computes the LDLT of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
......
......@@ -43,7 +43,7 @@ namespace eigenpy
"Returns the upper triangular matrix U.")
.def("matrixLLT",&Solver::matrixLLT,bp::arg("self"),
"Returns the LLT decomposition matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("rankUpdate",(Solver (Solver::*)(const VectorType &, const RealScalar &))&Solver::template rankUpdate<VectorType>,
bp::args("self","vector","sigma"))
......@@ -51,13 +51,13 @@ namespace eigenpy
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("adjoint",&Solver::adjoint,bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition itself as if the underlying matrix is self-adjoint.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
#endif
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::compute,
bp::args("self","matrix"),
"Computes the LLT of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
......
......@@ -6,6 +6,7 @@
#define __eigenpy_decomposition_self_adjoint_eigen_solver_hpp__
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
......@@ -37,10 +38,10 @@ namespace eigenpy
.def("eigenvalues",&Solver::eigenvalues,bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("eigenvectors",&Solver::eigenvectors,bp::arg("self"),
"Returns the eigenvectors of given matrix.",
bp::return_value_policy<bp::return_by_value>())
bp::return_internal_reference<>())
.def("compute",&SelfAdjointEigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self","matrix"),
......@@ -49,23 +50,21 @@ namespace eigenpy
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix, int options))&Solver::compute,
bp::args("self","matrix","options"),
"Computes the eigendecomposition of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("computeDirect",&SelfAdjointEigenSolverVisitor::computeDirect_proxy,
bp::args("self","matrix"),
"Computes eigendecomposition of given matrix using a closed-form algorithm.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("computeDirect",(Solver & (Solver::*)(const MatrixType & matrix, int options))&Solver::computeDirect,
bp::args("self","matrix","options"),
"Computes eigendecomposition of given matrix using a closed-form algorithm.",
bp::return_value_policy<bp::reference_existing_object>())
bp::return_self<>())
.def("operatorInverseSqrt",&Solver::operatorInverseSqrt,bp::arg("self"),
"Computes the inverse square root of the matrix.",
bp::return_value_policy<bp::return_by_value>())
"Computes the inverse square root of the matrix.")
.def("operatorSqrt",&Solver::operatorSqrt,bp::arg("self"),
"Computes the inverse square root of the matrix.",
bp::return_value_policy<bp::return_by_value>())
"Computes the inverse square root of the matrix.")
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
......
......@@ -155,7 +155,7 @@ namespace eigenpy
.def("coeffs",(const Vector4 & (Quaternion::*)()const)&Quaternion::coeffs,
bp::arg("self"),
"Returns a vector of the coefficients (x,y,z,w)",
bp::return_value_policy<bp::copy_const_reference>())
bp::return_internal_reference<>())
.def("matrix",&Quaternion::matrix,
bp::arg("self"),
"Returns an equivalent 3x3 rotation matrix. Similar to toRotationMatrix.")
......@@ -216,9 +216,13 @@ namespace eigenpy
.def("__setitem__",&QuaternionVisitor::__setitem__)
.def("__getitem__",&QuaternionVisitor::__getitem__)
.def("assign",&assign<Quaternion>,
bp::args("self","quat"),"Set *this from an quaternion quat and returns a reference to *this.",bp::return_self<>())
bp::args("self","quat"),
"Set *this from an quaternion quat and returns a reference to *this.",
bp::return_self<>())
.def("assign",(Quaternion & (Quaternion::*)(const AngleAxis &))&Quaternion::operator=,
bp::args("self","aa"),"Set *this from an angle-axis aa and returns a reference to *this.",bp::return_self<>())
bp::args("self","aa"),
"Set *this from an angle-axis aa and returns a reference to *this.",
bp::return_self<>())
.def("__str__",&print)
.def("__repr__",&print)
......@@ -251,9 +255,9 @@ namespace eigenpy
{ return self = quat; }
static Quaternion* FromTwoVectors(const Vector3& u, const Vector3& v)
{
{
Quaternion* q(new Quaternion); q->setFromTwoVectors(u,v);
return q;
return q;
}
static bool __eq__(const Quaternion & u, const Quaternion & v)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment