I understand that if $f$ is a modular function, then $g(S)=\max_{A \subseteq S, |A|\leq k} f(A)$ is monotone and submodular in $S$. I am curious about whether this applies to other constraints such as matroid and knapsack constraints. That is, assuming $f$ is a modular function, is the following function $g$ submodular? Here $\cal{I}$ is represents a family of feasible sets subject to a matroid or knapsack constraint.
$$g(S)=\max_{A \subseteq S, A \in \cal{I}} f(A)$$