17 return v.stableNorm();
59 Scalar s =
v.array().abs().maxCoeff();
60 return s*(
v/
s).norm();
66 return v.stableNorm();
87 #ifdef EIGEN_VECTORIZE
100 #ifndef EIGEN_VECTORIZE
111 int nbig, ibeta, it, iemin, iemax, iexp;
115 ibeta = std::numeric_limits<Scalar>::radix;
122 if(iemin > 1 - 2*it || 1+it>iemax || (it==2 && ibeta<5)
123 || (it<=4 && ibeta <= 3 ) || it<2)
125 eigen_assert(
false &&
"the algorithm cannot be guaranteed on this computer");
127 iexp = -((1-iemin)/2);
129 iexp = (iemax + 1 - it)/2;
134 iexp = - ((iemax+it)/2);
140 abig = 1.0/eps - 1.0;
141 if (
Scalar(nbig)>abig) nmax = abig;
150 Packet ps2m = internal::pset1<Packet>(s2m);
151 Packet ps1m = internal::pset1<Packet>(s1m);
152 Packet pb2 = internal::pset1<Packet>(
b2);
153 Packet pb1 = internal::pset1<Packet>(
b1);
154 for(
int j=0;
j<
v.size();
j+=
ps)
159 Packet maskBig = internal::plt(pb2,ax);
160 Packet maskSml = internal::plt(ax,pb1);
225 #define BENCH_PERF(NRM) { \
226 float af = 0; double ad = 0; std::complex<float> ac = 0; \
227 Eigen::BenchTimer tf, td, tcf; tf.reset(); td.reset(); tcf.reset();\
228 for (int k=0; k<tries; ++k) { \
230 for (int i=0; i<iters; ++i) { af += NRM(vf); } \
233 for (int k=0; k<tries; ++k) { \
235 for (int i=0; i<iters; ++i) { ad += NRM(vd); } \
243 std::cout << #NRM << "\t" << tf.value() << " " << td.value() << " " << tcf.value() << "\n"; \
248 double yf = basef *
std::abs(internal::random<double>());
249 double yd = based *
std::abs(internal::random<double>());
250 VectorXf vf = VectorXf::Ones(
s) * yf;
251 VectorXd vd = VectorXd::Ones(
s) * yd;
253 std::cout <<
"reference\t" <<
std::sqrt(
double(
s))*yf <<
"\t" <<
std::sqrt(
double(
s))*yd <<
"\n";
267 for (
int i=0;
i<
s; ++
i)
269 vf[
i] =
std::abs(internal::random<double>()) *
std::pow(
double(10), internal::random<int>(ef0,ef1));
270 vd[
i] =
std::abs(internal::random<double>()) *
std::pow(
double(10), internal::random<int>(ed0,ed1));
276 std::cout <<
"blueNorm\t" <<
blueNorm(vf) <<
"\t" <<
blueNorm(vd) <<
"\t" <<
blueNorm(vf.cast<
long double>()) <<
"\t" <<
blueNorm(vd.cast<
long double>()) <<
"\n";
283 int main(
int argc,
char** argv)
287 double y = 1.1345743233455785456788e12 * internal::random<double>();
288 VectorXf
v = VectorXf::Ones(1024) *
y;
292 double basef_ok = 1.1345743233455785456788e15;
293 double based_ok = 1.1345743233455785456788e95;
295 double basef_under = 1.1345743233455785456788e-27;
296 double based_under = 1.1345743233455785456788e-303;
298 double basef_over = 1.1345743233455785456788e+27;
299 double based_over = 1.1345743233455785456788e+302;
301 std::cout.precision(20);
303 std::cerr <<
"\nNo under/overflow:\n";
306 std::cerr <<
"\nUnderflow:\n";
309 std::cerr <<
"\nOverflow:\n";
312 std::cerr <<
"\nVarying (over):\n";
313 for (
int k=0; k<1; ++k)
319 std::cerr <<
"\nVarying (under):\n";
320 for (
int k=0; k<1; ++k)
327 std::cout.precision(4);
328 int s1 = 1024*1024*32;
329 std::cerr <<
"Performance (out of cache, " << s1 <<
"):\n";
332 VectorXf vf = VectorXf::Random(s1) *
y;
333 VectorXd vd = VectorXd::Random(s1) *
y;
334 VectorXcf vcf = VectorXcf::Random(s1) *
y;
345 std::cerr <<
"\nPerformance (in cache, " << 512 <<
"):\n";
348 VectorXf vf = VectorXf::Random(512) *
y;
349 VectorXd vd = VectorXd::Random(512) *
y;
350 VectorXcf vcf = VectorXcf::Random(512) *
y;