num_rows.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (c) 2011 David Bellot
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/numeric/ublas/fwd.hpp>
  7. #include <boost/numeric/ublas/matrix.hpp>
  8. #include <boost/numeric/ublas/matrix_expression.hpp>
  9. #include <boost/numeric/ublas/operation/num_rows.hpp>
  10. #include <iostream>
  11. #include "utils.hpp"
  12. BOOST_UBLAS_TEST_DEF( test_row_major_matrix_container )
  13. {
  14. BOOST_UBLAS_DEBUG_TRACE( "TEST Row-major Matrix Container" );
  15. typedef double value_type;
  16. typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
  17. matrix_type A(5,4);
  18. A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
  19. A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
  20. A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
  21. A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
  22. A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
  23. BOOST_UBLAS_DEBUG_TRACE( "num_rows(A) = " << boost::numeric::ublas::num_rows(A) << " ==> " << A.size1() );
  24. BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(A) == A.size1() );
  25. }
  26. BOOST_UBLAS_TEST_DEF( test_col_major_matrix_container )
  27. {
  28. BOOST_UBLAS_DEBUG_TRACE( "TEST Column-major Matrix Container" );
  29. typedef double value_type;
  30. typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::column_major> matrix_type;
  31. matrix_type A(5,4);
  32. A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
  33. A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
  34. A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
  35. A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
  36. A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
  37. BOOST_UBLAS_DEBUG_TRACE( "num_rows(A) = " << boost::numeric::ublas::num_rows(A) << " ==> " << A.size1() );
  38. BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(A) == A.size1() );
  39. }
  40. BOOST_UBLAS_TEST_DEF( test_matrix_expression )
  41. {
  42. BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Expression" );
  43. typedef double value_type;
  44. typedef boost::numeric::ublas::matrix<value_type> matrix_type;
  45. matrix_type A(5,4);
  46. A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
  47. A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
  48. A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
  49. A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
  50. A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
  51. BOOST_UBLAS_DEBUG_TRACE( "num_rows(A') = " << boost::numeric::ublas::num_rows(boost::numeric::ublas::trans(A)) << " ==> " << boost::numeric::ublas::trans(A).size1() );
  52. BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(boost::numeric::ublas::trans(A)) == boost::numeric::ublas::trans(A).size1() );
  53. }
  54. BOOST_UBLAS_TEST_DEF( test_matrix_reference )
  55. {
  56. BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Reference" );
  57. typedef double value_type;
  58. typedef boost::numeric::ublas::matrix<value_type> matrix_type;
  59. typedef boost::numeric::ublas::matrix_reference<matrix_type> matrix_reference_type;
  60. matrix_type A(5,4);
  61. A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
  62. A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
  63. A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
  64. A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
  65. A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
  66. BOOST_UBLAS_DEBUG_TRACE( "num_rows(reference(A)) = " << boost::numeric::ublas::num_rows(matrix_reference_type(A)) << " ==> " << matrix_reference_type(A).size1() );
  67. BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(matrix_reference_type(A)) == matrix_reference_type(A).size1() );
  68. }
  69. int main()
  70. {
  71. BOOST_UBLAS_TEST_BEGIN();
  72. BOOST_UBLAS_TEST_DO( test_row_major_matrix_container );
  73. BOOST_UBLAS_TEST_DO( test_col_major_matrix_container );
  74. BOOST_UBLAS_TEST_DO( test_matrix_expression );
  75. BOOST_UBLAS_TEST_DO( test_matrix_reference );
  76. BOOST_UBLAS_TEST_END();
  77. }