Subject: Re: [boost] [ublas] bugfix for matrix operation /
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-04-17 03:00:31
On 4/16/2013 10:16 PM, Steven Watanabe wrote:
> On 04/16/2013 07:20 PM, Mario Mulansky wrote:
>> I wanted to add an elementwise divide operations for ublas matrices using
>> operator /
> I don't think that's such a great idea.
> Using regular operators for elementwise
> operations is likely to be surprising.
> i.e. if you can do (A / B) you should
> be able to do (A * B) as well, and it
> you be the inverse of A / B. But
> multiplication is defined for matrices
> and is *not* an elementwise operation.
> There is no way to define this that
> won't surprise someone. There's a
> good reason why uBlas doesn't provide
> these operators already and why MATLAB
> has a separate set of operators for
> elementwise operations.
>> Unfortunately, there is operator/ defined for matrix and integral types which
>> hides any other operator definition (matrix_expression.hpp l. 3388) and thus
>> makes it impossible to add this functionality. I would like to add an
>> enable_if statement there that checks if the second argument is convertible to
>> matrix::value_type, as is done for other operators. Who would be responsible
>> for this small change? I can provide the according patch, it's almost trivial.
FWIW eigen3 implements element wise operators by converting a matrix
representation to an array representation and doing operators there.
Vector4f a, b, c;
c = a.array() * b.array();
c = a.array().abs().pow(3) * b.array().abs().sin();
where every operation is an element wise.
Naturally this uses TMP so .array() doesn't make a copy or anything silly.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk