init_fill.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2015 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2015 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. #include <armadillo>
  16. #include "catch.hpp"
  17. using namespace arma;
  18. TEST_CASE("init_fill_1")
  19. {
  20. mat Z( 5, 6, fill::zeros);
  21. mat O( 5, 6, fill::ones);
  22. mat I( 5, 6, fill::eye);
  23. mat U(50, 60, fill::randu);
  24. mat N(50, 60, fill::randn);
  25. REQUIRE( accu(Z != 0) == 0 );
  26. REQUIRE( accu(O != 0) == 5*6 );
  27. REQUIRE( accu(I != 0) == 5 );
  28. REQUIRE( mean(vectorise(U)) == Approx(0.500).epsilon(0.05) );
  29. REQUIRE( stddev(vectorise(U)) == Approx(0.288).epsilon(0.05) );
  30. REQUIRE( mean(vectorise(N)) == Approx(0.0).epsilon(0.05) );
  31. REQUIRE( stddev(vectorise(N)) == Approx(1.0).epsilon(0.05) );
  32. mat X(5, 6, fill::none); // only to test instantiation
  33. }
  34. TEST_CASE("init_fill_2")
  35. {
  36. cube Z( 5, 6, 2, fill::zeros);
  37. cube O( 5, 6, 2, fill::ones);
  38. cube U(50, 60, 2, fill::randu);
  39. cube N(50, 60, 2, fill::randn);
  40. REQUIRE( accu(Z != 0) == 0 );
  41. REQUIRE( accu(O != 0) == 5*6*2 );
  42. REQUIRE( mean(vectorise(U)) == Approx(0.500).epsilon(0.05) );
  43. REQUIRE( stddev(vectorise(U)) == Approx(0.288).epsilon(0.05) );
  44. REQUIRE( mean(vectorise(N)) == Approx(0.0).epsilon(0.05) );
  45. REQUIRE( stddev(vectorise(N)) == Approx(1.0).epsilon(0.05) );
  46. cube X(5, 6, 2, fill::none); // only to test instantiation
  47. cube I; REQUIRE_THROWS( I = cube(5, 6, 2, fill::eye) );
  48. }