| 171 | } |
| 172 | |
| 173 | template<typename MatrixType> void cwise_min_max(const MatrixType& m) |
| 174 | { |
| 175 | typedef typename MatrixType::Index Index; |
| 176 | typedef typename MatrixType::Scalar Scalar; |
| 177 | |
| 178 | Index rows = m.rows(); |
| 179 | Index cols = m.cols(); |
| 180 | |
| 181 | MatrixType m1 = MatrixType::Random(rows, cols); |
| 182 | |
| 183 | // min/max with array |
| 184 | Scalar maxM1 = m1.maxCoeff(); |
| 185 | Scalar minM1 = m1.minCoeff(); |
| 186 | |
| 187 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, minM1), m1.cwiseMin(MatrixType::Constant(rows,cols, minM1))); |
| 188 | VERIFY_IS_APPROX(m1, m1.cwiseMin(MatrixType::Constant(rows,cols, maxM1))); |
| 189 | |
| 190 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, maxM1), m1.cwiseMax(MatrixType::Constant(rows,cols, maxM1))); |
| 191 | VERIFY_IS_APPROX(m1, m1.cwiseMax(MatrixType::Constant(rows,cols, minM1))); |
| 192 | |
| 193 | // min/max with scalar input |
| 194 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, minM1), m1.cwiseMin( minM1)); |
| 195 | VERIFY_IS_APPROX(m1, m1.cwiseMin(maxM1)); |
| 196 | VERIFY_IS_APPROX(-m1, (-m1).cwiseMin(-minM1)); |
| 197 | VERIFY_IS_APPROX(-m1.array(), ((-m1).array().min)( -minM1)); |
| 198 | |
| 199 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, maxM1), m1.cwiseMax( maxM1)); |
| 200 | VERIFY_IS_APPROX(m1, m1.cwiseMax(minM1)); |
| 201 | VERIFY_IS_APPROX(-m1, (-m1).cwiseMax(-maxM1)); |
| 202 | VERIFY_IS_APPROX(-m1.array(), ((-m1).array().max)(-maxM1)); |
| 203 | |
| 204 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, minM1).array(), (m1.array().min)( minM1)); |
| 205 | VERIFY_IS_APPROX(m1.array(), (m1.array().min)( maxM1)); |
| 206 | |
| 207 | VERIFY_IS_APPROX(MatrixType::Constant(rows,cols, maxM1).array(), (m1.array().max)( maxM1)); |
| 208 | VERIFY_IS_APPROX(m1.array(), (m1.array().max)( minM1)); |
| 209 | |
| 210 | } |
| 211 | |
| 212 | template<typename MatrixTraits> void resize(const MatrixTraits& t) |
| 213 | { |