Exploiting Compositional Structure for Automatic and Efficient Numerical Linear Algebra