00001 #include <cstdlib>
00002 #include <iostream>
00003 #include <complex>
00004
00005 #include <kfilter/kmatrix.hpp>
00006
00007 using namespace std;
00008 using namespace Kalman;
00009
00010 template <typename T, K_UINT_32 BEG, bool DBG>
00011 void test() {
00012
00013 typedef KMatrix<T, BEG, DBG> Matrix;
00014 T values[10] = {9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0};
00015
00016
00017 Matrix M0;
00018 Matrix M1(0,4);
00019 Matrix M2(2,3);
00020 Matrix M3(0, 2, T(1.0));
00021 Matrix M4(4, 1, T(2.0));
00022 Matrix M5(3, 0, values);
00023 Matrix M6(3, 1, values);
00024 Matrix M7(M5);
00025 Matrix M8(M6);
00026 Matrix M9(4,0);
00027
00028 cout << "M0 : " << M0 << endl;
00029 cout << "M1 : " << M1 << endl;
00030 cout << "M2 : " << M2 << endl;
00031 cout << "M3 : " << M3 << endl;
00032 cout << "M4 : " << M4 << endl;
00033 cout << "M5 : " << M5 << endl;
00034 cout << "M6 : " << M6 << endl;
00035 cout << "M7 : " << M7 << endl;
00036 cout << "M8 : " << M8 << endl;
00037 cout << "M9 : " << M9 << endl << endl;
00038
00039
00040 M4.resize(0, 2);
00041 M4 = T(-1.0);
00042 M5 = T(6.0);
00043 M6 = T(7.0);
00044 M7.resize(2, 1);
00045 M7 = T(8.0);
00046 M8.resize(4, 2);
00047 M8 = T(9.0);
00048
00049 cout << "M4 : " << M4 << endl;
00050 cout << "M5 : " << M5 << endl;
00051 cout << "M6 : " << M6 << endl;
00052 cout << "M7 : " << M7 << endl;
00053 cout << "M8 : " << M8 << endl << endl;
00054
00055
00056
00057 M5 = M7;
00058 M6 = M8;
00059 M7 = M0;
00060 M0.assign(0, 2, values);
00061 M1.assign(2, 1, values);
00062 M2.assign(3, 0, values);
00063 M4.assign(3, 2, values);
00064
00065 cout << "M0 : " << M0 << endl;
00066 cout << "M1 : " << M1 << endl;
00067 cout << "M2 : " << M2 << endl;
00068 cout << "M3 : " << M3 << endl;
00069 cout << "M4 : " << M4 << endl;
00070 cout << "M5 : " << M5 << endl;
00071 cout << "M6 : " << M6 << endl;
00072 cout << "M7 : " << M7 << endl;
00073 cout << "M8 : " << M8 << endl << endl;
00074
00075
00076
00077 const Matrix& ref = M4;
00078
00079 cout << "M4(1,1) = " << M4(1,1) << endl;
00080 cout << "ref(1,1) = " << ref(1,1) << endl;
00081
00082 M4(1,1) = T(3.0);
00083
00084
00085 cout << "M4(1,1) = " << M4(1,1) << endl;
00086 cout << "ref(1,1) = " << ref(1,1) << endl;
00087
00088 if (DBG) {
00089
00090 try {
00091 M4(100,100) = T(7.0);
00092 } catch(OutOfBoundError& e) {
00093 cout << e.what() << endl;
00094 }
00095
00096 try {
00097 cout << ref(100,100) << endl;
00098 } catch(OutOfBoundError& e) {
00099 cout << e.what() << endl;
00100 }
00101
00102 }
00103
00104 cout << endl;
00105
00106
00107
00108
00109 cout << "M0 is of size : " << M0.nrow() << " by " << M0.ncol() << endl;
00110 cin >> M0;
00111 cout << "M0 : " << M0 << endl;
00112
00113 cout << "M1 is of size : " << M1.nrow() << " by " << M1.ncol() << endl;
00114 cin >> M1;
00115 cout << "M1 : " << M1 << endl;
00116
00117 cout << "----------------------------" << endl << endl;
00118
00119 }
00120
00121 int main() {
00122
00123
00124 test<float, 1, true>();
00125 test<float, 1, false>();
00126
00127
00128 test<double, 1, true>();
00129 test<double, 1, false>();
00130
00131
00132 test<complex<double>, 1, true>();
00133 test<complex<double>, 1, false>();
00134 return 0;
00135 }