Explorar o código

better templating

Former-commit-id: 970ec6ffdd43b11d47068b169c7c236dac036153
Alec Jacobson %!s(int64=8) %!d(string=hai) anos
pai
achega
2c0956abc6
Modificáronse 4 ficheiros con 20 adicións e 23 borrados
  1. 6 8
      include/igl/mat_max.cpp
  2. 4 4
      include/igl/mat_max.h
  3. 6 7
      include/igl/mat_min.cpp
  4. 4 4
      include/igl/mat_min.h

+ 6 - 8
include/igl/mat_max.cpp

@@ -7,12 +7,12 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "mat_max.h"
 
-template <typename T>
+template <typename DerivedX, typename DerivedY, typename DerivedI>
 IGL_INLINE void igl::mat_max(
-  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
+  const Eigen::DenseBase<DerivedX> & X,
   const int dim,
-  Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
-  Eigen::Matrix<int,Eigen::Dynamic,1> & I)
+  Eigen::PlainObjectBase<DerivedY> & Y,
+  Eigen::PlainObjectBase<DerivedI> & I)
 {
   assert(dim==1||dim==2);
 
@@ -25,9 +25,8 @@ IGL_INLINE void igl::mat_max(
   // loop over dimension opposite of dim
   for(int j = 0;j<n;j++)
   {
-    typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index PHONY;
-    typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index i;
-    T m;
+    typename DerivedX::Index PHONY,i;
+    typename DerivedX::Scalar  m;
     if(dim==1)
     {
       m = X.col(j).maxCoeff(&i,&PHONY);
@@ -42,5 +41,4 @@ IGL_INLINE void igl::mat_max(
 
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
-template void igl::mat_max<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, int, Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&);
 #endif

+ 4 - 4
include/igl/mat_max.h

@@ -29,12 +29,12 @@ namespace igl
   //   Y  m-long vector (if dim == 2)
   //   I  vector the same size as Y containing the indices along dim of maximum
   //     entries
-  template <typename T>
+  template <typename DerivedX, typename DerivedY, typename DerivedI>
   IGL_INLINE void mat_max(
-    const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
+    const Eigen::DenseBase<DerivedX> & X,
     const int dim,
-    Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
-    Eigen::Matrix<int,Eigen::Dynamic,1> & I);
+    Eigen::PlainObjectBase<DerivedY> & Y,
+    Eigen::PlainObjectBase<DerivedI> & I);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 6 - 7
include/igl/mat_min.cpp

@@ -7,12 +7,12 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "mat_min.h"
 
-template <typename T>
+template <typename DerivedX, typename DerivedY, typename DerivedI>
 IGL_INLINE void igl::mat_min(
-  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
+  const Eigen::DenseBase<DerivedX> & X,
   const int dim,
-  Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
-  Eigen::Matrix<int,Eigen::Dynamic,1> & I)
+  Eigen::PlainObjectBase<DerivedY> & Y,
+  Eigen::PlainObjectBase<DerivedI> & I)
 {
   assert(dim==1||dim==2);
 
@@ -25,9 +25,8 @@ IGL_INLINE void igl::mat_min(
   // loop over dimension opposite of dim
   for(int j = 0;j<n;j++)
   {
-    typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index PHONY;
-    typename Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Index i;
-    T m;
+    typename DerivedX::Index PHONY,i;
+    typename DerivedX::Scalar  m;
     if(dim==1)
     {
       m = X.col(j).minCoeff(&i,&PHONY);

+ 4 - 4
include/igl/mat_min.h

@@ -31,12 +31,12 @@ namespace igl
   //     entries
   //
   // See also: mat_max
-  template <typename T>
+  template <typename DerivedX, typename DerivedY, typename DerivedI>
   IGL_INLINE void mat_min(
-    const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & X,
+    const Eigen::DenseBase<DerivedX> & X,
     const int dim,
-    Eigen::Matrix<T,Eigen::Dynamic,1> & Y,
-    Eigen::Matrix<int,Eigen::Dynamic,1> & I);
+    Eigen::PlainObjectBase<DerivedY> & Y,
+    Eigen::PlainObjectBase<DerivedI> & I);
   // Use Y = X.colwise().minCoeff() instead
   //// In-line wrapper
   //template <typename T>