Imported from https://github.com/comratvlad/sv_softmax