Re: [eigen] row and col setZero in sparse matrices
• To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
• Subject: Re: [eigen] row and col setZero in sparse matrices
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Tue, 22 Apr 2014 16:55:18 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=jhfBeUarmc+2WmODmQ8+R+D3VmekotYCoH94wyUOI1A=; b=TIPqmiWLgTQpEjh9nlWWbGZfnxiWo1//CsxjuBUrw7EeP73P8Igrc0YG2fedvx2kUo /uA/JWa8CcEOp3Wx8hDwNNL9huWFjq+BfEBqodFMtwyI6Z0ExPm0+o4ujMgSKEeHJkS+ LaHa0lix9PNxoVocRkW3euNsVOZB2oadr51Bfup7sVImnXzoartzNBseREpSx5Xt2DxF afkrupWwjY7msO+zMx925Qhh8Anlp3+lcX8X0nnx9/v6i6hoBeLFZi/OBAh5XArIx9LS vfOeV4usCanMDcxNTtKBF4oiaXvm1di+Wugf7uhxytDVGyh76q9syYW6YY9/ogTUpq73 yW7A==

Hi,

sorry for late reply.. I agree this would be convenient, but this would also be pretty slow, especially if you fix several values this ways. If A is column major:

b-=value*A.col(dof);

-> fine

A.col(dof).setZero();

-> fine if we keep the memory allocated for col(dof), otherwise all remaining columns have to be copied to keep a compact storage.

A.row(dof).setZero();

This is basically a O(nnz) operation, so pretty costly if you do it multiple times.

A.coeffRef(dof,dof)=1.0;

-> fine if we kept a non-compact storage

Since in most cases you want to fix several unkowns, I usually build a permutation matrix P, permute A in a symmetric fashion (A1 = A.twistedBy(P)), and then pick sub matrices to solve: