13 #ifdef EIGEN_TEST_PART_1 16 #include <Eigen/SparseExtra> 17 #include <Eigen/KroneckerProduct> 19 template<
typename MatrixType>
27 template<
typename MatrixType>
28 void check_kronecker_product(
const MatrixType& ab)
72 template<
typename MatrixType>
73 void check_sparse_kronecker_product(
const MatrixType& ab)
91 Matrix<double, 2, 3> DM_a;
92 SparseMatrix<double> SM_a(2,3);
93 SM_a.insert(0,0) = DM_a.coeffRef(0,0) = -0.4461540300782201;
94 SM_a.insert(0,1) = DM_a.coeffRef(0,1) = -0.8057364375283049;
95 SM_a.insert(0,2) = DM_a.coeffRef(0,2) = 0.3896572459516341;
96 SM_a.insert(1,0) = DM_a.coeffRef(1,0) = -0.9076572187376921;
97 SM_a.insert(1,1) = DM_a.coeffRef(1,1) = 0.6469156566545853;
98 SM_a.insert(1,2) = DM_a.coeffRef(1,2) = -0.3658010398782789;
101 SparseMatrix<double> SM_b(3,2);
102 SM_b.insert(0,0) = DM_b.coeffRef(0,0) = 0.9004440976767099;
103 SM_b.insert(0,1) = DM_b.coeffRef(0,1) = -0.2368830858139832;
104 SM_b.insert(1,0) = DM_b.coeffRef(1,0) = -0.9311078389941825;
105 SM_b.insert(1,1) = DM_b.coeffRef(1,1) = 0.5310335762980047;
106 SM_b.insert(2,0) = DM_b.coeffRef(2,0) = -0.1225112806872035;
107 SM_b.insert(2,1) = DM_b.coeffRef(2,1) = 0.5903998022741264;
109 SparseMatrix<double,RowMajor> SM_row_a(SM_a), SM_row_b(SM_b);
112 Matrix<double, 6, 6> DM_fix_ab =
kroneckerProduct(DM_a.topLeftCorner<2,3>(),DM_b);
117 for(
int i=0;
i<DM_fix_ab.rows();++
i)
118 for(
int j=0;
j<DM_fix_ab.cols();++
j)
122 MatrixXd DM_block_ab(10,15);
124 CALL_SUBTEST(check_kronecker_product(DM_block_ab.block<6,6>(2,5)));
140 SM_ab.insert(0,0)=37.0;
144 SM_ab2.insert(0,0)=37.0;
151 SM_ab.insert(0,0)=37.0;
155 SM_ab2.insert(0,0)=37.0;
163 SM_a.resizeNonZeros(0);
164 SM_b.resizeNonZeros(0);
165 SM_a.insert(1,0) = -0.1;
166 SM_a.insert(0,3) = -0.2;
167 SM_a.insert(2,4) = 0.3;
170 SM_b.insert(0,0) = 0.4;
171 SM_b.insert(2,1) = -0.5;
174 SM_ab.insert(0,0)=37.0;
190 double density = Eigen::internal::random<double>(0.01,0.5);
191 int ra = Eigen::internal::random<int>(1,50);
192 int ca = Eigen::internal::random<int>(1,50);
193 int rb = Eigen::internal::random<int>(1,50);
194 int cb = Eigen::internal::random<int>(1,50);
195 SparseMatrix<float,ColMajor> sA(ra,ca), sB(rb,cb), sC;
196 SparseMatrix<float,RowMajor> sC2;
197 MatrixXf dA(ra,ca), dB(rb,cb), dC;
237 #ifdef EIGEN_TEST_PART_2 241 #include <Eigen/KroneckerProduct> 245 MatrixXd
a(2,2),
b(3,3),
c;
#define VERIFY_IS_APPROX(a, b)
#define VERIFY_IS_EQUAL(a, b)
#define EIGEN_DECLARE_TEST(X)
void initSparse(double density, Matrix< Scalar, Dynamic, Dynamic, Opt1 > &refMat, SparseMatrix< Scalar, Opt2, StorageIndex > &sparseMat, int flags=0, std::vector< Matrix< StorageIndex, 2, 1 > > *zeroCoords=0, std::vector< Matrix< StorageIndex, 2, 1 > > *nonzeroCoords=0)
#define CALL_SUBTEST(FUNC)
KroneckerProduct< A, B > kroneckerProduct(const MatrixBase< A > &a, const MatrixBase< B > &b)