3
0
mirror of https://github.com/triqs/dft_tools synced 2024-10-31 19:23:45 +01:00

arrays : fix matrix = scalar for complex types

Pb :
M() = rhs; // rhs of type RHS
Currenlty does :
M(i,j) = (i==j ? rhs : RHS{})
Changed to
M(i,j) = (i==j ? rhs : RHS{0*rhs})

If RHS is a double, int ... Same result.
If RHS is a matrix, gf, currently the offdiag elements
are default constructed (i.e. of 0 size !).
Which can break operations later (matrix<matrix<double>>)
After change : all elements have the same size !
This commit is contained in:
Olivier Parcollet 2014-02-12 21:50:58 +01:00
parent 87dc9aeaa5
commit 7aedaef945

View File

@ -139,8 +139,12 @@ namespace triqs { namespace arrays {
typedef typename LHS::value_type value_type;
LHS & lhs; const RHS & rhs;
impl(LHS & lhs_, const RHS & rhs_): lhs(lhs_), rhs(rhs_){} //, p(*(lhs_.data_start())) {}
// we MUST make off_diag like this, if value_type is a complicated type (i.e. gf, matrix) with a size
// off diagonal element is 0*rhs, i.e. a 0, but with the SAME SIZE as the diagonal part.
// otherwise further operation may fail later.
// TO DO : look at performance issue ?? (we can remote the multiplication by 0 using an auxiliary function)
template<typename ... Args>
void operator()(Args const & ... args) const {_ops_<value_type, RHS, OP>::invoke(lhs(args...), (kronecker(args...) ? rhs : RHS()));}
void operator()(Args const & ... args) const {_ops_<value_type, RHS, OP>::invoke(lhs(args...), (kronecker(args...) ? rhs : RHS{0*rhs}));}
void invoke() { foreach(lhs,*this); }
};