10 #if defined(_MSC_VER) && (_MSC_VER==1800)
13 #pragma optimize("",off)
23 #define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN { on_temporary_creation(); }
27 #define VERIFY_EVALUATION_COUNT(XPR,N) {\
29 CALL_SUBTEST( XPR ); \
30 if(nb_temporaries!=N) std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; \
31 VERIFY( (#XPR) && nb_temporaries==N ); \
38 typedef typename SparseMatrixType::StorageIndex StorageIndex;
40 const Index rows = internal::random<Index>(1,
n);
41 const Index cols = internal::random<Index>(1,
n);
44 enum { Flags = SparseMatrixType::Flags };
53 Scalar s1 = internal::random<Scalar>();
54 Scalar s2 = internal::random<Scalar>();
88 VERIFY_IS_APPROX(m4=m2t.transpose()*m3t.transpose(), refMat4=refMat2t.transpose()*refMat3t.transpose());
99 VERIFY_IS_APPROX(m4=(m2t.transpose()*
m3).pruned(0), refMat4=refMat2t.transpose()*refMat3);
100 VERIFY_IS_APPROX(m4=(m2t.transpose()*m3t.transpose()).pruned(0), refMat4=refMat2t.transpose()*refMat3t.transpose());
101 VERIFY_IS_APPROX(m4=(
m2*m3t.transpose()).pruned(0), refMat4=refMat2*refMat3t.transpose());
103 #ifndef EIGEN_SPARSE_PRODUCT_IGNORE_TEMPORARY_COUNT
105 if((!SparseMatrixType::IsRowMajor) &&
m2.rows()<=
m3.cols())
117 SparseMatrixType As(Ad.sparseView()),
B(2,2);
119 VERIFY_IS_EQUAL( (Ad*Ad.transpose()).eval().sparseView().eval().nonZeros(), 2);
130 VERIFY_IS_APPROX(dm4 =m2t.transpose()*m3t.transpose(), refMat4 =refMat2t.transpose()*refMat3t.transpose());
131 VERIFY_IS_APPROX(dm4+=m2t.transpose()*m3t.transpose(), refMat4+=refMat2t.transpose()*refMat3t.transpose());
132 VERIFY_IS_APPROX(dm4-=m2t.transpose()*m3t.transpose(), refMat4-=refMat2t.transpose()*refMat3t.transpose());
139 m4 =
m2; refMat4 = refMat2;
145 VERIFY_IS_APPROX(dm4=m2t.transpose()*refMat3, refMat4=refMat2t.transpose()*refMat3);
146 VERIFY_IS_APPROX(dm4=m2t.transpose()*refMat3t.transpose(), refMat4=refMat2t.transpose()*refMat3t.transpose());
155 VERIFY_IS_APPROX(dm4=m2t.transpose()*(refMat3+refMat5)*0.5, refMat4=refMat2t.transpose()*(refMat3+refMat5)*0.5);
158 VERIFY_IS_APPROX(dm4.col(0)=
m2*refMat3.col(0), refMat4.col(0)=refMat2*refMat3.col(0));
159 VERIFY_IS_APPROX(dm4.col(0)=
m2*refMat3t.transpose().col(0), refMat4.col(0)=refMat2*refMat3t.transpose().col(0));
160 VERIFY_IS_APPROX(dm4.col(0)=m2t.transpose()*refMat3.col(0), refMat4.col(0)=refMat2t.transpose()*refMat3.col(0));
161 VERIFY_IS_APPROX(dm4.col(0)=m2t.transpose()*refMat3t.transpose().col(0), refMat4.col(0)=refMat2t.transpose()*refMat3t.transpose().col(0));
170 VERIFY_IS_APPROX(dm4=refMat2*m3t.transpose(), refMat4=refMat2*refMat3t.transpose());
172 VERIFY_IS_APPROX(dm4=refMat2t.transpose()*m3t.transpose(), refMat4=refMat2t.transpose()*refMat3t.transpose());
177 Index r = internal::random<Index>(0,
rows-1);
194 VERIFY_IS_APPROX( m4=dm5.row(
r1).transpose()*
m2.col(
c).transpose(), refMat4=dm5.row(
r1).transpose()*refMat2.col(
c).transpose());
196 VERIFY_IS_APPROX(dm4=dm5.row(
r1).transpose()*
m2.col(
c).transpose(), refMat4=dm5.row(
r1).transpose()*refMat2.col(
c).transpose());
198 VERIFY_IS_APPROX( m4=
m2.row(r).transpose()*dm5.col(
c1).transpose(), refMat4=refMat2.row(r).transpose()*dm5.col(
c1).transpose());
200 VERIFY_IS_APPROX( m4=
m2.middleRows(r,1).transpose()*dm5.col(
c1).transpose(), refMat4=refMat2.row(r).transpose()*dm5.col(
c1).transpose());
202 VERIFY_IS_APPROX(dm4=
m2.row(r).transpose()*dm5.col(
c1).transpose(), refMat4=refMat2.row(r).transpose()*dm5.col(
c1).transpose());
218 ColSpVector cv0(
cols), cv1;
222 RowSpVector rv0(
depth), rv1;
223 RowDenseVector drv0(
depth), drv1(rv1);
283 initSparse<Scalar>(
density, refA, mA);
286 }
while (refUp.isZero());
287 refLo = refUp.adjoint();
289 refS = refUp + refLo;
290 refS.diagonal() *= 0.5;
293 for (
int k=0; k<mS.outerSize(); ++k)
294 for (
typename SparseMatrixType::InnerIterator it(mS,k); it; ++it)
296 it.valueRef() *=
Scalar(0.5);
319 refX = refLo.template selfadjointView<Lower>()*refS);
321 refX = refS * refLo.template selfadjointView<Lower>());
324 VERIFY_IS_APPROX(
x=mA.template triangularView<Upper>()*
b, refX=refA.template triangularView<Upper>()*
b);
326 VERIFY_IS_APPROX(
x=
b*mA.template triangularView<Upper>(), refX=
b*refA.template triangularView<Upper>());
332 VERIFY_IS_APPROX(mSres = mA.template triangularView<Upper>()*mS, refX = refA.template triangularView<Upper>()*refS);
333 VERIFY_IS_APPROX(mSres = mS * mA.template triangularView<Upper>(), refX = refS * refA.template triangularView<Upper>());
341 SparseMatrixType sm1(3,2);
342 DenseMatrixType
m2(2,2);
346 DenseMatrixType
m3 = sm1*
m2;
352 SparseMatrixType sm2(20000,2);
354 DenseMatrixType m4(sm2*
m2);
359 template<
typename Scalar>
382 template<
typename Real>
385 typedef std::complex<Real> Cplx;
392 Index n = internal::random<Index>(1,100);
396 SpMatCplx sC1(
n,
n), sC2(
n,
n), sC3(
n,
n);
397 SpRowMatCplx sCR(
n,
n);
398 DenseMatReal dR1(
n,
n);
399 DenseMatCplx dC1(
n,
n), dC2(
n,
n), dC3(
n,
n);
401 initSparse<Real>(
density, dR1, sR1);
402 initSparse<Cplx>(
density, dC1, sC1);
403 initSparse<Cplx>(
density, dC2, sC2);
405 VERIFY_IS_APPROX( sC2 = (sR1 * sC1), dC3 = dR1.template cast<Cplx>() * dC1 );
406 VERIFY_IS_APPROX( sC2 = (sC1 * sR1), dC3 = dC1 * dR1.template cast<Cplx>() );
407 VERIFY_IS_APPROX( sC2 = (sR1.transpose() * sC1), dC3 = dR1.template cast<Cplx>().transpose() * dC1 );
408 VERIFY_IS_APPROX( sC2 = (sC1.transpose() * sR1), dC3 = dC1.transpose() * dR1.template cast<Cplx>() );
409 VERIFY_IS_APPROX( sC2 = (sR1 * sC1.transpose()), dC3 = dR1.template cast<Cplx>() * dC1.transpose() );
410 VERIFY_IS_APPROX( sC2 = (sC1 * sR1.transpose()), dC3 = dC1 * dR1.template cast<Cplx>().transpose() );
411 VERIFY_IS_APPROX( sC2 = (sR1.transpose() * sC1.transpose()), dC3 = dR1.template cast<Cplx>().transpose() * dC1.transpose() );
412 VERIFY_IS_APPROX( sC2 = (sC1.transpose() * sR1.transpose()), dC3 = dC1.transpose() * dR1.template cast<Cplx>().transpose() );
414 VERIFY_IS_APPROX( sCR = (sR1 * sC1), dC3 = dR1.template cast<Cplx>() * dC1 );
415 VERIFY_IS_APPROX( sCR = (sC1 * sR1), dC3 = dC1 * dR1.template cast<Cplx>() );
416 VERIFY_IS_APPROX( sCR = (sR1.transpose() * sC1), dC3 = dR1.template cast<Cplx>().transpose() * dC1 );
417 VERIFY_IS_APPROX( sCR = (sC1.transpose() * sR1), dC3 = dC1.transpose() * dR1.template cast<Cplx>() );
418 VERIFY_IS_APPROX( sCR = (sR1 * sC1.transpose()), dC3 = dR1.template cast<Cplx>() * dC1.transpose() );
419 VERIFY_IS_APPROX( sCR = (sC1 * sR1.transpose()), dC3 = dC1 * dR1.template cast<Cplx>().transpose() );
420 VERIFY_IS_APPROX( sCR = (sR1.transpose() * sC1.transpose()), dC3 = dR1.template cast<Cplx>().transpose() * dC1.transpose() );
421 VERIFY_IS_APPROX( sCR = (sC1.transpose() * sR1.transpose()), dC3 = dC1.transpose() * dR1.template cast<Cplx>().transpose() );
424 VERIFY_IS_APPROX( sC2 = (sR1 * sC1).pruned(), dC3 = dR1.template cast<Cplx>() * dC1 );
425 VERIFY_IS_APPROX( sC2 = (sC1 * sR1).pruned(), dC3 = dC1 * dR1.template cast<Cplx>() );
426 VERIFY_IS_APPROX( sC2 = (sR1.transpose() * sC1).pruned(), dC3 = dR1.template cast<Cplx>().transpose() * dC1 );
427 VERIFY_IS_APPROX( sC2 = (sC1.transpose() * sR1).pruned(), dC3 = dC1.transpose() * dR1.template cast<Cplx>() );
428 VERIFY_IS_APPROX( sC2 = (sR1 * sC1.transpose()).pruned(), dC3 = dR1.template cast<Cplx>() * dC1.transpose() );
429 VERIFY_IS_APPROX( sC2 = (sC1 * sR1.transpose()).pruned(), dC3 = dC1 * dR1.template cast<Cplx>().transpose() );
430 VERIFY_IS_APPROX( sC2 = (sR1.transpose() * sC1.transpose()).pruned(), dC3 = dR1.template cast<Cplx>().transpose() * dC1.transpose() );
431 VERIFY_IS_APPROX( sC2 = (sC1.transpose() * sR1.transpose()).pruned(), dC3 = dC1.transpose() * dR1.template cast<Cplx>().transpose() );
433 VERIFY_IS_APPROX( sCR = (sR1 * sC1).pruned(), dC3 = dR1.template cast<Cplx>() * dC1 );
434 VERIFY_IS_APPROX( sCR = (sC1 * sR1).pruned(), dC3 = dC1 * dR1.template cast<Cplx>() );
435 VERIFY_IS_APPROX( sCR = (sR1.transpose() * sC1).pruned(), dC3 = dR1.template cast<Cplx>().transpose() * dC1 );
436 VERIFY_IS_APPROX( sCR = (sC1.transpose() * sR1).pruned(), dC3 = dC1.transpose() * dR1.template cast<Cplx>() );
437 VERIFY_IS_APPROX( sCR = (sR1 * sC1.transpose()).pruned(), dC3 = dR1.template cast<Cplx>() * dC1.transpose() );
438 VERIFY_IS_APPROX( sCR = (sC1 * sR1.transpose()).pruned(), dC3 = dC1 * dR1.template cast<Cplx>().transpose() );
439 VERIFY_IS_APPROX( sCR = (sR1.transpose() * sC1.transpose()).pruned(), dC3 = dR1.template cast<Cplx>().transpose() * dC1.transpose() );
440 VERIFY_IS_APPROX( sCR = (sC1.transpose() * sR1.transpose()).pruned(), dC3 = dC1.transpose() * dR1.template cast<Cplx>().transpose() );
443 VERIFY_IS_APPROX( dC2 = (sR1 * sC1), dC3 = dR1.template cast<Cplx>() * dC1 );
444 VERIFY_IS_APPROX( dC2 = (sC1 * sR1), dC3 = dC1 * dR1.template cast<Cplx>() );
445 VERIFY_IS_APPROX( dC2 = (sR1.transpose() * sC1), dC3 = dR1.template cast<Cplx>().transpose() * dC1 );
446 VERIFY_IS_APPROX( dC2 = (sC1.transpose() * sR1), dC3 = dC1.transpose() * dR1.template cast<Cplx>() );
447 VERIFY_IS_APPROX( dC2 = (sR1 * sC1.transpose()), dC3 = dR1.template cast<Cplx>() * dC1.transpose() );
448 VERIFY_IS_APPROX( dC2 = (sC1 * sR1.transpose()), dC3 = dC1 * dR1.template cast<Cplx>().transpose() );
449 VERIFY_IS_APPROX( dC2 = (sR1.transpose() * sC1.transpose()), dC3 = dR1.template cast<Cplx>().transpose() * dC1.transpose() );
450 VERIFY_IS_APPROX( dC2 = (sC1.transpose() * sR1.transpose()), dC3 = dC1.transpose() * dR1.template cast<Cplx>().transpose() );
458 VERIFY_IS_APPROX( dC2 = dR1.row(0) * sC1, dC3 = dR1.template cast<Cplx>().row(0) * sC1 );
459 VERIFY_IS_APPROX( dC2 = sR1 * dC1.col(0), dC3 = sR1.template cast<Cplx>() * dC1.col(0) );
460 VERIFY_IS_APPROX( dC2 = dC1.row(0) * sR1, dC3 = dC1.row(0) * sR1.template cast<Cplx>() );
461 VERIFY_IS_APPROX( dC2 = sC1 * dR1.col(0), dC3 = sC1 * dR1.template cast<Cplx>().col(0) );