2009-07-16 20:20:36 +08:00
|
|
|
#include <typeinfo>
|
2010-07-09 09:59:36 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <Eigen/Core>
|
2009-07-16 17:33:56 +08:00
|
|
|
#include "BenchTimer.h"
|
|
|
|
using namespace Eigen;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
template<typename T>
|
2014-09-11 16:27:46 +08:00
|
|
|
EIGEN_DONT_INLINE typename T::Scalar sqsumNorm(T& v)
|
2009-07-16 17:33:56 +08:00
|
|
|
{
|
|
|
|
return v.norm();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-09-11 16:27:46 +08:00
|
|
|
EIGEN_DONT_INLINE typename T::Scalar stableNorm(T& v)
|
|
|
|
{
|
|
|
|
return v.stableNorm();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar hypotNorm(T& v)
|
2009-07-16 17:33:56 +08:00
|
|
|
{
|
2009-07-17 22:22:39 +08:00
|
|
|
return v.hypotNorm();
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-09-11 16:27:46 +08:00
|
|
|
EIGEN_DONT_INLINE typename T::Scalar blueNorm(T& v)
|
2009-07-16 17:33:56 +08:00
|
|
|
{
|
|
|
|
return v.blueNorm();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar lapackNorm(T& v)
|
|
|
|
{
|
|
|
|
typedef typename T::Scalar Scalar;
|
|
|
|
int n = v.size();
|
2009-07-16 22:21:26 +08:00
|
|
|
Scalar scale = 0;
|
|
|
|
Scalar ssq = 1;
|
2009-07-16 17:33:56 +08:00
|
|
|
for (int i=0;i<n;++i)
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
Scalar ax = std::abs(v.coeff(i));
|
2009-07-16 22:21:26 +08:00
|
|
|
if (scale >= ax)
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
ssq += numext::abs2(ax/scale);
|
2009-07-16 22:21:26 +08:00
|
|
|
}
|
|
|
|
else
|
2009-07-16 17:33:56 +08:00
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
ssq = Scalar(1) + ssq * numext::abs2(scale/ax);
|
2009-07-16 17:33:56 +08:00
|
|
|
scale = ax;
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 22:53:51 +08:00
|
|
|
return scale * std::sqrt(ssq);
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
2009-07-16 22:21:26 +08:00
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar twopassNorm(T& v)
|
|
|
|
{
|
|
|
|
typedef typename T::Scalar Scalar;
|
2014-02-13 22:53:51 +08:00
|
|
|
Scalar s = v.array().abs().maxCoeff();
|
2009-07-16 22:21:26 +08:00
|
|
|
return s*(v/s).norm();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar bl2passNorm(T& v)
|
|
|
|
{
|
2009-07-17 22:22:39 +08:00
|
|
|
return v.stableNorm();
|
2009-07-16 22:21:26 +08:00
|
|
|
}
|
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar divacNorm(T& v)
|
|
|
|
{
|
|
|
|
int n =v.size() / 2;
|
|
|
|
for (int i=0;i<n;++i)
|
|
|
|
v(i) = v(2*i)*v(2*i) + v(2*i+1)*v(2*i+1);
|
|
|
|
n = n/2;
|
|
|
|
while (n>0)
|
|
|
|
{
|
|
|
|
for (int i=0;i<n;++i)
|
|
|
|
v(i) = v(2*i) + v(2*i+1);
|
|
|
|
n = n/2;
|
|
|
|
}
|
2014-02-13 22:53:51 +08:00
|
|
|
return std::sqrt(v(0));
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
2014-02-13 22:53:51 +08:00
|
|
|
namespace Eigen {
|
|
|
|
namespace internal {
|
2009-07-16 20:20:36 +08:00
|
|
|
#ifdef EIGEN_VECTORIZE
|
2014-02-13 22:53:51 +08:00
|
|
|
Packet4f plt(const Packet4f& a, Packet4f& b) { return _mm_cmplt_ps(a,b); }
|
|
|
|
Packet2d plt(const Packet2d& a, Packet2d& b) { return _mm_cmplt_pd(a,b); }
|
2009-07-16 17:33:56 +08:00
|
|
|
|
2014-02-13 22:53:51 +08:00
|
|
|
Packet4f pandnot(const Packet4f& a, Packet4f& b) { return _mm_andnot_ps(a,b); }
|
|
|
|
Packet2d pandnot(const Packet2d& a, Packet2d& b) { return _mm_andnot_pd(a,b); }
|
2009-07-16 20:20:36 +08:00
|
|
|
#endif
|
2014-02-13 22:53:51 +08:00
|
|
|
}
|
|
|
|
}
|
2009-07-16 17:33:56 +08:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
EIGEN_DONT_INLINE typename T::Scalar pblueNorm(const T& v)
|
|
|
|
{
|
2009-07-16 20:20:36 +08:00
|
|
|
#ifndef EIGEN_VECTORIZE
|
|
|
|
return v.blueNorm();
|
|
|
|
#else
|
2009-07-16 17:33:56 +08:00
|
|
|
typedef typename T::Scalar Scalar;
|
|
|
|
|
2009-07-16 20:20:36 +08:00
|
|
|
static int nmax = 0;
|
2009-07-16 17:33:56 +08:00
|
|
|
static Scalar b1, b2, s1m, s2m, overfl, rbig, relerr;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if(nmax <= 0)
|
|
|
|
{
|
|
|
|
int nbig, ibeta, it, iemin, iemax, iexp;
|
|
|
|
Scalar abig, eps;
|
|
|
|
|
|
|
|
nbig = std::numeric_limits<int>::max(); // largest integer
|
2009-07-16 20:20:36 +08:00
|
|
|
ibeta = std::numeric_limits<Scalar>::radix; //NumTraits<Scalar>::Base; // base for floating-point numbers
|
|
|
|
it = std::numeric_limits<Scalar>::digits; //NumTraits<Scalar>::Mantissa; // number of base-beta digits in mantissa
|
2009-07-16 17:33:56 +08:00
|
|
|
iemin = std::numeric_limits<Scalar>::min_exponent; // minimum exponent
|
|
|
|
iemax = std::numeric_limits<Scalar>::max_exponent; // maximum exponent
|
|
|
|
rbig = std::numeric_limits<Scalar>::max(); // largest floating-point number
|
|
|
|
|
|
|
|
// Check the basic machine-dependent constants.
|
|
|
|
if(iemin > 1 - 2*it || 1+it>iemax || (it==2 && ibeta<5)
|
|
|
|
|| (it<=4 && ibeta <= 3 ) || it<2)
|
|
|
|
{
|
2010-10-25 22:15:22 +08:00
|
|
|
eigen_assert(false && "the algorithm cannot be guaranteed on this computer");
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
iexp = -((1-iemin)/2);
|
2009-07-16 20:20:36 +08:00
|
|
|
b1 = std::pow(ibeta, iexp); // lower boundary of midrange
|
2009-07-16 17:33:56 +08:00
|
|
|
iexp = (iemax + 1 - it)/2;
|
2009-07-16 20:20:36 +08:00
|
|
|
b2 = std::pow(ibeta,iexp); // upper boundary of midrange
|
2009-07-16 17:33:56 +08:00
|
|
|
|
|
|
|
iexp = (2-iemin)/2;
|
2009-07-16 20:20:36 +08:00
|
|
|
s1m = std::pow(ibeta,iexp); // scaling factor for lower range
|
2009-07-16 17:33:56 +08:00
|
|
|
iexp = - ((iemax+it)/2);
|
2009-07-16 20:20:36 +08:00
|
|
|
s2m = std::pow(ibeta,iexp); // scaling factor for upper range
|
2009-07-16 17:33:56 +08:00
|
|
|
|
|
|
|
overfl = rbig*s2m; // overfow boundary for abig
|
2009-07-16 20:20:36 +08:00
|
|
|
eps = std::pow(ibeta, 1-it);
|
2014-02-13 22:53:51 +08:00
|
|
|
relerr = std::sqrt(eps); // tolerance for neglecting asml
|
2009-07-16 17:33:56 +08:00
|
|
|
abig = 1.0/eps - 1.0;
|
|
|
|
if (Scalar(nbig)>abig) nmax = abig; // largest safe n
|
|
|
|
else nmax = nbig;
|
|
|
|
}
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2010-10-25 22:15:22 +08:00
|
|
|
typedef typename internal::packet_traits<Scalar>::type Packet;
|
|
|
|
const int ps = internal::packet_traits<Scalar>::size;
|
2014-02-13 22:53:51 +08:00
|
|
|
Packet pasml = internal::pset1<Packet>(Scalar(0));
|
|
|
|
Packet pamed = internal::pset1<Packet>(Scalar(0));
|
|
|
|
Packet pabig = internal::pset1<Packet>(Scalar(0));
|
|
|
|
Packet ps2m = internal::pset1<Packet>(s2m);
|
|
|
|
Packet ps1m = internal::pset1<Packet>(s1m);
|
|
|
|
Packet pb2 = internal::pset1<Packet>(b2);
|
|
|
|
Packet pb1 = internal::pset1<Packet>(b1);
|
2009-07-16 17:33:56 +08:00
|
|
|
for(int j=0; j<v.size(); j+=ps)
|
|
|
|
{
|
2010-10-25 22:15:22 +08:00
|
|
|
Packet ax = internal::pabs(v.template packet<Aligned>(j));
|
|
|
|
Packet ax_s2m = internal::pmul(ax,ps2m);
|
|
|
|
Packet ax_s1m = internal::pmul(ax,ps1m);
|
|
|
|
Packet maskBig = internal::plt(pb2,ax);
|
|
|
|
Packet maskSml = internal::plt(ax,pb1);
|
|
|
|
|
|
|
|
// Packet maskMed = internal::pand(maskSml,maskBig);
|
|
|
|
// Packet scale = internal::pset1(Scalar(0));
|
|
|
|
// scale = internal::por(scale, internal::pand(maskBig,ps2m));
|
|
|
|
// scale = internal::por(scale, internal::pand(maskSml,ps1m));
|
|
|
|
// scale = internal::por(scale, internal::pandnot(internal::pset1(Scalar(1)),maskMed));
|
|
|
|
// ax = internal::pmul(ax,scale);
|
|
|
|
// ax = internal::pmul(ax,ax);
|
|
|
|
// pabig = internal::padd(pabig, internal::pand(maskBig, ax));
|
|
|
|
// pasml = internal::padd(pasml, internal::pand(maskSml, ax));
|
|
|
|
// pamed = internal::padd(pamed, internal::pandnot(ax,maskMed));
|
|
|
|
|
|
|
|
|
|
|
|
pabig = internal::padd(pabig, internal::pand(maskBig, internal::pmul(ax_s2m,ax_s2m)));
|
|
|
|
pasml = internal::padd(pasml, internal::pand(maskSml, internal::pmul(ax_s1m,ax_s1m)));
|
|
|
|
pamed = internal::padd(pamed, internal::pandnot(internal::pmul(ax,ax),internal::pand(maskSml,maskBig)));
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
2010-10-25 22:15:22 +08:00
|
|
|
Scalar abig = internal::predux(pabig);
|
|
|
|
Scalar asml = internal::predux(pasml);
|
|
|
|
Scalar amed = internal::predux(pamed);
|
2009-07-16 17:33:56 +08:00
|
|
|
if(abig > Scalar(0))
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
abig = std::sqrt(abig);
|
2009-07-16 17:33:56 +08:00
|
|
|
if(abig > overfl)
|
|
|
|
{
|
2010-10-25 22:15:22 +08:00
|
|
|
eigen_assert(false && "overflow");
|
2009-07-16 17:33:56 +08:00
|
|
|
return rbig;
|
|
|
|
}
|
|
|
|
if(amed > Scalar(0))
|
|
|
|
{
|
|
|
|
abig = abig/s2m;
|
2014-02-13 22:53:51 +08:00
|
|
|
amed = std::sqrt(amed);
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return abig/s2m;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(asml > Scalar(0))
|
|
|
|
{
|
|
|
|
if (amed > Scalar(0))
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
abig = std::sqrt(amed);
|
|
|
|
amed = std::sqrt(asml) / s1m;
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
return std::sqrt(asml)/s1m;
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
return std::sqrt(amed);
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
asml = std::min(abig, amed);
|
|
|
|
abig = std::max(abig, amed);
|
|
|
|
if(asml <= abig*relerr)
|
|
|
|
return abig;
|
|
|
|
else
|
2014-02-13 22:53:51 +08:00
|
|
|
return abig * std::sqrt(Scalar(1) + numext::abs2(asml/abig));
|
2009-07-16 20:20:36 +08:00
|
|
|
#endif
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BENCH_PERF(NRM) { \
|
2014-09-11 16:27:46 +08:00
|
|
|
float af = 0; double ad = 0; std::complex<float> ac = 0; \
|
2009-07-17 22:22:39 +08:00
|
|
|
Eigen::BenchTimer tf, td, tcf; tf.reset(); td.reset(); tcf.reset();\
|
2009-07-16 17:33:56 +08:00
|
|
|
for (int k=0; k<tries; ++k) { \
|
|
|
|
tf.start(); \
|
2014-09-11 16:27:46 +08:00
|
|
|
for (int i=0; i<iters; ++i) { af += NRM(vf); } \
|
2009-07-16 17:33:56 +08:00
|
|
|
tf.stop(); \
|
|
|
|
} \
|
|
|
|
for (int k=0; k<tries; ++k) { \
|
|
|
|
td.start(); \
|
2014-09-11 16:27:46 +08:00
|
|
|
for (int i=0; i<iters; ++i) { ad += NRM(vd); } \
|
2009-07-16 17:33:56 +08:00
|
|
|
td.stop(); \
|
|
|
|
} \
|
2014-02-13 22:53:51 +08:00
|
|
|
/*for (int k=0; k<std::max(1,tries/3); ++k) { \
|
2009-07-17 22:22:39 +08:00
|
|
|
tcf.start(); \
|
2014-09-11 16:27:46 +08:00
|
|
|
for (int i=0; i<iters; ++i) { ac += NRM(vcf); } \
|
2009-07-17 22:22:39 +08:00
|
|
|
tcf.stop(); \
|
2014-02-13 22:53:51 +08:00
|
|
|
} */\
|
2009-07-17 22:22:39 +08:00
|
|
|
std::cout << #NRM << "\t" << tf.value() << " " << td.value() << " " << tcf.value() << "\n"; \
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void check_accuracy(double basef, double based, int s)
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
double yf = basef * std::abs(internal::random<double>());
|
|
|
|
double yd = based * std::abs(internal::random<double>());
|
2009-07-16 17:33:56 +08:00
|
|
|
VectorXf vf = VectorXf::Ones(s) * yf;
|
|
|
|
VectorXd vd = VectorXd::Ones(s) * yd;
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2014-02-13 22:53:51 +08:00
|
|
|
std::cout << "reference\t" << std::sqrt(double(s))*yf << "\t" << std::sqrt(double(s))*yd << "\n";
|
2009-07-16 17:33:56 +08:00
|
|
|
std::cout << "sqsumNorm\t" << sqsumNorm(vf) << "\t" << sqsumNorm(vd) << "\n";
|
|
|
|
std::cout << "hypotNorm\t" << hypotNorm(vf) << "\t" << hypotNorm(vd) << "\n";
|
|
|
|
std::cout << "blueNorm\t" << blueNorm(vf) << "\t" << blueNorm(vd) << "\n";
|
|
|
|
std::cout << "pblueNorm\t" << pblueNorm(vf) << "\t" << pblueNorm(vd) << "\n";
|
|
|
|
std::cout << "lapackNorm\t" << lapackNorm(vf) << "\t" << lapackNorm(vd) << "\n";
|
2009-07-16 22:21:26 +08:00
|
|
|
std::cout << "twopassNorm\t" << twopassNorm(vf) << "\t" << twopassNorm(vd) << "\n";
|
|
|
|
std::cout << "bl2passNorm\t" << bl2passNorm(vf) << "\t" << bl2passNorm(vd) << "\n";
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
2009-07-16 20:20:36 +08:00
|
|
|
void check_accuracy_var(int ef0, int ef1, int ed0, int ed1, int s)
|
|
|
|
{
|
|
|
|
VectorXf vf(s);
|
|
|
|
VectorXd vd(s);
|
|
|
|
for (int i=0; i<s; ++i)
|
|
|
|
{
|
2014-02-13 22:53:51 +08:00
|
|
|
vf[i] = std::abs(internal::random<double>()) * std::pow(double(10), internal::random<int>(ef0,ef1));
|
|
|
|
vd[i] = std::abs(internal::random<double>()) * std::pow(double(10), internal::random<int>(ed0,ed1));
|
2009-07-16 20:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-25 22:15:22 +08:00
|
|
|
//std::cout << "reference\t" << internal::sqrt(double(s))*yf << "\t" << internal::sqrt(double(s))*yd << "\n";
|
2009-07-16 20:20:36 +08:00
|
|
|
std::cout << "sqsumNorm\t" << sqsumNorm(vf) << "\t" << sqsumNorm(vd) << "\t" << sqsumNorm(vf.cast<long double>()) << "\t" << sqsumNorm(vd.cast<long double>()) << "\n";
|
|
|
|
std::cout << "hypotNorm\t" << hypotNorm(vf) << "\t" << hypotNorm(vd) << "\t" << hypotNorm(vf.cast<long double>()) << "\t" << hypotNorm(vd.cast<long double>()) << "\n";
|
|
|
|
std::cout << "blueNorm\t" << blueNorm(vf) << "\t" << blueNorm(vd) << "\t" << blueNorm(vf.cast<long double>()) << "\t" << blueNorm(vd.cast<long double>()) << "\n";
|
|
|
|
std::cout << "pblueNorm\t" << pblueNorm(vf) << "\t" << pblueNorm(vd) << "\t" << blueNorm(vf.cast<long double>()) << "\t" << blueNorm(vd.cast<long double>()) << "\n";
|
|
|
|
std::cout << "lapackNorm\t" << lapackNorm(vf) << "\t" << lapackNorm(vd) << "\t" << lapackNorm(vf.cast<long double>()) << "\t" << lapackNorm(vd.cast<long double>()) << "\n";
|
2009-07-16 22:21:26 +08:00
|
|
|
std::cout << "twopassNorm\t" << twopassNorm(vf) << "\t" << twopassNorm(vd) << "\t" << twopassNorm(vf.cast<long double>()) << "\t" << twopassNorm(vd.cast<long double>()) << "\n";
|
2009-07-17 22:22:39 +08:00
|
|
|
// std::cout << "bl2passNorm\t" << bl2passNorm(vf) << "\t" << bl2passNorm(vd) << "\t" << bl2passNorm(vf.cast<long double>()) << "\t" << bl2passNorm(vd.cast<long double>()) << "\n";
|
2009-07-16 20:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
2009-07-16 17:33:56 +08:00
|
|
|
{
|
2009-07-16 22:21:26 +08:00
|
|
|
int tries = 10;
|
2009-07-16 17:33:56 +08:00
|
|
|
int iters = 100000;
|
2010-10-25 22:15:22 +08:00
|
|
|
double y = 1.1345743233455785456788e12 * internal::random<double>();
|
2009-07-16 17:33:56 +08:00
|
|
|
VectorXf v = VectorXf::Ones(1024) * y;
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2009-07-17 22:22:39 +08:00
|
|
|
// return 0;
|
2009-07-16 17:33:56 +08:00
|
|
|
int s = 10000;
|
2009-07-16 20:20:36 +08:00
|
|
|
double basef_ok = 1.1345743233455785456788e15;
|
|
|
|
double based_ok = 1.1345743233455785456788e95;
|
|
|
|
|
|
|
|
double basef_under = 1.1345743233455785456788e-27;
|
2009-07-16 22:21:26 +08:00
|
|
|
double based_under = 1.1345743233455785456788e-303;
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
double basef_over = 1.1345743233455785456788e+27;
|
2009-07-16 20:20:36 +08:00
|
|
|
double based_over = 1.1345743233455785456788e+302;
|
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
std::cout.precision(20);
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
std::cerr << "\nNo under/overflow:\n";
|
|
|
|
check_accuracy(basef_ok, based_ok, s);
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
std::cerr << "\nUnderflow:\n";
|
2009-07-17 22:22:39 +08:00
|
|
|
check_accuracy(basef_under, based_under, s);
|
2009-07-16 20:20:36 +08:00
|
|
|
|
2009-07-16 17:33:56 +08:00
|
|
|
std::cerr << "\nOverflow:\n";
|
|
|
|
check_accuracy(basef_over, based_over, s);
|
2009-07-16 20:20:36 +08:00
|
|
|
|
|
|
|
std::cerr << "\nVarying (over):\n";
|
2009-07-16 22:21:26 +08:00
|
|
|
for (int k=0; k<1; ++k)
|
2009-07-16 20:20:36 +08:00
|
|
|
{
|
|
|
|
check_accuracy_var(20,27,190,302,s);
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
2009-07-16 22:21:26 +08:00
|
|
|
|
|
|
|
std::cerr << "\nVarying (under):\n";
|
|
|
|
for (int k=0; k<1; ++k)
|
|
|
|
{
|
|
|
|
check_accuracy_var(-27,20,-302,-190,s);
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
2009-07-17 22:22:39 +08:00
|
|
|
|
2014-09-11 16:27:46 +08:00
|
|
|
y = 1;
|
2009-07-17 22:22:39 +08:00
|
|
|
std::cout.precision(4);
|
2014-09-11 16:27:46 +08:00
|
|
|
int s1 = 1024*1024*32;
|
|
|
|
std::cerr << "Performance (out of cache, " << s1 << "):\n";
|
2009-07-17 22:22:39 +08:00
|
|
|
{
|
|
|
|
int iters = 1;
|
2014-09-11 16:27:46 +08:00
|
|
|
VectorXf vf = VectorXf::Random(s1) * y;
|
|
|
|
VectorXd vd = VectorXd::Random(s1) * y;
|
|
|
|
VectorXcf vcf = VectorXcf::Random(s1) * y;
|
2009-07-17 22:22:39 +08:00
|
|
|
BENCH_PERF(sqsumNorm);
|
2014-09-11 16:27:46 +08:00
|
|
|
BENCH_PERF(stableNorm);
|
2009-07-17 22:22:39 +08:00
|
|
|
BENCH_PERF(blueNorm);
|
2014-02-13 22:53:51 +08:00
|
|
|
BENCH_PERF(pblueNorm);
|
|
|
|
BENCH_PERF(lapackNorm);
|
|
|
|
BENCH_PERF(hypotNorm);
|
|
|
|
BENCH_PERF(twopassNorm);
|
2009-07-17 22:22:39 +08:00
|
|
|
BENCH_PERF(bl2passNorm);
|
|
|
|
}
|
|
|
|
|
2014-09-11 16:27:46 +08:00
|
|
|
std::cerr << "\nPerformance (in cache, " << 512 << "):\n";
|
2009-07-17 22:22:39 +08:00
|
|
|
{
|
|
|
|
int iters = 100000;
|
|
|
|
VectorXf vf = VectorXf::Random(512) * y;
|
|
|
|
VectorXd vd = VectorXd::Random(512) * y;
|
|
|
|
VectorXcf vcf = VectorXcf::Random(512) * y;
|
|
|
|
BENCH_PERF(sqsumNorm);
|
2014-09-11 16:27:46 +08:00
|
|
|
BENCH_PERF(stableNorm);
|
2009-07-17 22:22:39 +08:00
|
|
|
BENCH_PERF(blueNorm);
|
2014-02-13 22:53:51 +08:00
|
|
|
BENCH_PERF(pblueNorm);
|
|
|
|
BENCH_PERF(lapackNorm);
|
|
|
|
BENCH_PERF(hypotNorm);
|
|
|
|
BENCH_PERF(twopassNorm);
|
2009-07-17 22:22:39 +08:00
|
|
|
BENCH_PERF(bl2passNorm);
|
|
|
|
}
|
2009-07-16 17:33:56 +08:00
|
|
|
}
|