GenSpecialiser.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 GenSpecialiser
  16. //! @{
  17. template<typename elem_type, bool is_gen_zeros, bool is_gen_ones, bool is_gen_randu, bool is_gen_randn>
  18. struct GenSpecialiser
  19. {
  20. arma_inline elem_type generate() const { return elem_type(); }
  21. };
  22. template<typename elem_type>
  23. struct GenSpecialiser<elem_type, true, false, false, false>
  24. {
  25. arma_inline elem_type generate() const { return elem_type(0); }
  26. };
  27. template<typename elem_type>
  28. struct GenSpecialiser<elem_type, false, true, false, false>
  29. {
  30. arma_inline elem_type generate() const { return elem_type(1); }
  31. };
  32. template<typename elem_type>
  33. struct GenSpecialiser<elem_type, false, false, true, false>
  34. {
  35. arma_inline elem_type generate() const { return elem_type(arma_rng::randu<elem_type>()); }
  36. };
  37. template<typename elem_type>
  38. struct GenSpecialiser<elem_type, false, false, false, true>
  39. {
  40. arma_inline elem_type generate() const { return elem_type(arma_rng::randn<elem_type>()); }
  41. };
  42. //! @}