isdiag.cpp 915 B

1234567891011121314151617181920212223242526272829303132
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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 "isdiag.h"
  9. template <typename Scalar>
  10. IGL_INLINE bool igl::isdiag(const Eigen::SparseMatrix<Scalar> & A)
  11. {
  12. // Iterate over outside of A
  13. for(int k=0; k<A.outerSize(); ++k)
  14. {
  15. // Iterate over inside
  16. for(typename Eigen::SparseMatrix<Scalar>::InnerIterator it (A,k); it; ++it)
  17. {
  18. if(it.row() != it.col() && it.value()!=0)
  19. {
  20. return false;
  21. }
  22. }
  23. }
  24. return true;
  25. }
  26. #ifdef IGL_STATIC_LIBRARY
  27. // Explicit template instantiation
  28. template bool igl::isdiag<double>(class Eigen::SparseMatrix<double,0,int> const &);
  29. #endif