sprow.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2011-2017 Ryan Curtin (http://www.ratml.org/)
  2. // Copyright 2017 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("sprow_shed_col_test")
  19. {
  20. SpRow<int> d(10);
  21. d[3] = 2;
  22. d[4] = 6;
  23. d[6] = 2;
  24. d[7] = 9;
  25. d[8] = 1;
  26. d[9] = -2;
  27. d.shed_cols(4, 7);
  28. REQUIRE( d.n_cols == 6 );
  29. REQUIRE( d.n_rows == 1 );
  30. REQUIRE( d.n_elem == 6 );
  31. REQUIRE( d.n_nonzero == 3 );
  32. REQUIRE( d[0] == 0 );
  33. REQUIRE( d[1] == 0 );
  34. REQUIRE( d[2] == 0 );
  35. REQUIRE( d[3] == 2 );
  36. REQUIRE( d[4] == 1 );
  37. REQUIRE( d[5] == -2 );
  38. }
  39. TEST_CASE("sprow_row_constructor_test")
  40. {
  41. SpMat<double> m(100, 100);
  42. m.sprandu(100, 100, 0.3);
  43. SpRow<double> r = m.row(0);
  44. rowvec v(r);
  45. for (uword i = 0; i < 100; ++i)
  46. {
  47. REQUIRE( v(i) == (double) r(i) );
  48. }
  49. }