Generalized perfectly matched layer for the absorption of propagating and evanescent waves in lossless and lossy media