This might be a XY problem. I first post my immediate question and some background below.

Question: What's the fastest way to pass arguments matching PatternSequence[a_List,{b_?NumericQ,c_List}] to a (compiled) function that takes PatternSequence[a_List,b_?NumericQ,c_List]?

Of course I can just do somthing along the lines of


but if bar is very fast then this introduces a considerable overhead. Is there a better way?

Background: I'm using FoldList to simulate a linear stochastic differential equation with time dependent coefficients. For speed I want to compile the function that generates a time step. One example for this is

NT = 1000; dt = 0.01;
{tvec, nvec} = {Table[t, {t, dt, NT, dt}], Sqrt[2 dt]*Map[List,RandomVariate[NormalDistribution[], NT/dt]]};
uf = With[{AM = IdentityMatrix[2] + {{0, 1}, {-1, -t/10}}*dt, LM = {{0}, {Sqrt[t/10]}}}, Compile[{{x, _Real, 1}, {t, _Real}, {n, _Real, 1}}, AM.x + LM.n]];
xt = FoldList[uf[#1, Sequence @@ #2] &, {100, 0}, Transpose[{tvec, nvec}]];
  • 1
    $\begingroup$ Have you measured the overhead? How significant is it? $\endgroup$
    – rcollyer
    Sep 16, 2016 at 19:20
  • $\begingroup$ @rcollyer I have to double check (can't do right now) but I think around a factor of 4... $\endgroup$
    – sebhofer
    Sep 16, 2016 at 19:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.