added function to compute Gram matrix