Deep Learning Approximation of Matrix Functions: From Feedforward Neural Networks to Transformers