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

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


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




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