kronecker_product.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "kronecker_product.h"
  9. //// Bug in unsupported/Eigen/SparseExtra needs iostream first
  10. //#include <iostream>
  11. //#include <unsupported/Eigen/SparseExtra>
  12. //
  13. //template <typename Scalar>
  14. //IGL_INLINE Eigen::SparseMatrix<Scalar> igl::kronecker_product(
  15. // const Eigen::SparseMatrix<Scalar> & A,
  16. // const Eigen::SparseMatrix<Scalar> & B)
  17. //{
  18. // using namespace Eigen;
  19. // using namespace std;
  20. //
  21. // // Convert B in triplets format
  22. // MatrixXd B_triplets(B.nonZeros(),3);
  23. // int count = 0;
  24. // for (int k=0; k<B.outerSize(); ++k)
  25. // for (SparseMatrix<double>::InnerIterator it(B,k); it; ++it)
  26. // B_triplets.row(count++) << it.row(), it.col(), it.value();
  27. //
  28. // MatrixXd C_triplets(B_triplets.rows()*A.nonZeros(),3);
  29. // count = 0;
  30. // for (int k=0; k<A.outerSize(); ++k)
  31. // for (SparseMatrix<double>::InnerIterator it(A,k); it; ++it)
  32. // {
  33. // int i = it.row();
  34. // int j = it.col();
  35. // double v = it.value();
  36. //
  37. // MatrixXd B_triplets_copy = B_triplets;
  38. // B_triplets_copy.col(0) = B_triplets_copy.col(0).array() + double(B.rows()*i);
  39. // B_triplets_copy.col(1) = B_triplets_copy.col(1).array() + double(B.cols()*j);
  40. // B_triplets_copy.col(2) = B_triplets_copy.col(2).array() * v;
  41. //
  42. // C_triplets.block(count*B_triplets.rows(),0,
  43. // B_triplets.rows(), B_triplets.cols()) = B_triplets_copy;
  44. //
  45. // count++;
  46. // }
  47. //
  48. // typedef Eigen::Triplet<double> T;
  49. // std::vector<T> triplets;
  50. // triplets.reserve(C_triplets.rows());
  51. //
  52. // for(unsigned i=0; i<C_triplets.rows(); ++i)
  53. // triplets.push_back(T(C_triplets(i,0),C_triplets(i,1),C_triplets(i,2)));
  54. // SparseMatrix<Scalar> C(A.rows()*B.rows(),A.cols()*B.cols());
  55. // C.setFromTriplets(triplets.begin(),triplets.end());
  56. //
  57. // return C;
  58. //}
  59. //
  60. //#ifdef IGL_STATIC_LIBRARY
  61. //// Explicit template specialization
  62. //// generated by autoexplicit.sh
  63. //template Eigen::SparseMatrix<double, 0, int> igl::kronecker_product<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::SparseMatrix<double, 0, int> const&);
  64. //#endif