Exactly. The problem is with static allocation.
I think we could fix this by replacing the static constant
one_ with a call to a static function one(). That's
how a traits-based approach would do it, and that will work
for us as long as nobody calls the function out of turn.
I assume that's what they were talking about in the ublas
package in their comment saying they should use traits
in the vector header file.
It doesn't make sense conceptually in our reverse-mode
auto-diff to have a free-floating value of type
stan::agrad::var. The use pattern is:
-- create var instances for inputs to functions
-- call the function on those instances
-- calculate a gradient in a backward pass
-- free memory
And to boot, it's not thread safe (unless you make
the variable stack thread local, and then there are
performance penalties).
The alternative is to somehow manage multiple memory arenas,
with references from var to the relevant arena. The problem
with that is that the objects are bigger and there's
a dynamic indirection that's not cheap to follow in
the guts of our loop.
Another alternative would be to have long-lived var
instances. They wouldn't need any auto-diff because
they wouldn't depend on any var values. The problem is
that I can't figure out how to do that without
making the value and derivative calls virtual, which
I would also rather not do for speed reasons.
Finally, there's the same mixed-type issue as with Eigen.
They wrap the constants for the algorithm up in
member variable instances of the scalar type, which means
more auto-diff variables that should really be double for us.
What this means is that we don't want the one_ value
to even be a variable --- all we need is a double if we
have double by var matrix multiplication. And seriously,
we don't even need that --- it's probably expression templated
out somewhere because it's a constant!
So it seemed like the easiest thing to do to just
rewrite their solver calling Eigen instead of ublas
and using double instances instead of var types for
constants.
- Bob
> /boost/numeric/ublas/matrix.__hp__p:
> ----------------------------
> ...
> static const value_type one_;
>
>
>
>
> The result of uBLAS's use of static constants is that we get a segmentation fault. The attached
> test, as written, does not seg fault. By accessing any element in the identity matrix (lines 9-12),
> it will seg fault.
>
> No error messages, no nothing. It all happens before this code executes. It took us a while to
> figure out how and where the seg fault was coming from, but we found it.
>
> In short, Stan's autodiff library will not work with Boost's uBLAS matrix library.
>
>
>
> Daniel
>
> P.S. This means Boost numeric's ODE solvers will not work with Stan. There are other issues to
> getting those ODE solvers to work.
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing
> list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> stan-dev+u...@__
googlegroups.com.
> For more options, visit
https://groups.google.com/__groups/opt_out
> <
https://groups.google.com/groups/opt_out>.
>
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
>
stan-dev+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out <
https://groups.google.com/groups/opt_out>.