Generalized_inverse function

I would like to compute the Moore-Penrose matrix inverse, but cannot install the version of Stan that has the generalized_inverse function added. Is there anyway someone can provide me with the code so I can simply add it as a function to my Stan script? I’m open to other suggestions as well.

I’m using R 4.1.2 and rstan 2.21.3