testMatrixFunctions.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @file testMatrixFunctions.cpp
  3. * @author Alexander Lütz
  4. * @date 07/10/2011
  5. * @brief test routine for the main functions of the MatrixT-class (at the moment only row/col-deletion is tested)
  6. */
  7. #include "core/vector/MatrixT.h"
  8. #include "iostream"
  9. #include "vector"
  10. #include "core/basics/Exception.h"
  11. using namespace std;
  12. int main(int argc, char* argv[])
  13. {
  14. NICE::Matrix foo(10,10,0.0);
  15. std::cerr << "foo: " << std::endl;
  16. for (uint i = 0; i < foo.rows(); i++)
  17. {
  18. for (uint j = 0; j < foo.cols(); j++)
  19. {
  20. if (i>0)
  21. foo(i,j) = i;
  22. else foo(i,j) = j;
  23. std::cerr << " " << foo(i,j);
  24. }
  25. std::cerr << std::endl;
  26. }
  27. foo.deleteRow(8);
  28. std::cerr << "foo after deleting row 8: " << std::endl;
  29. for (uint i = 0; i < foo.rows(); i++)
  30. {
  31. for (uint j = 0; j < foo.cols(); j++)
  32. {
  33. std::cerr << " " << foo(i,j);
  34. }
  35. std::cerr << std::endl;
  36. }
  37. foo.deleteCol(7);
  38. std::cerr << "foo after deleting col 7: " << std::endl;
  39. for (uint i = 0; i < foo.rows(); i++)
  40. {
  41. for (uint j = 0; j < foo.cols(); j++)
  42. {
  43. std::cerr << " " << foo(i,j);
  44. }
  45. std::cerr << std::endl;
  46. }
  47. std::vector<int> indices_to_delete;
  48. indices_to_delete.push_back(2);
  49. indices_to_delete.push_back(5);
  50. foo.deleteRows(indices_to_delete);
  51. std::cerr << "foo after deleting rows 2 and 5: " << std::endl;
  52. for (uint i = 0; i < foo.rows(); i++)
  53. {
  54. for (uint j = 0; j < foo.cols(); j++)
  55. {
  56. std::cerr << " " << foo(i,j);
  57. }
  58. std::cerr << std::endl;
  59. }
  60. foo.deleteCols(indices_to_delete);
  61. std::cerr << "foo after deleting cols 2 and 5: " << std::endl;
  62. for (uint i = 0; i < foo.rows(); i++)
  63. {
  64. for (uint j = 0; j < foo.cols(); j++)
  65. {
  66. std::cerr << " " << foo(i,j);
  67. }
  68. std::cerr << std::endl;
  69. }
  70. std::cerr << "Try to delete row 11, which should produce an error!" << std::endl;
  71. try{
  72. //this should produce an error!
  73. foo.deleteRow(11);
  74. }
  75. catch (NICE::Exception e)
  76. {
  77. std::cerr << "Exception succesfully thrown!" << std::endl;
  78. }
  79. return 0;
  80. }