transpose_blocks.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. #ifndef IGL_TRANSPOSE_BLOCKS_H
  9. #define IGL_TRANSPOSE_BLOCKS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Transpose blocks of a matrix
  15. ///
  16. /// @tparam T should be a eigen matrix primitive type like int or double
  17. /// @param[in] A m*k by n (dim: 1) or m by n*k (dim: 2) eigen Matrix of type T values
  18. /// @param[in] k number of blocks
  19. /// @param[in] dim dimension in which to transpose
  20. /// @param[out] B n*k by m (dim: 1) or n by m*k (dim: 2) eigen Matrix of type T values,
  21. /// NOT allowed to be the same as A
  22. ///
  23. /// #### Example:
  24. /// A = [
  25. /// 1 2 3 4
  26. /// 5 6 7 8
  27. /// 101 102 103 104
  28. /// 105 106 107 108
  29. /// 201 202 203 204
  30. /// 205 206 207 208];
  31. /// transpose_blocks(A,1,3,B);
  32. /// B -> [
  33. /// 1 5
  34. /// 2 6
  35. /// 3 7
  36. /// 4 8
  37. /// 101 105
  38. /// 102 106
  39. /// 103 107
  40. /// 104 108
  41. /// 201 205
  42. /// 202 206
  43. /// 203 207
  44. /// 204 208];
  45. ///
  46. template <typename T>
  47. IGL_INLINE void transpose_blocks(
  48. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & A,
  49. const size_t k,
  50. const size_t dim,
  51. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  52. }
  53. #ifndef IGL_STATIC_LIBRARY
  54. # include "transpose_blocks.cpp"
  55. #endif
  56. #endif