transpose_blocks.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #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. // Templates:
  15. // T should be a eigen matrix primitive type like int or double
  16. // Inputs:
  17. // A m*k by n (dim: 1) or m by n*k (dim: 2) eigen Matrix of type T values
  18. // k number of blocks
  19. // dim dimension in which to transpose
  20. // Output
  21. // B n*k by m (dim: 1) or n by m*k (dim: 2) eigen Matrix of type T values,
  22. // NOT allowed to be the same as A
  23. //
  24. // Example:
  25. // A = [
  26. // 1 2 3 4
  27. // 5 6 7 8
  28. // 101 102 103 104
  29. // 105 106 107 108
  30. // 201 202 203 204
  31. // 205 206 207 208];
  32. // transpose_blocks(A,1,3,B);
  33. // B -> [
  34. // 1 5
  35. // 2 6
  36. // 3 7
  37. // 4 8
  38. // 101 105
  39. // 102 106
  40. // 103 107
  41. // 104 108
  42. // 201 205
  43. // 202 206
  44. // 203 207
  45. // 204 208];
  46. //
  47. template <typename T>
  48. IGL_INLINE void transpose_blocks(
  49. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & A,
  50. const size_t k,
  51. const size_t dim,
  52. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  53. }
  54. #ifndef IGL_STATIC_LIBRARY
  55. # include "transpose_blocks.cpp"
  56. #endif
  57. #endif