cython implementation of score() and feature2dim()