Re: [eigen] Value-initializing a Matrix
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] Value-initializing a Matrix
• From: gabriel nützi <gnuetzi@xxxxxxxxx>
• Date: Sun, 19 Apr 2015 22:21:12 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to; bh=p8mMh0MgwxDVpA0hpYv2TxKoDNr4hfCMgBS22H/AnUs=; b=F972lvUDoJWM/QPnG6mIA8eXpTjzG7dNBhhc87YaxETd7k38q4d/cYq0p8iYShPPRI XOqLiE4v67tn5INmFQO88B1xWdEOVDtEN5Z/5rKNjJgvvr711D4H2MHhp3W3g4eDovcv L1wXzUxxIKz/38Lz4TAc65t4N3y+WlAtEzxP7ks/LhsQ6oskQ6RczIKQot0owWeEbH7j 8R58ILUsIPGbfEor2iTtH51hIFbxjrdWbGfLJs8ou4f/273oI7i8T8Oppaze7siTaHS8 dQTGYMEsUsWwDkOZCc/bfT9mtxNfuxFBI8yA9c1gfdPm7BwxGDENGXjAWqrnYFZyrDBj oVFQ==

 I dont get your code?:Do you mean this:struct foo {foo() : v{} private:Eigen::Vector2d v;};orstruct foo {foo() : v() private:Eigen::Vector2d v;};I think Eigen should support value initialization ( although its tricky business and I am not quite sure about all the different initialization, “default”, “value”, “zero”)I think Eigen3 should (at least in the next release ) include the c++11 conformance with value initialization such that v{} get initialized properly (that means to zero)and any default-initialization should result in undetermined values .Anyway how can we distinguish in C++ between MatrixXd M;     < default-initialization -> uninitializedMatrixXd M{};  < value-initialized -> zero initializedWhat would need to be done to distinguish these two cases?Am 19.04.2015 um 00:44 schrieb Matan Nassau :To be clear, my question stands still whether the code is struct foo { foo() : v{} {} // braces private: Eigen::Vector2d v(); };or struct foo { foo() : v() {} // parentheses private: Eigen::Vector2d v(); };The question is, what's the value of v after construction? In the current state of affairs it is indeterminate. It can be anything. But one might expect it to be value-initialized just as std::vector or int would be (such that v.size()==0 or v==0 for the std::vector and int respectively) if that's what the type of v were. Yes, I can get this behaviour with the EIGEN_INITIALIZE_MATRICES_BY_ZERO define, but then I can't get the do-nothing performance anymore if that's what I want, so that's not a solution.On Sat, Apr 18, 2015 at 18:26 Matan Nassau wrote:But, there is no initializer list here. There is an =default, yes, but maybe we can do that conditionally? #if __cplusplus >= 201103L Matrix()=default; #else #ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO ...If Eigen supports C++11 initialization semantics it opens the door for more performant code, and for more expressive flexibility in user code. I mean, I can clearly express what I want with Matrix3d m;and Matrix3d m{};controlling the performance or behaviour in case-by-case fashion, in my code.Eigen can do this, while still providing the current behaviour for C++03.On Sat, Apr 18, 2015 at 15:47 Gael Guennebaud wrote:Hi,Eigen aims to be compatible with C++03, and initializer-lists are not supported yet. So currently Vector2d v{}; is equivalent to Vector2d v; .See this bug entry for further discussions on initializer-lists: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=954. They will likely be supported in Eigen 3.3, and we already agreed on making the empty initializer-list initializes to 0.In the meantime, you can compile with -DEIGEN_INITIALIZE_MATRICES_BY_ZERO, as documented there: http://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html#title0.cheers,gaelOn Sat, Apr 18, 2015 at 7:22 PM, Matan Nassau wrote:I have a class, struct foo {   foo() : v{} {}   private:   Eigen::Vector2d v; };I just got bitten when I realized the value of v is undetermined.I understand the default constructor of a fixed-size matrix does nothing. In particular, Eigen::Vector2d v{};will create a vector with an undetermined value.Why is that? Is this for speed? If I value-initialize an object I expect it to initialize. To motivate, all standard templates and classes behave this way: std::string s{};  // assert(s==""); std::vector v{};  // assert(v.size() == 0);Granted, std::string s;  // assert(s=="");but if we want speed here then we can do template<... struct Matrix {   Matrix() = default;   // ...This way, we'd get the best of both worlds: Eigen::Vector2d v;  // valid, undetermined value Eigen::Vector2d v{};  // assert(v==Eigen::Vector2d::Zero());Matan

 Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/