On 10/13/12 7:59 PM, Marcus Brubaker wrote:
> On Sat, Oct 13, 2012 at 7:18 PM, Ben Goodrich <
goodri...@gmail.com <mailto:
goodri...@gmail.com>> wrote:
>
> On Saturday, October 13, 2012 6:47:42 PM UTC-4, Marcus Brubaker wrote:
>
> Just for kicks this afternoon I implemented a check_pos_definite for matrices of vars which does the positive
> definiteness test on a double matrix instead to avoid the wasteful creation of vars. This should provide a
> moderate speedup to anyone who has cov_matrix or corr_matrix parameters. As it turns out, it won't impact the
> multi_normal case because the positive definiteness test is done differently there.
We should go back and check where the tests are getting done
with the transforms. It should help there if we're testing.
That would wind up testing redundantly in the case of a cov_matrix
that was unmodified and used in the normal.
Also, anything that's just constant double shouldn't need to
be continually checked.
These are the things that Ben's new design for positive def
matrices with caching should address. (They're orthogonal
to the issue of speeding up from pulling the value out of
var and calling the tests with double -- that should be a
pretty big win in terms of auto-dif vars generated, so that
the copy will be of negligible cost in comparison.)
No -- it won't work for just that reason.
We don't want to add an implicit cast from var to double, either.
You probably want two functions to make the templates easier
to go down.
I'd just pull the test code into a function validate_pos_def()
and use:
void validate_pos_def(const Matrix<var,Dynamic,Dynamic>& m)
// convert to double matrix
// call shared test code
void validate_pos_def(const Matrix<double,Dynamic,Dynamic>& m) {
// call shared test code
Trying to share more than that in a single function is going to
lead to trouble because both branches of any if statement must
compile.
> I thought you couldn't convert to double
> without calling .val() which would break the cast call.
Correct.
> The other thing (although less relevant) is that what you
> posted would also convert floats, ints, long doubles, etc to double.
It'd be best to avoid this, but I'm not too worried about
making our libs play nicely with float or long double types.
Many things that should probably be more general are already
somewhat or fully hard-coded for double.
- Bob