This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 157 - add *, /, *=, /= to VectorwiseOp
add *, /, *=, /= to VectorwiseOp
 Status: RESOLVED FIXED None Eigen Unclassified Core - general (show other bugs) unspecified All All --- enhancement Nobody (view as bug list)

 Reported: 2011-01-19 19:17 UTC by Evan Herbst 2019-12-04 10:11 UTC (History) 5 users (show) gael.guennebaud jacob.benoit.1 johan.pauwels kkimlabs+eigen marton78

Attachments
Fixed VectorwiseOp.h (23.82 KB, text/x-chdr)
2011-11-11 16:56 UTC, Kibeom Kim
no flags Details
this patch implements some of the operators. (2.71 KB, patch)
2011-11-18 00:13 UTC, Kibeom Kim
no flags Details | Diff

 Evan Herbst 2011-01-19 19:17:43 UTC ```They make sense at least for Array. What I want to do is divide each row of rho by its sum: MatrixXf rho(n, m), r(n, m); r = rho.array().colwise() / rho.rowwise().sum().array(); and I don't see how to do it without a loop. Thanks.``` Marton Danoczy 2011-01-25 09:55:12 UTC ```You can do that with .replicate(): r = rho.array().colwise() / rho.rowwise().sum().array().replicate(n,1); I think this should work as well: r = rho.array().colwise() / rho.rowwise().sum().array().colwise().replicate(n); But yes, me too I miss that feature a lot as it enables code to be a lot more concise.``` Kibeom Kim 2011-11-11 00:02:42 UTC `*** Bug 374 has been marked as a duplicate of this bug. ***` Kibeom Kim 2011-11-11 00:03:23 UTC ```Summary: From the tutorial, http://eigen.tuxfamily.org/dox/TutorialReductionsVisitorsBroadcasting.html mat.colwise() += v; //works mat.colwise() -= v; //works mat.colwise() *= v; //not implemented mat.colwise() /= v; //not implemented Moreover, mat2 = mat.colwise() + v; //works mat2 = mat.colwise() - v; //works mat2 = mat.colwise() * v; //not implemented mat2 = mat.colwise() / v; //not implemented mat2 = v + mat.colwise(); //not implemented mat2 = v - mat.colwise(); //not implemented mat2 = v * mat.colwise(); //not implemented mat2 = v / mat.colwise(); //not implemented``` Kibeom Kim 2011-11-11 12:34:15 UTC ```In addition, Eigen::ArrayXf v(2); v = 3/v; //not implemented``` Kibeom Kim 2011-11-11 16:56:49 UTC ```Created attachment 229 [details] Fixed VectorwiseOp.h Here is the fixed VectorwiseOp.h. but need to implement operations for rhs VectorwiseOp. But I think that should be somewhere else, not this file.``` Kibeom Kim 2011-11-11 19:31:05 UTC `*** Bug 151 has been marked as a duplicate of this bug. ***` Kibeom Kim 2011-11-18 00:13:05 UTC ```Created attachment 230 [details] this patch implements some of the operators. this patch implements some of the operators. Eigen::MatrixXf mat(2,4); Eigen::ArrayXf v(2); mat.colwise() += v; //works mat.colwise() -= v; //works mat.colwise() *= v; //not implemented -> now implemented mat.colwise() /= v; //not implemented -> now implemented mat2 = mat.colwise() + v; //works mat2 = mat.colwise() - v; //works mat2 = mat.colwise() * v; //not implemented -> now implemented mat2 = mat.colwise() / v; //not implemented -> now implemented mat2 = v + mat.colwise(); //not implemented mat2 = v - mat.colwise(); //not implemented mat2 = v * mat.colwise(); //not implemented mat2 = v / mat.colwise(); //not implemented v = 3 / v; //not implemented -> now implemented``` Gael Guennebaud 2011-11-18 00:48:26 UTC ```Comment on attachment 230 [details] this patch implements some of the operators. Review of attachment 230 [details]: ----------------------------------------------------------------- First, such / operators should be available only in array mode. Otherwise they make no sense to me. The correct way of doing this with linear algebra objects is, e.g.: C = A * v.diagonal().inverse(); Second, the documentation should mention that these functions are actually equivalent to matrix * diagonal matrix products: C = A * v.diagonal(); <=> rowwise vector multiply C = A * v.diagonal().inverse(); <=> rowwise vector divison``` Kibeom Kim 2011-11-18 01:10:01 UTC ```Comment on attachment 230 [details] this patch implements some of the operators. Review of attachment 230 [details]: ----------------------------------------------------------------- 1. I also think that / operator should be only available for array mode. (but can you teach me how it can be done in a correct way? I'm still learning the library structure and it's not so easy) 2. C = A / v //newly implemented operator C = A * v.diagonal().inverse(); //equivalent? seems your example will work for a scalar A and "ArrayXf v;" but how about for "ArrayXXf v;" ?``` Benoit Jacob 2011-11-18 05:13:35 UTC ```The relevant part of the class hierarchy is: - DenseBase is the common base class for all dense matrix and array expressions - MatrixBase inherits DenseBase, is the common base class for Matrix expressions - ArrayBase inherits DenseBase, is the common base class for Array expressions``` Gael Guennebaud 2011-11-18 08:09:32 UTC ```(In reply to comment #9) For your point 2, the equivalents I shown are for the matrix world only where v is a vector, and it is not equivalent to C = A/v but C = A.rowwise() / v where v also has to be a vector.``` Benoit Jacob 2011-11-18 15:45:22 UTC ```This whole area is really a mess. I propose that we: 1) take Kibeom's patch adding multiplicative vectorwise ops 2) add lots of static assertions making it very explicit when all these ops are supposed to work: 2a) additive ops already require that the lhs and rhs are of the same kind (matrix vs vector) 2b) multiplicative ops (as in Kibeom's patch) also pretty much have to be restricted to arrays (enabling them for matrices would require a complex dance with .array()/.matrix() which would be fine for *= and /= but would force * and / to return very deeply nested expressions. 3) add unit tests. there just aren't enough unit tests here. currently, additive ops are only tested in array.cpp on arrays as far as I can see.``` Benoit Jacob 2011-11-18 15:48:25 UTC ```oh and: 4) this stuff: for(Index j=0; j

 Note You need to log in before you can comment on or make changes to this bug.