Registered Member
|
I'm using Eigen vector/matrix types with both doubles and Interval objects as scalar types, and I'd like to implement a couple of special interval-related methods. For instance, I'd like to implement a hull() method such that I can write
which would result in c having each coefficient be the hull (Interval containing both) of the corresponding coefficients in a and b. The trick, of course, is that while a and b are double-valued, the result is Interval-valued, so as I understand it there's no way to use the CwiseBinaryOp class. I was thinking of implementing a class based on CwiseNullaryOp that would take a couple const reference parameters (a and b) at construction and specify an Interval return type...it seems to me this should work, but I thought I should check to see if there was something I was missing. For instance, does hiding the two arguments this way mean that there could be issues with aliasing? |
Registered Member
|
So what you're trying to do here is not a nullary operation, it's a binary operation. See CwiseBinaryOp. There is a function already to apply a custom functor as binary op, see binaryExpr().
There's no aliasing problem in coeff-wise operations. Aliasing problems arise in non-coeff-wise operations, when reading back an already overwritten value.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
You're right, that was a bad example...I should have mentioned that I also would ideally like to be able to mix double/Interval vectors, so it's possible to write things like
since the result of the first hull() would be an Interval-valued expression, and as I understand it it's not possible to have a binary expression with different scalar types. But perhaps the simplicity of just using binaryExpr() makes up for the slight loss in syntactic sugar of not being able to mix scalar types... |
Registered Member
|
OK, it's true that CwiseBinaryOp requires same scalar type (except for a few ops where it allows mixing real and complex).
So, yes your idea of doing a nullary/unary op and "artificially" passing the other(s) operand(s) would work. But you can also simply write your new expression class from scratch (hint: a good simple example of an expression class is Minor in Eigen 2) and construct objects of it with either a global function or a new matrixbase method that you inject with EIGEN_MATRIXBASE_PLUGIN.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thanks! And yes, Minor does seem like a nice example...
|
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient