add low rank gram matrix function