예제 #1
0
파일: grid.hpp 프로젝트: hojonathanho/timb
void from_eigen(const Eigen::DenseBase<Derived> &in, DoubleField& out) {
  assert(out.grid_params().nx == in.rows() && out.grid_params().ny == in.cols());
  for (int i = 0; i < in.rows(); ++i) {
    for (int j = 0; j < in.cols(); ++j) {
      out(i,j) = in(i,j);
    }
  }
}
예제 #2
0
파일: find.cpp 프로젝트: bbrrck/libigl
IGL_INLINE void igl::find(
  const Eigen::DenseBase<DerivedX>& X,
  Eigen::PlainObjectBase<DerivedI> & I,
  Eigen::PlainObjectBase<DerivedJ> & J,
  Eigen::PlainObjectBase<DerivedV> & V)
{
  const int nnz = X.count();
  I.resize(nnz,1);
  J.resize(nnz,1);
  V.resize(nnz,1);
  {
    int k = 0;
    for(int j = 0;j<X.cols();j++)
    {
      for(int i = 0;i<X.rows();i++)
      {
        if(X(i,j))
        {
          I(k) = i;
          J(k) = j;
          V(k) = X(i,j);
          k++;
        }
      }
    }
  }
}
예제 #3
0
파일: mat_min.cpp 프로젝트: bbrrck/libigl
IGL_INLINE void igl::mat_min(
  const Eigen::DenseBase<DerivedX> & X,
  const int dim,
  Eigen::PlainObjectBase<DerivedY> & Y,
  Eigen::PlainObjectBase<DerivedI> & I)
{
  assert(dim==1||dim==2);

  // output size
  int n = (dim==1?X.cols():X.rows());
  // resize output
  Y.resize(n);
  I.resize(n);

  // loop over dimension opposite of dim
  for(int j = 0;j<n;j++)
  {
    typename DerivedX::Index PHONY,i;
    typename DerivedX::Scalar  m;
    if(dim==1)
    {
      m = X.col(j).minCoeff(&i,&PHONY);
    }else
    {
      m = X.row(j).minCoeff(&PHONY,&i);
    }
    Y(j) = m;
    I(j) = i;
  }
}
예제 #4
0
파일: naive_bayes.hpp 프로젝트: libgm/libgm
 Label posterior(const Eigen::DenseBase<Derived>& observations,
                 bool normalize = true) const {
   assert(observations.cols() == num_features());
   Label result = prior_;
   for (std::size_t i = 0; i < num_features(); ++i) {
     result *= feature(i).restrict_head(observations.col(i));
     if (normalize) {
       result.normalize();
     }
   }
   return result;
 }
예제 #5
0
파일: setdiff.cpp 프로젝트: etrigger/libigl
IGL_INLINE void igl::setdiff(
  const Eigen::DenseBase<DerivedA> & A,
  const Eigen::DenseBase<DerivedB> & B,
  Eigen::PlainObjectBase<DerivedC> & C,
  Eigen::PlainObjectBase<DerivedIA> & IA)
{
  using namespace Eigen;
  using namespace std;
  // boring base cases
  if(A.size() == 0)
  {
    C.resize(0,1);
    IA.resize(0,1);
  }
  if(B.size() == 0)
  {
    C.resize(A.size(),1);
    int k = 0;
    for(int j = 0;j<A.cols();j++)
    {
      for(int i = 0;i<A.rows();i++)
      {
        C(k++) = A(i,j);
      }
    }
    assert(k == C.size());
    IA = igl::LinSpaced<Eigen::Matrix<typename DerivedIA::Scalar,Eigen::Dynamic,1> >(
      C.size(),0,C.size()-1);
  }

  // Get rid of any duplicates
  typedef Matrix<typename DerivedA::Scalar,Dynamic,1> VectorA;
  typedef Matrix<typename DerivedB::Scalar,Dynamic,1> VectorB;
  VectorA uA;
  VectorB uB;
  typedef DerivedIA IAType;
  IAType uIA,uIuA,uIB,uIuB;
  unique(A,uA,uIA,uIuA);
  unique(B,uB,uIB,uIuB);

  // Sort both
  VectorA sA;
  VectorB sB;
  IAType sIA,sIB;
  sort(uA,1,true,sA,sIA);
  sort(uB,1,true,sB,sIB);

  vector<typename DerivedB::Scalar> vC;
  vector<typename DerivedIA::Scalar> vIA;
  int bi = 0;
  // loop over sA
  bool past = false;
  for(int a = 0;a<sA.size();a++)
  {
    while(!past && sA(a)>sB(bi))
    {
      bi++;
      past = bi>=sB.size();
    }
    if(past || sA(a)<sB(bi))
    {
      // then sA(a) did not appear in sB
      vC.push_back(sA(a));
      vIA.push_back(uIA(sIA(a)));
    }
  }
  list_to_matrix(vC,C);
  list_to_matrix(vIA,IA);
}