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: Fri, 28 Sep 2012 19:58:06 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1348855156; bh=CzKehludkJI5JcAH7cYBeSX7W0HBGLrecRPR57Nwbx0=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=MfsyK4Q8BKU8DNhMx6ic/zKxOuVbxSHWHQtceJkWxK0pTu99aBkyjhfSlh3+68MlL yPlS66neZv14wiNyRO0+4j50YSDFzmeEIUB8GwG/Z8uzxTKKmEX1bH82CyLyD7IaBk QDOJVq+r6Z7Zi7zf97zMoGmkeHT/T9FBNxk1XWnU=
However, using binaryExpr() or select(), don't mind it will never do
without a temporary 2D array. operator|| doesn't match on arr.colwise()
parameters.
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);
cout << ":1D:" << endl << arr1D << endl << endl;
cout << ":2D:" << endl << arr2D << endl << endl;
Eigen::ArrayXXd tmp(arr2D.rows(),arr2D.cols());
tmp.colwise() = arr1D;
cout << ":tmp:" << endl << tmp << endl << endl;
arr2D = ( arr2D<0 || tmp<=0 ).select( 0, arr2D );
arr1D = ( arr1D<0 ).select( 1E-20, arr1D );
// won't do
// arr2D.colwise() = ( arr1D<=0 ).select( 0, arr2D.colwise() );
// arr2D = ( arr2D<0 ).select( 0, arr2D );
// arr1D = ( arr1D<0 ).select( 1E-20, arr1D );
cout << ":->1D:" << endl << arr1D << endl << endl;
cout << ":->2D:" << endl << arr2D << endl << endl;
cout << ":2D/1D:" << endl << (arr2D.colwise()/arr1D) << endl;
arr2D.colwise()+arr1D;
return 0;
}
----8<----8<----
On 09/28/2012 05:09 PM, Holger Herrlich wrote:
>
>
> Is here a way to make this comparison work?
> Lg Holger
>
>
> ----8<---8<----
>
> #include <iostream>
> #include <Eigen/Core>
> using namespace std;
>
> int main() {
>
> Eigen::ArrayXXd arr2D;
> Eigen::ArrayXd arr1D;
> Eigen::ArrayXXd True;
> Eigen::ArrayXXd False;
>
> arr2D = Eigen::ArrayXXd::Random(3,5);
> arr1D = Eigen::ArrayXd:: Random(3);
> cout << ":1a:" << endl << arr2D << endl
> << ":1b:" << endl << arr1D << endl;
>
> True = Eigen::ArrayXXd::Ones(3,5);
> False = Eigen::ArrayXXd::Zero(3,5);
>
> cout << ":2a:" << endl << (arr2D.colwise()+arr1D) << endl; // works
> cout << ":2b:" << endl << (arr2D.colwise()>arr1D) << endl; // fails
>
> // arr2D = ( arr2D>arr1D ).select( True, False ); //fails at runtime
> // cout << ":3:" << endl << arr2D << endl;
>
> return 0;
> }
>
> ----8<---8<----
>
> On 09/26/2012 02:50 PM, Holger Herrlich wrote:
>>
>> Hi, did I really have to:
>>
>> Eigen::ArrayXXd* smInt;
>> Eigen::ArrayXd* tmp = fn_create();
>> smInt = new Eigen::ArrayXXd( *(tmp) );
>> delete(tmp.arrayXd);
>>
>> to cast from Array<double,len> to Array<double,len,1> when using pointers?
>>
>>
>> Regards Holger
>>
>
>
>
>