fn_ones.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_ones
  16. //! @{
  17. arma_warn_unused
  18. arma_inline
  19. const Gen<vec, gen_ones>
  20. ones(const uword n_elem)
  21. {
  22. arma_extra_debug_sigprint();
  23. return Gen<vec, gen_ones>(n_elem, 1);
  24. }
  25. template<typename obj_type>
  26. arma_warn_unused
  27. arma_inline
  28. const Gen<obj_type, gen_ones>
  29. ones(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
  30. {
  31. arma_extra_debug_sigprint();
  32. arma_ignore(junk1);
  33. arma_ignore(junk2);
  34. if(is_Row<obj_type>::value)
  35. {
  36. return Gen<obj_type, gen_ones>(1, n_elem);
  37. }
  38. else
  39. {
  40. return Gen<obj_type, gen_ones>(n_elem, 1);
  41. }
  42. }
  43. arma_warn_unused
  44. arma_inline
  45. const Gen<mat, gen_ones>
  46. ones(const uword n_rows, const uword n_cols)
  47. {
  48. arma_extra_debug_sigprint();
  49. return Gen<mat, gen_ones>(n_rows, n_cols);
  50. }
  51. arma_warn_unused
  52. arma_inline
  53. const Gen<mat, gen_ones>
  54. ones(const SizeMat& s)
  55. {
  56. arma_extra_debug_sigprint();
  57. return Gen<mat, gen_ones>(s.n_rows, s.n_cols);
  58. }
  59. template<typename obj_type>
  60. arma_warn_unused
  61. inline
  62. const Gen<obj_type, gen_ones>
  63. ones(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
  64. {
  65. arma_extra_debug_sigprint();
  66. arma_ignore(junk);
  67. if(is_Col<obj_type>::value)
  68. {
  69. arma_debug_check( (n_cols != 1), "ones(): incompatible size" );
  70. }
  71. else
  72. if(is_Row<obj_type>::value)
  73. {
  74. arma_debug_check( (n_rows != 1), "ones(): incompatible size" );
  75. }
  76. return Gen<obj_type, gen_ones>(n_rows, n_cols);
  77. }
  78. template<typename obj_type>
  79. arma_warn_unused
  80. inline
  81. const Gen<obj_type, gen_ones>
  82. ones(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
  83. {
  84. arma_extra_debug_sigprint();
  85. arma_ignore(junk);
  86. return ones<obj_type>(s.n_rows, s.n_cols);
  87. }
  88. arma_warn_unused
  89. arma_inline
  90. const GenCube<cube::elem_type, gen_ones>
  91. ones(const uword n_rows, const uword n_cols, const uword n_slices)
  92. {
  93. arma_extra_debug_sigprint();
  94. return GenCube<cube::elem_type, gen_ones>(n_rows, n_cols, n_slices);
  95. }
  96. arma_warn_unused
  97. arma_inline
  98. const GenCube<cube::elem_type, gen_ones>
  99. ones(const SizeCube& s)
  100. {
  101. arma_extra_debug_sigprint();
  102. return GenCube<cube::elem_type, gen_ones>(s.n_rows, s.n_cols, s.n_slices);
  103. }
  104. template<typename cube_type>
  105. arma_warn_unused
  106. arma_inline
  107. const GenCube<typename cube_type::elem_type, gen_ones>
  108. ones(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
  109. {
  110. arma_extra_debug_sigprint();
  111. arma_ignore(junk);
  112. return GenCube<typename cube_type::elem_type, gen_ones>(n_rows, n_cols, n_slices);
  113. }
  114. template<typename cube_type>
  115. arma_warn_unused
  116. arma_inline
  117. const GenCube<typename cube_type::elem_type, gen_ones>
  118. ones(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
  119. {
  120. arma_extra_debug_sigprint();
  121. arma_ignore(junk);
  122. return GenCube<typename cube_type::elem_type, gen_ones>(s.n_rows, s.n_cols, s.n_slices);
  123. }
  124. //! @}