| 148 | } |
| 149 | |
| 150 | template<typename VectorType> void lpNorm(const VectorType& v) |
| 151 | { |
| 152 | using std::sqrt; |
| 153 | typedef typename VectorType::RealScalar RealScalar; |
| 154 | VectorType u = VectorType::Random(v.size()); |
| 155 | |
| 156 | if(v.size()==0) |
| 157 | { |
| 158 | VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), RealScalar(0)); |
| 159 | VERIFY_IS_APPROX(u.template lpNorm<1>(), RealScalar(0)); |
| 160 | VERIFY_IS_APPROX(u.template lpNorm<2>(), RealScalar(0)); |
| 161 | VERIFY_IS_APPROX(u.template lpNorm<5>(), RealScalar(0)); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwiseAbs().maxCoeff()); |
| 166 | } |
| 167 | |
| 168 | VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwiseAbs().sum()); |
| 169 | VERIFY_IS_APPROX(u.template lpNorm<2>(), sqrt(u.array().abs().square().sum())); |
| 170 | VERIFY_IS_APPROX(numext::pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.array().abs().pow(5).sum()); |
| 171 | } |
| 172 | |
| 173 | template<typename MatrixType> void cwise_min_max(const MatrixType& m) |
| 174 | { |