Skip to content
Snippets Groups Projects
Commit abc9fae9 authored by Wilson Jallet's avatar Wilson Jallet :clapper:
Browse files

std-vector: try setting elements to zero

* does not work properly
parent 51d1672e
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ np.random.seed(0)
l1 = [np.random.randn(3), np.random.randn(2)]
l2 = eigenpy.StdVec_VectorXd(l1)
l3 = [np.random.randn(2, 2), np.random.randn(1, 2), np.random.randn(2, 6)]
l3 = [np.random.randn(2, 2), np.random.randn(3, 1), np.random.randn(4, 2)]
def checkAllValues(li1, li2):
......@@ -33,11 +33,31 @@ print()
l4 = [np.random.randn(3, 3) for _ in range(4)]
assert "StdVec_Mat3d" in printVectorOf3x3.__doc__
printVectorOf3x3(l4)
print()
l4_copy = copyStdVector(l4)
assert isinstance(l4_copy, eigenpy.StdVec_MatrixXd)
print(l4_copy)
l4_copy2 = vector.copyStdVec_3x3(l4)
assert isinstance(l4_copy2, vector.StdVec_Mat3d)
print(l4_copy2)
def checkZero(l):
for x in l:
assert np.allclose(x, 0.), "x = {}".format(x)
print("l1:")
vector.setZero(l1)
print(l1)
checkZero(l1)
print("l2:")
l2_py = l2.tolist()
vector.setZero(l2_py)
print(l2_py)
checkZero(l2_py)
print("l3:")
vector.setZero(l3)
checkZero(l3)
......@@ -18,10 +18,19 @@ std::vector<MatType> copy(const std::vector<MatType> &Ms) {
return out;
}
template<typename MatType>
void setZero(std::vector<MatType> Ms) {
for (std::size_t i = 0; i < Ms.size(); i++) {
Ms[i].setZero();
}
}
BOOST_PYTHON_MODULE(vector) {
namespace bp = boost::python;
using namespace eigenpy;
eigenpy::enableEigenPy();
enableEigenPy();
bp::def("printVectorOfMatrix", printVectorOfMatrix<Eigen::VectorXd>);
bp::def("printVectorOfMatrix", printVectorOfMatrix<Eigen::MatrixXd>);
......@@ -29,8 +38,12 @@ BOOST_PYTHON_MODULE(vector) {
bp::def("copyStdVector", copy<Eigen::MatrixXd>);
bp::def("copyStdVector", copy<Eigen::VectorXd>);
eigenpy::StdVectorPythonVisitor<std::vector<Eigen::Matrix3d>>::expose(
StdVectorPythonVisitor<std::vector<Eigen::Matrix3d>>::expose(
"StdVec_Mat3d", "3D matrices.");
bp::def("printVectorOf3x3", printVectorOfMatrix<Eigen::Matrix3d>);
bp::def("copyStdVec_3x3", copy<Eigen::Matrix3d>, bp::args("mats"));
typedef Eigen::Ref<Eigen::MatrixXd> MatRef;
StdVectorPythonVisitor<std::vector<MatRef>, true>::expose("StdVec_MatRef");
bp::def("setZero", setZero<MatRef>, "Sets the coeff in [0,0] to 0.");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment