matrix conversion on cython side