Skip to content
Snippets Groups Projects
Verified Commit 85e6bcd9 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: enhance testing of user types

parent ac74a487
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ import numpy as np
rows = 10
cols = 20
def test(mat):
mat[:] = mat.dtype.type(10.)
def test(dtype):
mat = np.ones((rows,cols),dtype=dtype)
mat_copy = mat.copy()
assert (mat == mat_copy).all()
assert not (mat != mat_copy).all()
......@@ -25,18 +25,31 @@ def test(mat):
mat_op = mat.dot(mat.T)
mat_op = mat / mat
mat_op = -mat;
mat_op = -mat
assert (mat >= mat).all()
assert (mat <= mat).all()
assert not (mat > mat).all()
assert not (mat < mat).all()
mat = user_type.create_double(rows,cols)
test(mat)
def test_cast(from_dtype,to_dtype):
np.can_cast(from_dtype,to_dtype)
mat = user_type.create_float(rows,cols)
test(mat)
from_mat = np.zeros((rows,cols),dtype=from_dtype)
to_mat = from_mat.astype(dtype=to_dtype)
test(user_type.CustomDouble)
test_cast(user_type.CustomDouble,np.double)
test_cast(np.double,user_type.CustomDouble)
test_cast(user_type.CustomDouble,np.int64)
test_cast(np.int64,user_type.CustomDouble)
test_cast(user_type.CustomDouble,np.int32)
test_cast(np.int32,user_type.CustomDouble)
test(user_type.CustomFloat)
v = user_type.CustomDouble(1)
a = np.array(v)
......
......@@ -97,6 +97,11 @@ struct CustomType
CustomType operator-() const { return CustomType(-m_value); }
operator Scalar () const
{
return m_value;
}
std::string print() const
{
std::stringstream ss;
......@@ -110,7 +115,7 @@ struct CustomType
return os;
}
protected:
//protected:
Scalar m_value;
};
......@@ -186,4 +191,16 @@ BOOST_PYTHON_MODULE(user_type)
bp::def("build_matrix",build_matrix<double>);
bp::def("print",print<double>);
bp::def("print",print<float>);
eigenpy::registerCast<DoubleType,double>(true);
eigenpy::registerCast<double,DoubleType>(true);
eigenpy::registerCast<DoubleType,int32_t>(false);
eigenpy::registerCast<int32_t,DoubleType>(true);
eigenpy::registerCast<DoubleType,int64_t>(false);
eigenpy::registerCast<int64_t,DoubleType>(true);
eigenpy::registerCast<FloatType,int64_t>(false);
eigenpy::registerCast<int64_t,FloatType>(true);
bp::implicitly_convertible<double,DoubleType>();
bp::implicitly_convertible<DoubleType,double>();
}
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