Overloaded apply_tree() and apply_forest() for matrices