mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 05:43:40 +01:00
Fix #122
- the conj_ function was not written properly (T is a ref, the trait is_complex was not returning true). - a simpler version is clearly better !
This commit is contained in:
parent
7cf7d09c77
commit
e6234ed3d5
@ -33,7 +33,7 @@ template<typename Vd, typename Vi>
|
|||||||
void test() {
|
void test() {
|
||||||
Vd a(2),aa(2),c(2) ;a()=2.0; c() = 1;
|
Vd a(2),aa(2),c(2) ;a()=2.0; c() = 1;
|
||||||
Vi b(2);b()=3;
|
Vi b(2);b()=3;
|
||||||
std::cout << blas::dot<false>(a,b) << std::endl;
|
std::cerr << blas::dot<false>(a,b) << std::endl;
|
||||||
|
|
||||||
aa = 2*a;
|
aa = 2*a;
|
||||||
|
|
||||||
@ -51,7 +51,19 @@ void test() {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
test<vector<double> , vector<int> >();
|
test<vector<double> , vector<int> >();
|
||||||
|
|
||||||
|
/// Added by I. Krivenko, #122
|
||||||
|
/// test the complex version, specially with the zdotu workaround on Os X.
|
||||||
|
vector<std::complex<double>> v(2);
|
||||||
|
v(0) = 0;
|
||||||
|
v(1) = {0, 1};
|
||||||
|
|
||||||
|
std::cerr << v << std::endl;
|
||||||
|
std::cerr << blas::dot<false>(v, v) << std::endl;
|
||||||
|
std::cerr << blas::dot<true>(v, v) << std::endl;
|
||||||
|
assert_close( dot(v,v), -1);
|
||||||
|
assert_close( dotc(v,v), 1);
|
||||||
|
|
||||||
// does not work for array just because of .size() vs .shape(0)...
|
// does not work for array just because of .size() vs .shape(0)...
|
||||||
//test<array<double,1> , array<int,1> >();
|
//test<array<double,1> , array<int,1> >();
|
||||||
//test<array<double,1> , vector<int> >();
|
//test<array<double,1> , vector<int> >();
|
||||||
|
@ -67,13 +67,10 @@ namespace triqs { namespace arrays { namespace blas {
|
|||||||
//return f77::dot(X.size(), Cx().data_start(), Cx().stride(), Cy().data_start(), Cy().stride());
|
//return f77::dot(X.size(), Cx().data_start(), Cx().stride(), Cy().data_start(), Cy().stride());
|
||||||
}
|
}
|
||||||
|
|
||||||
template< bool Star, typename T>
|
template <bool Star> std::complex<double> _conj(std::complex<double> const& x);
|
||||||
typename std::enable_if<triqs::is_complex<T>::value && Star,T>::type
|
template <> std::complex<double> _conj<true>(std::complex<double> const& x) { return conj(x); }
|
||||||
_conj(T && x) { return conj(std::forward<T>(x));}
|
template <> std::complex<double> _conj<false>(std::complex<double> const& x) { return x;}
|
||||||
|
template <bool Star> double _conj(double x) { return x; }
|
||||||
template< bool Star, typename T>
|
|
||||||
typename std::enable_if<!( triqs::is_complex<T>::value && Star),T>::type
|
|
||||||
_conj(T && x) { return std::forward<T>(x);}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls dot product of 2 vectors.
|
* Calls dot product of 2 vectors.
|
||||||
@ -94,7 +91,7 @@ namespace triqs { namespace arrays { namespace blas {
|
|||||||
auto * restrict X_ = X.data_start();
|
auto * restrict X_ = X.data_start();
|
||||||
auto * restrict Y_ = Y.data_start();
|
auto * restrict Y_ = Y.data_start();
|
||||||
if ((incx==1) && (incy==1)) {
|
if ((incx==1) && (incy==1)) {
|
||||||
for (size_t i=0; i<N; ++i) res += _conj<Star>(X_[i]) * Y_[i];
|
for (size_t i = 0; i < N; ++i) res += _conj<Star>(X_[i]) * Y_[i];
|
||||||
}
|
}
|
||||||
else { // code for unequal increments or equal increments not equal to 1
|
else { // code for unequal increments or equal increments not equal to 1
|
||||||
for (size_t i=0, ix=0, iy=0; i<N; ++i, ix += incx, iy +=incy) {res += _conj<Star>(X_[ix]) * Y_[iy]; }
|
for (size_t i=0, ix=0, iy=0; i<N; ++i, ix += incx, iy +=incy) {res += _conj<Star>(X_[ix]) * Y_[iy]; }
|
||||||
|
Loading…
Reference in New Issue
Block a user