Re: [eigen] cast ArrayXd* to ArrayXXd* (comparision 2D>1D) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] cast ArrayXd* to ArrayXXd* (comparision 2D>1D)
- From: Holger Herrlich <holgerherrlich05@xxxxxxxx>
- Date: Wed, 03 Oct 2012 15:14:19 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1349270098; bh=ucw9rQAYkhIBqO6yEfW3x6RdeMIVj6GRTbQGaB1wUC0=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=BTNtI1ZFMDdBaRXfe/1BjEuTmDGtOlM7gVP9PeWF8VsjRxuqlGt2Y8cmQ4GUZTBd2 n3hqiaHNmRMMF4Xe5WHT9USImYgUtJjT4VL27me5qXBPV3XTfS79JFRqj9pyobz2A/ p3xTd1nBNqMJQUE/z41g9YWQI/Qk9GMqqgxaiTno=
replicate():
Found it next to colwise() at the quick reference. It escaped my notice.
But works: Thanks.
Lg Holger
---8<---8<---
#include <iostream>
#include <Eigen/Core>
using namespace std;
int main() {
Eigen::ArrayXd arr1D;
Eigen::ArrayXXd arr2D;
arr1D = Eigen::ArrayXd:: Random(3);
arr2D = Eigen::ArrayXXd::Random(3,5);
arr2D(0,0) = 0.0;
cout << ":1D:" << endl << arr1D << endl << endl;
cout << ":2D:" << endl << arr2D << endl << endl;
if(false) {
// work around
Eigen::ArrayXXd tmp(arr2D.rows(),arr2D.cols());
tmp.colwise() = arr1D;
arr2D = ( arr2D<0 || tmp<=0 ).select( 0, arr2D );
arr1D = ( arr1D<0 ).select( 1E-20, arr1D );
cout << ":->1D:" << endl << arr1D << endl << endl;
cout << ":->2D:" << endl << arr2D << endl << endl;
}
else {
// straight
cout << ":replicate: "
<< (arr1D<=0).replicate(arr2D.cols(),arr2D.rows()).rows()
<< ","
<< (arr1D<=0).replicate(arr2D.cols(),arr2D.rows()).cols()
<< endl << endl;
arr2D = ( arr2D<0 || (arr1D<=0).replicate(1,arr2D.cols())
).select( 0, arr2D );
arr1D = ( arr1D<0
).select( 1E-20, arr1D );
cout << ":->1D:" << endl << arr1D << endl << endl;
cout << ":->2D:" << endl << arr2D << endl << endl;
}
return 0;
}
---8<---8<---