to form sparse matrix