generalized matrix indexing