Re: [eigen] cast ArrayXd* to ArrayXXd* (comparision 2D>1D)

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


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
>>
> 
> 
> 
> 



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