fn_zeros.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_zeros
  16. //! @{
  17. arma_warn_unused
  18. arma_inline
  19. const Gen<vec, gen_zeros>
  20. zeros(const uword n_elem)
  21. {
  22. arma_extra_debug_sigprint();
  23. return Gen<vec, gen_zeros>(n_elem, 1);
  24. }
  25. template<typename obj_type>
  26. arma_warn_unused
  27. arma_inline
  28. const Gen<obj_type, gen_zeros>
  29. zeros(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_zeros>(1, n_elem);
  37. }
  38. else
  39. {
  40. return Gen<obj_type, gen_zeros>(n_elem, 1);
  41. }
  42. }
  43. arma_warn_unused
  44. arma_inline
  45. const Gen<mat, gen_zeros>
  46. zeros(const uword n_rows, const uword n_cols)
  47. {
  48. arma_extra_debug_sigprint();
  49. return Gen<mat, gen_zeros>(n_rows, n_cols);
  50. }
  51. arma_warn_unused
  52. arma_inline
  53. const Gen<mat, gen_zeros>
  54. zeros(const SizeMat& s)
  55. {
  56. arma_extra_debug_sigprint();
  57. return Gen<mat, gen_zeros>(s.n_rows, s.n_cols);
  58. }
  59. template<typename obj_type>
  60. arma_warn_unused
  61. arma_inline
  62. const Gen<obj_type, gen_zeros>
  63. zeros(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), "zeros(): incompatible size" );
  70. }
  71. else
  72. if(is_Row<obj_type>::value)
  73. {
  74. arma_debug_check( (n_rows != 1), "zeros(): incompatible size" );
  75. }
  76. return Gen<obj_type, gen_zeros>(n_rows, n_cols);
  77. }
  78. template<typename obj_type>
  79. arma_warn_unused
  80. arma_inline
  81. const Gen<obj_type, gen_zeros>
  82. zeros(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 zeros<obj_type>(s.n_rows, s.n_cols);
  87. }
  88. arma_warn_unused
  89. arma_inline
  90. const GenCube<cube::elem_type, gen_zeros>
  91. zeros(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_zeros>(n_rows, n_cols, n_slices);
  95. }
  96. arma_warn_unused
  97. arma_inline
  98. const GenCube<cube::elem_type, gen_zeros>
  99. zeros(const SizeCube& s)
  100. {
  101. arma_extra_debug_sigprint();
  102. return GenCube<cube::elem_type, gen_zeros>(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_zeros>
  108. zeros(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_zeros>(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_zeros>
  118. zeros(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_zeros>(s.n_rows, s.n_cols, s.n_slices);
  123. }
  124. template<typename sp_obj_type>
  125. arma_warn_unused
  126. inline
  127. sp_obj_type
  128. zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
  129. {
  130. arma_extra_debug_sigprint();
  131. arma_ignore(junk);
  132. if(is_SpCol<sp_obj_type>::value == true)
  133. {
  134. arma_debug_check( (n_cols != 1), "zeros(): incompatible size" );
  135. }
  136. else
  137. if(is_SpRow<sp_obj_type>::value == true)
  138. {
  139. arma_debug_check( (n_rows != 1), "zeros(): incompatible size" );
  140. }
  141. return sp_obj_type(n_rows, n_cols);
  142. }
  143. template<typename sp_obj_type>
  144. arma_warn_unused
  145. inline
  146. sp_obj_type
  147. zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
  148. {
  149. arma_extra_debug_sigprint();
  150. arma_ignore(junk);
  151. return zeros<sp_obj_type>(s.n_rows, s.n_cols);
  152. }
  153. //! @}