speye.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 "speye.h"
  9. template <typename T>
  10. IGL_INLINE void igl::speye(const int m, const int n, Eigen::SparseMatrix<T> & I)
  11. {
  12. // size of diagonal
  13. int d = (m<n?m:n);
  14. I = Eigen::SparseMatrix<T>(m,n);
  15. I.reserve(d);
  16. for(int i = 0;i<d;i++)
  17. {
  18. I.insert(i,i) = 1.0;
  19. }
  20. I.finalize();
  21. }
  22. template <typename T>
  23. IGL_INLINE void igl::speye(const int n, Eigen::SparseMatrix<T> & I)
  24. {
  25. return igl::speye(n,n,I);
  26. }
  27. #ifdef IGL_STATIC_LIBRARY
  28. // Explicit template instantiation
  29. // generated by autoexplicit.sh
  30. template void igl::speye<double>(int, Eigen::SparseMatrix<double, 0, int>&);
  31. template void igl::speye<std::complex<double> >(int, int, Eigen::SparseMatrix<std::complex<double>, 0, int>&);
  32. #endif