Imported from https://github.com/Element-Research/dpnn