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

ufunc: use Eigen algebra to compute dotfunc

parent 06e4150d
No related branches found
No related tags found
No related merge requests found
...@@ -199,18 +199,15 @@ namespace eigenpy ...@@ -199,18 +199,15 @@ namespace eigenpy
void * op, npy_intp n, void * /*arr*/) void * op, npy_intp n, void * /*arr*/)
{ {
// std::cout << "dotfunc" << std::endl; // std::cout << "dotfunc" << std::endl;
T res(0); typedef Eigen::Matrix<T,Eigen::Dynamic,1> VectorT;
char *ip0 = (char*)ip0_, *ip1 = (char*)ip1_; typedef Eigen::InnerStride<Eigen::Dynamic> InputStride;
npy_intp i; typedef const Eigen::Map<const VectorT,0,InputStride> ConstMapType;
for(i = 0; i < n; i++)
{ ConstMapType
v0(static_cast<T*>(ip0_),n,InputStride(is0/sizeof(T))),
res += *static_cast<T*>(static_cast<void*>(ip0)) v1(static_cast<T*>(ip1_),n,InputStride(is1/sizeof(T)));
* *static_cast<T*>(static_cast<void*>(ip1));
ip0 += is0; *static_cast<T*>(op) = v0.dot(v1);
ip1 += is1;
}
*static_cast<T*>(op) = res;
} }
......
...@@ -7,6 +7,7 @@ cols = 20 ...@@ -7,6 +7,7 @@ cols = 20
def test(dtype): def test(dtype):
mat = np.ones((rows,cols),dtype=dtype) mat = np.ones((rows,cols),dtype=dtype)
mat = np.random.rand(rows,cols).astype(dtype)
mat_copy = mat.copy() mat_copy = mat.copy()
assert (mat == mat_copy).all() assert (mat == mat_copy).all()
assert not (mat != mat_copy).all() assert not (mat != mat_copy).all()
...@@ -33,8 +34,11 @@ def test(dtype): ...@@ -33,8 +34,11 @@ def test(dtype):
assert not (mat < mat).all() assert not (mat < mat).all()
mat2 = mat.dot(mat.T) mat2 = mat.dot(mat.T)
mat2_ref = mat.astype(np.double).dot(mat.T.astype(np.double))
assert np.isclose(mat2.astype(np.double),mat2_ref).all()
if np.__version__ >= '1.17.0': if np.__version__ >= '1.17.0':
mat2 = np.matmul(mat,mat.T) mat2 = np.matmul(mat,mat.T)
assert np.isclose(mat2.astype(np.double),mat2_ref).all()
def test_cast(from_dtype,to_dtype): def test_cast(from_dtype,to_dtype):
np.can_cast(from_dtype,to_dtype) np.can_cast(from_dtype,to_dtype)
......
...@@ -200,6 +200,8 @@ BOOST_PYTHON_MODULE(user_type) ...@@ -200,6 +200,8 @@ BOOST_PYTHON_MODULE(user_type)
eigenpy::registerCast<int32_t,DoubleType>(true); eigenpy::registerCast<int32_t,DoubleType>(true);
eigenpy::registerCast<DoubleType,int64_t>(false); eigenpy::registerCast<DoubleType,int64_t>(false);
eigenpy::registerCast<int64_t,DoubleType>(true); eigenpy::registerCast<int64_t,DoubleType>(true);
eigenpy::registerCast<FloatType,double>(true);
eigenpy::registerCast<double,FloatType>(false);
eigenpy::registerCast<FloatType,int64_t>(false); eigenpy::registerCast<FloatType,int64_t>(false);
eigenpy::registerCast<int64_t,FloatType>(true); eigenpy::registerCast<int64_t,FloatType>(true);
......
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