[ublas] bugfix for matrix operation /
Hi, I wanted to add an elementwise divide operations for ublas matrices using operator / 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. Mario
AMDG On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
In Christ, Steven Watanabe
On 4/16/2013 10:16 PM, Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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(); or 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.
On Tuesday, April 16, 2013 08:16:57 PM Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
uh wait, i dont want to add this operator to ublas. I need it within odeint and it would be part of some ublas_extension.hpp in odeint, it would be merely an implementation detail no user would encounter. The problem is just that currently any definition of operater/ for two matrices is hidden by the ublas implementation of matrix-skalar division. So I would like to add an enabler to this, just as it is already there for the multiplication operator *, for example.
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. In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On Wed, Apr 17, 2013 at 7:08 AM, Mario Mulansky
On Tuesday, April 16, 2013 08:16:57 PM Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
uh wait, i dont want to add this operator to ublas. I need it within odeint and it would be part of some ublas_extension.hpp in odeint, it would be merely an implementation detail no user would encounter.
[...] If no user would encounter it, why don't you just define and use a free function elementwise_divide? Why does it have to be named operator/? - Jeff
On Wednesday, April 17, 2013 09:06:35 AM Jeffrey Lee Hellrung, Jr. wrote:
On Wed, Apr 17, 2013 at 7:08 AM, Mario Mulansky
wrote: On Tuesday, April 16, 2013 08:16:57 PM Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
uh wait, i dont want to add this operator to ublas. I need it within odeint and it would be part of some ublas_extension.hpp in odeint, it would be merely an implementation detail no user would encounter.
[...]
If no user would encounter it, why don't you just define and use a free function elementwise_divide? Why does it have to be named operator/?
oh because then i can reuse my code that is based on operator / being defined, it's just the easier way for me to go. but despite that i consider it a bug in ublas. the templated operator matrix/skalar gets instantiated even if i write matrix/matrix. this then results in a nasty compiler error instead of telling me operator/ for matrix matrix is not defined, as it would if the enable_if was there. best, mario
- Jeff
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On Tuesday, April 16, 2013 08:16:57 PM Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
So here's the patch I would like to be applied to ublas. As I said, it's almost trivial and would allow to add matrix-matrix operator/ for those who want it. Is it possible to have that added to ublas? Best, Mario
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. In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On Sat, Apr 20, 2013 at 10:02 AM, Mario Mulansky
On Tuesday, April 16, 2013 08:16:57 PM Steven Watanabe wrote:
AMDG
On 04/16/2013 07:20 PM, Mario Mulansky wrote:
Hi,
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.
So here's the patch I would like to be applied to ublas. As I said, it's almost trivial and would allow to add matrix-matrix operator/ for those who want it. Is it possible to have that added to ublas?
Better off creating a ticket and attaching the patch. - Jeff
participants (4)
-
Jeffrey Lee Hellrung, Jr.
-
Mario Mulansky
-
Michael Marcin
-
Steven Watanabe