Imported from https://github.com/bayesiains/nsf