This seems very mllib specific. I would move it to somewhere in mllib.