add Mat generator
fix bugs and add some helper methods for Mat
add spec test for Mat