mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
optimize setConstant, setZero
This commit is contained in:
@@ -73,6 +73,21 @@ void block(const MatrixType& m) {
|
||||
|
||||
block_real_only(m1, r1, r2, c1, c1, s1);
|
||||
|
||||
// test fill logic with innerpanel and non-innerpanel blocks
|
||||
m1.row(r1).setConstant(s1);
|
||||
VERIFY_IS_CWISE_EQUAL(m1.row(r1), DynamicVectorType::Constant(cols, s1).transpose());
|
||||
m1 = m1_copy;
|
||||
m1.col(c1).setConstant(s1);
|
||||
VERIFY_IS_CWISE_EQUAL(m1.col(c1), DynamicVectorType::Constant(rows, s1));
|
||||
m1 = m1_copy;
|
||||
// test setZero logic with innerpanel and non-innerpanel blocks
|
||||
m1.row(r1).setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(m1.row(r1), DynamicVectorType::Zero(cols).transpose());
|
||||
m1 = m1_copy;
|
||||
m1.col(c1).setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(m1.col(c1), DynamicVectorType::Zero(rows));
|
||||
m1 = m1_copy;
|
||||
|
||||
// check row() and col()
|
||||
VERIFY_IS_EQUAL(m1.col(c1).transpose(), m1.transpose().row(c1));
|
||||
// check operator(), both constant and non-constant, on row() and col()
|
||||
|
||||
@@ -75,8 +75,23 @@ void map_class_matrix(const MatrixType& m) {
|
||||
Map<MatrixType> map4(array4, rows, cols);
|
||||
|
||||
VERIFY_IS_EQUAL(map1, MatrixType::Ones(rows, cols));
|
||||
map1.setConstant(s1);
|
||||
VERIFY_IS_EQUAL(map1, MatrixType::Constant(rows, cols, s1));
|
||||
map1.setZero();
|
||||
VERIFY_IS_EQUAL(map1, MatrixType::Zero(rows, cols));
|
||||
|
||||
VERIFY_IS_EQUAL(map2, MatrixType::Ones(rows, cols));
|
||||
map2.setConstant(s1);
|
||||
VERIFY_IS_EQUAL(map2, MatrixType::Constant(rows, cols, s1));
|
||||
map2.setZero();
|
||||
VERIFY_IS_EQUAL(map2, MatrixType::Zero(rows, cols));
|
||||
|
||||
VERIFY_IS_EQUAL(map3, MatrixType::Ones(rows, cols));
|
||||
map3.setConstant(s1);
|
||||
VERIFY_IS_EQUAL(map3, MatrixType::Constant(rows, cols, s1));
|
||||
map3.setZero();
|
||||
VERIFY_IS_EQUAL(map3, MatrixType::Zero(rows, cols));
|
||||
|
||||
map1 = MatrixType::Random(rows, cols);
|
||||
map2 = map1;
|
||||
map3 = map1;
|
||||
|
||||
@@ -94,6 +94,8 @@ void map_class_matrix(const MatrixType& _m) {
|
||||
VERIFY_IS_APPROX(s1 * map, s1 * m);
|
||||
map *= s1;
|
||||
VERIFY_IS_APPROX(map, s1 * m);
|
||||
map.setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(map, MatrixType::Zero(rows, cols));
|
||||
}
|
||||
|
||||
// test no inner stride and an outer stride of +4. This is quite important as for fixed-size matrices,
|
||||
@@ -118,6 +120,8 @@ void map_class_matrix(const MatrixType& _m) {
|
||||
VERIFY_IS_APPROX(s1 * map, s1 * m);
|
||||
map *= s1;
|
||||
VERIFY_IS_APPROX(map, s1 * m);
|
||||
map.setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(map, MatrixType::Zero(rows, cols));
|
||||
}
|
||||
|
||||
// test both inner stride and outer stride
|
||||
@@ -138,6 +142,8 @@ void map_class_matrix(const MatrixType& _m) {
|
||||
VERIFY_IS_APPROX(s1 * map, s1 * m);
|
||||
map *= s1;
|
||||
VERIFY_IS_APPROX(map, s1 * m);
|
||||
map.setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(map, MatrixType::Zero(rows, cols));
|
||||
}
|
||||
|
||||
// test inner stride and no outer stride
|
||||
@@ -156,6 +162,8 @@ void map_class_matrix(const MatrixType& _m) {
|
||||
VERIFY_IS_APPROX(s1 * map, s1 * m);
|
||||
map *= s1;
|
||||
VERIFY_IS_APPROX(map, s1 * m);
|
||||
map.setZero();
|
||||
VERIFY_IS_CWISE_EQUAL(map, MatrixType::Zero(rows, cols));
|
||||
}
|
||||
|
||||
// test negative strides
|
||||
|
||||
Reference in New Issue
Block a user