New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 663 - Permit NoChange in setZero, setOnes, setConstant, setRandom
Summary: Permit NoChange in setZero, setOnes, setConstant, setRandom
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: unspecified
Hardware: All All
: Normal enhancement
Assignee: Nobody
Keywords: JuniorJob
Depends on:
Blocks: 3.4
  Show dependency treegraph
Reported: 2013-09-25 18:50 UTC by Rhys Ulerich
Modified: 2016-03-11 15:43 UTC (History)
3 users (show)

Patch for Bug 663 (13.68 KB, patch)
2016-03-11 15:43 UTC, Philipp Wissmann
no flags Details | Diff

Description Rhys Ulerich 2013-09-25 18:50:21 UTC
If feasible, please consider permitting NoChange as an argument in either the rows or cols slots within the following methods:

x.setZero(rows, cols);
x.setOnes(rows, cols);
x.setConstant(rows, cols, value);
x.setRandom(rows, cols);

That is, the LHS and RHS of the following equalities would behave identically:

x.setZero(NoChange, cols) "==" x.setZero(x.rows(), cols)
x.setZero(rows, NoChange) "==" x.setZero(rows, x.cols())

x.setOnes(NoChange, cols) "==" x.setOnes(x.rows(), cols)
x.setOnes(rows, NoChange) "==" x.setOnes(rows, x.cols())

x.setConstant(NoChange, cols, value) "==" x.setConstant(x.rows(), cols, value)
x.setConstant(rows, NoChange, value) "==" x.setConstant(rows, x.cols(), value)

x.setRandom(NoChange, cols) "==" x.setRandom(x.rows(), cols)
x.setRandom(rows, NoChange) "==" x.setRandom(rows, x.cols())

These would be handy when "x" is complicated to express.  Feel free to close as irrelevant if I'm missing some portion of the API that handles this succinctly.
Comment 1 Gael Guennebaud 2013-10-28 17:27:46 UTC
This should not be difficult to add, and a welcome addition for consistency.  Patch welcome.

In the meantime you can do:

X.resize(NoChange, cols); X.setConstant(2);

which is not much more verbose.
Comment 2 Gael Guennebaud 2016-01-31 13:08:15 UTC
Not critical, but good junior-job. So let's keep it for newcomers.
Comment 3 Philipp Wissmann 2016-03-11 15:43:21 UTC
Created attachment 666 [details]
Patch for Bug 663

I've added support for NoChange in the functions mentioned above.

Please have a look at it.


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