fn_eye.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_eye
  16. //! @{
  17. arma_warn_unused
  18. arma_inline
  19. const Gen<mat, gen_eye>
  20. eye(const uword n_rows, const uword n_cols)
  21. {
  22. arma_extra_debug_sigprint();
  23. return Gen<mat, gen_eye>(n_rows, n_cols);
  24. }
  25. arma_warn_unused
  26. arma_inline
  27. const Gen<mat, gen_eye>
  28. eye(const SizeMat& s)
  29. {
  30. arma_extra_debug_sigprint();
  31. return Gen<mat, gen_eye>(s.n_rows, s.n_cols);
  32. }
  33. template<typename obj_type>
  34. arma_warn_unused
  35. arma_inline
  36. const Gen<obj_type, gen_eye>
  37. eye(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
  38. {
  39. arma_extra_debug_sigprint();
  40. arma_ignore(junk);
  41. if(is_Col<obj_type>::value)
  42. {
  43. arma_debug_check( (n_cols != 1), "eye(): incompatible size" );
  44. }
  45. else
  46. if(is_Row<obj_type>::value)
  47. {
  48. arma_debug_check( (n_rows != 1), "eye(): incompatible size" );
  49. }
  50. return Gen<obj_type, gen_eye>(n_rows, n_cols);
  51. }
  52. template<typename obj_type>
  53. arma_warn_unused
  54. arma_inline
  55. const Gen<obj_type, gen_eye>
  56. eye(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
  57. {
  58. arma_extra_debug_sigprint();
  59. arma_ignore(junk);
  60. return eye<obj_type>(s.n_rows, s.n_cols);
  61. }
  62. template<typename obj_type>
  63. arma_warn_unused
  64. inline
  65. obj_type
  66. eye(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<obj_type>::result* junk = NULL)
  67. {
  68. arma_extra_debug_sigprint();
  69. arma_ignore(junk);
  70. if(is_SpCol<obj_type>::value)
  71. {
  72. arma_debug_check( (n_cols != 1), "eye(): incompatible size" );
  73. }
  74. else
  75. if(is_SpRow<obj_type>::value)
  76. {
  77. arma_debug_check( (n_rows != 1), "eye(): incompatible size" );
  78. }
  79. obj_type out;
  80. out.eye(n_rows, n_cols);
  81. return out;
  82. }
  83. template<typename obj_type>
  84. arma_warn_unused
  85. inline
  86. obj_type
  87. eye(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<obj_type>::result* junk = NULL)
  88. {
  89. arma_extra_debug_sigprint();
  90. arma_ignore(junk);
  91. return eye<obj_type>(s.n_rows, s.n_cols);
  92. }
  93. //! @}