00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define EIGEN_INITIALIZE_MATRICES_BY_ZERO
00028
00029 #ifndef EIGEN_NO_STATIC_ASSERT
00030 #define EIGEN_NO_STATIC_ASSERT // turn static asserts into runtime asserts in order to check them
00031 #endif
00032
00033
00034
00035
00036
00037 #include "main.h"
00038
00039 using namespace std;
00040
00041 template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
00042 {
00043 typedef std::complex<float> CF;
00044 typedef std::complex<double> CD;
00045 typedef Matrix<float, SizeAtCompileType, SizeAtCompileType> Mat_f;
00046 typedef Matrix<double, SizeAtCompileType, SizeAtCompileType> Mat_d;
00047 typedef Matrix<std::complex<float>, SizeAtCompileType, SizeAtCompileType> Mat_cf;
00048 typedef Matrix<std::complex<double>, SizeAtCompileType, SizeAtCompileType> Mat_cd;
00049 typedef Matrix<float, SizeAtCompileType, 1> Vec_f;
00050 typedef Matrix<double, SizeAtCompileType, 1> Vec_d;
00051 typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf;
00052 typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd;
00053
00054 Mat_f mf = Mat_f::Random(size,size);
00055 Mat_d md = mf.template cast<double>();
00056 Mat_cf mcf = Mat_cf::Random(size,size);
00057 Mat_cd mcd = mcf.template cast<complex<double> >();
00058 Vec_f vf = Vec_f::Random(size,1);
00059 Vec_d vd = vf.template cast<double>();
00060 Vec_cf vcf = Vec_cf::Random(size,1);
00061 Vec_cd vcd = vcf.template cast<complex<double> >();
00062 float sf = internal::random<float>();
00063 double sd = internal::random<double>();
00064 complex<float> scf = internal::random<complex<float> >();
00065 complex<double> scd = internal::random<complex<double> >();
00066
00067
00068 mf+mf;
00069 VERIFY_RAISES_ASSERT(mf+md);
00070 VERIFY_RAISES_ASSERT(mf+mcf);
00071 VERIFY_RAISES_ASSERT(vf=vd);
00072 VERIFY_RAISES_ASSERT(vf+=vd);
00073 VERIFY_RAISES_ASSERT(mcd=md);
00074
00075
00076 VERIFY_IS_APPROX(vcf * sf , vcf * complex<float>(sf));
00077 VERIFY_IS_APPROX(sd * vcd, complex<double>(sd) * vcd);
00078 VERIFY_IS_APPROX(vf * scf , vf.template cast<complex<float> >() * scf);
00079 VERIFY_IS_APPROX(scd * vd, scd * vd.template cast<complex<double> >());
00080
00081
00082 vf.dot(vf);
00083 #if 0 // we get other compilation errors here than just static asserts
00084 VERIFY_RAISES_ASSERT(vd.dot(vf));
00085 #endif
00086 VERIFY_IS_APPROX(vcf.dot(vf), vcf.dot(vf.template cast<complex<float> >()));
00087
00088
00089 VERIFY_IS_APPROX(vf.asDiagonal() * mcf, vf.template cast<complex<float> >().asDiagonal() * mcf);
00090 VERIFY_IS_APPROX(vcd.asDiagonal() * md, vcd.asDiagonal() * md.template cast<complex<double> >());
00091 VERIFY_IS_APPROX(mcf * vf.asDiagonal(), mcf * vf.template cast<complex<float> >().asDiagonal());
00092 VERIFY_IS_APPROX(md * vcd.asDiagonal(), md.template cast<complex<double> >() * vcd.asDiagonal());
00093
00094
00095
00096
00097 VERIFY_IS_APPROX((vf.transpose() * vcf).value(), (vf.template cast<complex<float> >().transpose() * vcf).value());
00098
00099
00100 VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());
00101
00102
00103
00104 VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());
00105
00106 Mat_cd mcd2 = mcd;
00107 VERIFY_IS_APPROX(mcd.array() *= md.array(), mcd2.array() *= md.array().template cast<std::complex<double> >());
00108
00109
00110
00111 VERIFY_IS_APPROX(sd*md*mcd, (sd*md).template cast<CD>().eval()*mcd);
00112 VERIFY_IS_APPROX(sd*mcd*md, sd*mcd*md.template cast<CD>());
00113 VERIFY_IS_APPROX(scd*md*mcd, scd*md.template cast<CD>().eval()*mcd);
00114 VERIFY_IS_APPROX(scd*mcd*md, scd*mcd*md.template cast<CD>());
00115
00116 VERIFY_IS_APPROX(sf*mf*mcf, sf*mf.template cast<CF>()*mcf);
00117 VERIFY_IS_APPROX(sf*mcf*mf, sf*mcf*mf.template cast<CF>());
00118 VERIFY_IS_APPROX(scf*mf*mcf, scf*mf.template cast<CF>()*mcf);
00119 VERIFY_IS_APPROX(scf*mcf*mf, scf*mcf*mf.template cast<CF>());
00120
00121 VERIFY_IS_APPROX(sf*mf*vcf, (sf*mf).template cast<CF>().eval()*vcf);
00122 VERIFY_IS_APPROX(scf*mf*vcf,(scf*mf.template cast<CF>()).eval()*vcf);
00123 VERIFY_IS_APPROX(sf*mcf*vf, sf*mcf*vf.template cast<CF>());
00124 VERIFY_IS_APPROX(scf*mcf*vf,scf*mcf*vf.template cast<CF>());
00125
00126 VERIFY_IS_APPROX(sf*vcf.adjoint()*mf, sf*vcf.adjoint()*mf.template cast<CF>().eval());
00127 VERIFY_IS_APPROX(scf*vcf.adjoint()*mf, scf*vcf.adjoint()*mf.template cast<CF>().eval());
00128 VERIFY_IS_APPROX(sf*vf.adjoint()*mcf, sf*vf.adjoint().template cast<CF>().eval()*mcf);
00129 VERIFY_IS_APPROX(scf*vf.adjoint()*mcf, scf*vf.adjoint().template cast<CF>().eval()*mcf);
00130
00131 VERIFY_IS_APPROX(sd*md*vcd, (sd*md).template cast<CD>().eval()*vcd);
00132 VERIFY_IS_APPROX(scd*md*vcd,(scd*md.template cast<CD>()).eval()*vcd);
00133 VERIFY_IS_APPROX(sd*mcd*vd, sd*mcd*vd.template cast<CD>().eval());
00134 VERIFY_IS_APPROX(scd*mcd*vd,scd*mcd*vd.template cast<CD>().eval());
00135
00136 VERIFY_IS_APPROX(sd*vcd.adjoint()*md, sd*vcd.adjoint()*md.template cast<CD>().eval());
00137 VERIFY_IS_APPROX(scd*vcd.adjoint()*md, scd*vcd.adjoint()*md.template cast<CD>().eval());
00138 VERIFY_IS_APPROX(sd*vd.adjoint()*mcd, sd*vd.adjoint().template cast<CD>().eval()*mcd);
00139 VERIFY_IS_APPROX(scd*vd.adjoint()*mcd, scd*vd.adjoint().template cast<CD>().eval()*mcd);
00140 }
00141
00142 void test_mixingtypes()
00143 {
00144 CALL_SUBTEST_1(mixingtypes<3>());
00145 CALL_SUBTEST_2(mixingtypes<4>());
00146 CALL_SUBTEST_3(mixingtypes<Dynamic>(internal::random<int>(1,310)));
00147 }