Skip to content

Support softmax for row_vector, matrix types + code simplifications#3313

Open
jachymb wants to merge 7 commits intostan-dev:developfrom
jachymb:jachymb_softmax
Open

Support softmax for row_vector, matrix types + code simplifications#3313
jachymb wants to merge 7 commits intostan-dev:developfrom
jachymb:jachymb_softmax

Conversation

@jachymb
Copy link
Copy Markdown

@jachymb jachymb commented Apr 28, 2026

Summary

This refactors the softmax and log_softmax functions in the following ways:

  • both vector and row_vector are now supported instead of just vector
  • matrix type is also supported and the softmax is applied row-wise. (i.e. the return value is effectively a row_stochastic_matrix for modelling purposes)
  • refactored the relevant code to utilize Eigen functionalities instead of some for loops and some other bits here and there, simplifying the code and improving clarity. I am honestly not a C++ guru, but I believe these shouldn't have any negative impact on performance.

Tests

  • Added test for the new types
  • Added a test for the edge case when some of the values is -inf

Side Effects

None to my knowledge.

Release notes

softmax and log_softmax now support row_vector and matrix (applied row-wise)

Checklist

@jachymb
Copy link
Copy Markdown
Author

jachymb commented Apr 29, 2026

I think it's some server error, not actual test failure.

@SteveBronder
Copy link
Copy Markdown
Collaborator

SteveBronder commented Apr 29, 2026

@serban-nicusor-toptal Can you take a look at https://jenkins.flatironinstitute.org/blue/organizations/jenkins/Stan%2FMath/detail/PR-3313/4/pipeline/ ?

I'm not sure what is going on with the nohup permissions there

EDIT: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants