浏览代码

Merge branch 'master' of https://github.com/libigl/libigl

Former-commit-id: e5957e54a4660b2b95c7064ae1edd5eae6081d74
Daniele Panozzo 11 年之前
父节点
当前提交
572868e8a8
共有 2 个文件被更改,包括 83 次插入77 次删除
  1. 56 56
      include/igl/kronecker_product.cpp
  2. 27 21
      include/igl/kronecker_product.h

+ 56 - 56
include/igl/kronecker_product.cpp

@@ -7,59 +7,59 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "kronecker_product.h"
 
-// Bug in unsupported/Eigen/SparseExtra needs iostream first
-#include <iostream>
-#include <unsupported/Eigen/SparseExtra>
-
-template <typename Scalar>
-IGL_INLINE Eigen::SparseMatrix<Scalar> igl::kronecker_product(
-  const Eigen::SparseMatrix<Scalar> & A,
-  const Eigen::SparseMatrix<Scalar> & B)
-{
-  using namespace Eigen;
-  using namespace std;
-
-  // Convert B in triplets format
-  MatrixXd B_triplets(B.nonZeros(),3);
-  int count = 0;
-  for (int k=0; k<B.outerSize(); ++k)
-    for (SparseMatrix<double>::InnerIterator it(B,k); it; ++it)
-      B_triplets.row(count++) << it.row(), it.col(), it.value();
-
-  MatrixXd C_triplets(B_triplets.rows()*A.nonZeros(),3);
-  count = 0;
-  for (int k=0; k<A.outerSize(); ++k)
-    for (SparseMatrix<double>::InnerIterator it(A,k); it; ++it)
-    {
-      int i = it.row();
-      int j = it.col();
-      double v = it.value();
-
-      MatrixXd B_triplets_copy = B_triplets;
-      B_triplets_copy.col(0) = B_triplets_copy.col(0).array() + double(B.rows()*i);
-      B_triplets_copy.col(1) = B_triplets_copy.col(1).array() + double(B.cols()*j);
-      B_triplets_copy.col(2) = B_triplets_copy.col(2).array() * v;
-
-      C_triplets.block(count*B_triplets.rows(),0,
-                       B_triplets.rows(), B_triplets.cols()) = B_triplets_copy;
-
-      count++;
-    }
-
-  typedef Eigen::Triplet<double> T;
-  std::vector<T> triplets;
-  triplets.reserve(C_triplets.rows());
-  
-  for(unsigned i=0; i<C_triplets.rows(); ++i)
-    triplets.push_back(T(C_triplets(i,0),C_triplets(i,1),C_triplets(i,2)));
-  SparseMatrix<Scalar> C(A.rows()*B.rows(),A.cols()*B.cols());
-  C.setFromTriplets(triplets.begin(),triplets.end());
-  
-  return C;
-}
-
-#ifndef IGL_HEADER_ONLY
-// Explicit template specialization
-// generated by autoexplicit.sh
-template Eigen::SparseMatrix<double, 0, int> igl::kronecker_product<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::SparseMatrix<double, 0, int> const&);
-#endif
+//// Bug in unsupported/Eigen/SparseExtra needs iostream first
+//#include <iostream>
+//#include <unsupported/Eigen/SparseExtra>
+//
+//template <typename Scalar>
+//IGL_INLINE Eigen::SparseMatrix<Scalar> igl::kronecker_product(
+//  const Eigen::SparseMatrix<Scalar> & A,
+//  const Eigen::SparseMatrix<Scalar> & B)
+//{
+//  using namespace Eigen;
+//  using namespace std;
+//
+//  // Convert B in triplets format
+//  MatrixXd B_triplets(B.nonZeros(),3);
+//  int count = 0;
+//  for (int k=0; k<B.outerSize(); ++k)
+//    for (SparseMatrix<double>::InnerIterator it(B,k); it; ++it)
+//      B_triplets.row(count++) << it.row(), it.col(), it.value();
+//
+//  MatrixXd C_triplets(B_triplets.rows()*A.nonZeros(),3);
+//  count = 0;
+//  for (int k=0; k<A.outerSize(); ++k)
+//    for (SparseMatrix<double>::InnerIterator it(A,k); it; ++it)
+//    {
+//      int i = it.row();
+//      int j = it.col();
+//      double v = it.value();
+//
+//      MatrixXd B_triplets_copy = B_triplets;
+//      B_triplets_copy.col(0) = B_triplets_copy.col(0).array() + double(B.rows()*i);
+//      B_triplets_copy.col(1) = B_triplets_copy.col(1).array() + double(B.cols()*j);
+//      B_triplets_copy.col(2) = B_triplets_copy.col(2).array() * v;
+//
+//      C_triplets.block(count*B_triplets.rows(),0,
+//                       B_triplets.rows(), B_triplets.cols()) = B_triplets_copy;
+//
+//      count++;
+//    }
+//
+//  typedef Eigen::Triplet<double> T;
+//  std::vector<T> triplets;
+//  triplets.reserve(C_triplets.rows());
+//  
+//  for(unsigned i=0; i<C_triplets.rows(); ++i)
+//    triplets.push_back(T(C_triplets(i,0),C_triplets(i,1),C_triplets(i,2)));
+//  SparseMatrix<Scalar> C(A.rows()*B.rows(),A.cols()*B.cols());
+//  C.setFromTriplets(triplets.begin(),triplets.end());
+//  
+//  return C;
+//}
+//
+//#ifndef IGL_HEADER_ONLY
+//// Explicit template specialization
+//// generated by autoexplicit.sh
+//template Eigen::SparseMatrix<double, 0, int> igl::kronecker_product<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::SparseMatrix<double, 0, int> const&);
+//#endif

+ 27 - 21
include/igl/kronecker_product.h

@@ -7,28 +7,34 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #ifndef IGL_KRONECKERPRODUCT_H
 #define IGL_KRONECKERPRODUCT_H
-#include "igl_inline.h"
 
-#include <Eigen/Dense>
-#include <Eigen/Sparse>
+// Obsolete: Use 
+// #include <unsupported/Eigen/src/KroneckerProduct>
+// ...
+// Eigen::kroneckerProduct(A,B,C);
 
-namespace igl
-{
-  // Computes the Kronecker product between sparse matrices A and B.
-  //
-  // Inputs:
-  //   A  #M by #N sparse matrix
-  //   B  #P by #Q sparse matrix
-  // Returns #M*#P by #N*#Q sparse matrix
-  //
-  template <typename Scalar>
-  IGL_INLINE Eigen::SparseMatrix<Scalar> kronecker_product(
-    const Eigen::SparseMatrix<Scalar> & A,
-    const Eigen::SparseMatrix<Scalar> & B);
-}
-
-#ifdef IGL_HEADER_ONLY
-#  include "kronecker_product.cpp"
-#endif
+//#include "igl_inline.h"
+//
+//#include <Eigen/Dense>
+//#include <Eigen/Sparse>
+//
+//namespace igl
+//{
+//  // Computes the Kronecker product between sparse matrices A and B.
+//  //
+//  // Inputs:
+//  //   A  #M by #N sparse matrix
+//  //   B  #P by #Q sparse matrix
+//  // Returns #M*#P by #N*#Q sparse matrix
+//  //
+//  template <typename Scalar>
+//  IGL_INLINE Eigen::SparseMatrix<Scalar> kronecker_product(
+//    const Eigen::SparseMatrix<Scalar> & A,
+//    const Eigen::SparseMatrix<Scalar> & B);
+//}
+//
+//#ifdef IGL_HEADER_ONLY
+//#  include "kronecker_product.cpp"
+//#endif
 
 #endif