I'll check in a fix for elt_multiply ASAP
and if it works get back to the list. More below.
On 11/20/12 11:01 PM, Ben Goodrich wrote:
> On Tuesday, November 20, 2012 9:07:02 PM UTC-5, Daniel Lee wrote:
> I think the compiler under Windows is actually doing the right thing in this case and the other compilers (clang++
> on Mac, macports g++ 4.6.3 on Mac) are not as strict.
Absolutely. Our code below is wrong.
> There are templated functions in the stan::agrad namespace
> that conflicts with the function definitions in stan::math namespace.
>
> For elt_multiply(), the math/matrix.hpp version's signature looks like:
> vector_d elt_multiply(const vector_d& v1, const vector_d& v2);
>
> and the agrad/matrix.hpp version's signature looks like:
> template <typename T1, typename T2>
> inline Eigen::Matrix<stan::agrad::var,Eigen::Dynamic,1>
> elt_multiply(const Eigen::Matrix<T1,Eigen::Dynamic,1>& v1,
> const Eigen::Matrix<T2,Eigen::Dynamic,1>& v2)
> When T1 and T2 are double, the function is defined twice for double vector inputs. I believe this is the cause of
> the problem in Windows, and it may be the cause of the mysterious bus errors in Mac (but the bus error could be
> something else).
> I was under the impression that the above was valid C++ and that the compiler should select the more specific definition
> of the function, but maybe that is not right.
Functions can only have full specializations. Otherwise,
it's just overloading. Here, there's an extra layer of
namespace difference.
I'm not sure what's supposed to happen if two namespaces
both contain matching functions.
Also, the signature of the second one doesn't really specialize
the first one because of the var return type.
> With all that said, I think the solution to these problems is to:
> 1) rewrite most of the matrix functionality using templates
> 2) add tests that instantiates all the different permutations of the inputs and outputs to the functions.
>
> Any takers? Can anyone on another OS verify that the agrad/matrix test fails?
This will definitely solve the problem.
The return type on the templated versions should use
promotion, and then it can all be done in math/matrix
and we're good to go.
In fact, I think we can just use one templated version
for all of these in math/matrix and be done with it.
> make test-unit with CC=g++-4.6 works for me. I can't run the tests under cross-compilation right now, but that appears
> to be an unrelated problem.
>
> Can't we just eliminate the versions that are defined for doubles?
Yes, if you use promotion for the return types.
> I think Ben and Marcus are the closest to this code, but if there aren't any volunteers, this is critical enough for
> me to pick it up to starting tomorrow.
>
>
> I can do it, but not having Windows would make it a bit harder to trigger failures such as this.
I'm taking a whack at it right now. Shouldn't take
long at all.
- Bob