Skip to content

Transforming User Code To Stan Math Specialized Functions? #879

Answered by nhuurre
SteveBronder asked this question in Q&A
Discussion options

You must be logged in to vote

Your first quad_form example almost works already. Compile the following model with stanc --O and you'll see a quad_form call in the C++.

data { int N; }
parameters {
vector[N] B;
matrix[N, N] A;
}
transformed parameters {
  real quaded = transpose(B) * A * B;
}

This is implemented in the optimization suite

| ( "Times__"
, [ { pattern=
FunApp
( StanLib "Times__"
, [ {pattern= FunApp (StanLib "transpose", [b]); _}
; a ] ); _ }
; c ] )
when Expr.Typed.equal b c ->
FunApp (StanLib "quad_form", [a; b])

It doesn't work with your original example becaus…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@rok-cesnovar
Comment options

@SteveBronder
Comment options

SteveBronder Apr 12, 2021
Maintainer Author

@SteveBronder
Comment options

SteveBronder Apr 12, 2021
Maintainer Author

@SteveBronder
Comment options

SteveBronder Apr 12, 2021
Maintainer Author

Answer selected by rok-cesnovar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants