Accessing the "diagonal" of a re-indexed matrix

I somewhat frequently have the situation where I have a matrix (or higher dimensional structure) which represents an intercept for some interaction of categorical variables. So I need to access it by re-indexing, as in:

 matrix[J_Edu, J_Race] alpha_Edu_Race;

  vector[N_SurveyData] alpha_Edu_Race_v;
  for (n in 1:N_SurveyData) {
    alpha_Edu_Race_v[n] = alpha_Edu_Race[SurveyData_Edu[n], SurveyData_Race[n]];

Now I can access alpha_Edu_Race[SurveyData_Edu, SurveyData_Race] as a vector. Is there a way to do that more directly? I’ve tried the diagonal function, as in diagonal(alpha_Edu_Race[SurveyData_Edu, SurveyData_Race]), but that made things orders of magnitude slower.

Is there some other way to express this?