Improve (no)specialization in print_matrix (#39194)
It makes sense to extract the axes before we lose inferrability
of the vector or matrix being printed. Hence this delays
application of `@nospecialize`. However, it also standardizes
the row/column indices and reduces specialization in `alignment`.
Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>