aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/kronecker_product.cpp
diff options
context:
space:
mode:
authorGravatar Chen-Pang He <jdh8@ms63.hinet.net>2012-10-15 00:21:12 +0800
committerGravatar Chen-Pang He <jdh8@ms63.hinet.net>2012-10-15 00:21:12 +0800
commitc4b83461d97a2520fecc00f647ca2ae9c4bf04d2 (patch)
treee146e77321041b851ae70acd53da527d710645f0 /unsupported/test/kronecker_product.cpp
parentf34db6578a36438c6d229a9be25378cfe6fab38b (diff)
Make kroneckerProduct take two arguments and return an expression, which is more straight-forward.
Diffstat (limited to 'unsupported/test/kronecker_product.cpp')
-rw-r--r--unsupported/test/kronecker_product.cpp61
1 files changed, 26 insertions, 35 deletions
diff --git a/unsupported/test/kronecker_product.cpp b/unsupported/test/kronecker_product.cpp
index a60bd3022..68fde8aa5 100644
--- a/unsupported/test/kronecker_product.cpp
+++ b/unsupported/test/kronecker_product.cpp
@@ -3,6 +3,7 @@
//
// Copyright (C) 2011 Kolja Brix <brix@igpm.rwth-aachen.de>
// Copyright (C) 2011 Andreas Platen <andiplaten@gmx.de>
+// Copyright (C) 2012 Chen-Pang He <jdh8@ms63.hinet.net>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
@@ -89,64 +90,55 @@ void test_kronecker_product()
MatrixXd DM_b(3,2);
SparseMatrix<double> SM_a(2,3);
SparseMatrix<double> SM_b(3,2);
- SM_a.insert(0,0) = DM_a(0,0) = -0.4461540300782201;
- SM_a.insert(0,1) = DM_a(0,1) = -0.8057364375283049;
- SM_a.insert(0,2) = DM_a(0,2) = 0.3896572459516341;
- SM_a.insert(1,0) = DM_a(1,0) = -0.9076572187376921;
- SM_a.insert(1,1) = DM_a(1,1) = 0.6469156566545853;
- SM_a.insert(1,2) = DM_a(1,2) = -0.3658010398782789;
- SM_b.insert(0,0) = DM_b(0,0) = 0.9004440976767099;
- SM_b.insert(0,1) = DM_b(0,1) = -0.2368830858139832;
- SM_b.insert(1,0) = DM_b(1,0) = -0.9311078389941825;
- SM_b.insert(1,1) = DM_b(1,1) = 0.5310335762980047;
- SM_b.insert(2,0) = DM_b(2,0) = -0.1225112806872035;
- SM_b.insert(2,1) = DM_b(2,1) = 0.5903998022741264;
+ SM_a.insert(0,0) = DM_a.coeffRef(0,0) = -0.4461540300782201;
+ SM_a.insert(0,1) = DM_a.coeffRef(0,1) = -0.8057364375283049;
+ SM_a.insert(0,2) = DM_a.coeffRef(0,2) = 0.3896572459516341;
+ SM_a.insert(1,0) = DM_a.coeffRef(1,0) = -0.9076572187376921;
+ SM_a.insert(1,1) = DM_a.coeffRef(1,1) = 0.6469156566545853;
+ SM_a.insert(1,2) = DM_a.coeffRef(1,2) = -0.3658010398782789;
+ SM_b.insert(0,0) = DM_b.coeffRef(0,0) = 0.9004440976767099;
+ SM_b.insert(0,1) = DM_b.coeffRef(0,1) = -0.2368830858139832;
+ SM_b.insert(1,0) = DM_b.coeffRef(1,0) = -0.9311078389941825;
+ SM_b.insert(1,1) = DM_b.coeffRef(1,1) = 0.5310335762980047;
+ SM_b.insert(2,0) = DM_b.coeffRef(2,0) = -0.1225112806872035;
+ SM_b.insert(2,1) = DM_b.coeffRef(2,1) = 0.5903998022741264;
SparseMatrix<double,RowMajor> SM_row_a(SM_a), SM_row_b(SM_b);
// test kroneckerProduct(DM_block,DM,DM_fixedSize)
- Matrix<double, 6, 6> DM_fix_ab;
- DM_fix_ab(0,0)=37.0;
- kroneckerProduct(DM_a.block(0,0,2,3),DM_b,DM_fix_ab);
+ Matrix<double, 6, 6> DM_fix_ab = kroneckerProduct(DM_a.topLeftCorner<2,3>(),DM_b);
CALL_SUBTEST(check_kronecker_product(DM_fix_ab));
// test kroneckerProduct(DM,DM,DM_block)
MatrixXd DM_block_ab(10,15);
- DM_block_ab(0,0)=37.0;
- kroneckerProduct(DM_a,DM_b,DM_block_ab.block(2,5,6,6));
- CALL_SUBTEST(check_kronecker_product(DM_block_ab.block(2,5,6,6)));
+ DM_block_ab.block<6,6>(2,5) = kroneckerProduct(DM_a,DM_b);
+ CALL_SUBTEST(check_kronecker_product(DM_block_ab.block<6,6>(2,5)));
// test kroneckerProduct(DM,DM,DM)
- MatrixXd DM_ab(1,5);
- DM_ab(0,0)=37.0;
- kroneckerProduct(DM_a,DM_b,DM_ab);
+ MatrixXd DM_ab = kroneckerProduct(DM_a,DM_b);
CALL_SUBTEST(check_kronecker_product(DM_ab));
// test kroneckerProduct(SM,DM,SM)
- SparseMatrix<double> SM_ab(1,20);
- SM_ab.insert(0,0)=37.0;
- kroneckerProduct(SM_a,DM_b,SM_ab);
+ SparseMatrix<double> SM_ab = kroneckerProduct(SM_a,DM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab));
- SparseMatrix<double,RowMajor> SM_ab2(10,3);
- SM_ab2.insert(0,0)=37.0;
- kroneckerProduct(SM_a,DM_b,SM_ab2);
+ SparseMatrix<double,RowMajor> SM_ab2 = kroneckerProduct(SM_a,DM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab2));
// test kroneckerProduct(DM,SM,SM)
SM_ab.insert(0,0)=37.0;
- kroneckerProduct(DM_a,SM_b,SM_ab);
+ SM_ab = kroneckerProduct(DM_a,SM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab));
SM_ab2.insert(0,0)=37.0;
- kroneckerProduct(DM_a,SM_b,SM_ab2);
+ SM_ab2 = kroneckerProduct(DM_a,SM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab2));
// test kroneckerProduct(SM,SM,SM)
SM_ab.resize(2,33);
SM_ab.insert(0,0)=37.0;
- kroneckerProduct(SM_a,SM_b,SM_ab);
+ SM_ab = kroneckerProduct(SM_a,SM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab));
SM_ab2.resize(5,11);
SM_ab2.insert(0,0)=37.0;
- kroneckerProduct(SM_a,SM_b,SM_ab2);
+ SM_ab2 = kroneckerProduct(SM_a,SM_b);
CALL_SUBTEST(check_kronecker_product(SM_ab2));
// test kroneckerProduct(SM,SM,SM) with sparse pattern
@@ -163,17 +155,16 @@ void test_kronecker_product()
SM_b.finalize();
SM_ab.resize(1,1);
SM_ab.insert(0,0)=37.0;
- kroneckerProduct(SM_a,SM_b,SM_ab);
+ SM_ab = kroneckerProduct(SM_a,SM_b);
CALL_SUBTEST(check_sparse_kronecker_product(SM_ab));
// test dimension of result of kroneckerProduct(DM,DM,DM)
MatrixXd DM_a2(2,1);
MatrixXd DM_b2(5,4);
- MatrixXd DM_ab2;
- kroneckerProduct(DM_a2,DM_b2,DM_ab2);
+ MatrixXd DM_ab2 = kroneckerProduct(DM_a2,DM_b2);
CALL_SUBTEST(check_dimension(DM_ab2,2*5,1*4));
DM_a2.resize(10,9);
DM_b2.resize(4,8);
- kroneckerProduct(DM_a2,DM_b2,DM_ab2);
+ DM_ab2 = kroneckerProduct(DM_a2,DM_b2);
CALL_SUBTEST(check_dimension(DM_ab2,10*4,9*8));
}