mirror of
https://github.com/triqs/dft_tools
synced 2024-10-31 19:23:45 +01:00
Fix #139
- Python legacy code : - Put back for both refreq and imfreq gf g += matrix g += complex g + matrix g + complex and same with - operator. - same impl. for both. - with python wrapping
This commit is contained in:
parent
eacf3a0d30
commit
41caa7ab91
@ -381,10 +381,17 @@ g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.replace_by_tail_depr")
|
||||
g.add_pure_python_method("pytriqs.gf.local._gf_imfreq.fit_tail_depr")
|
||||
|
||||
# For legacy Python code : authorize g + Matrix
|
||||
#g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<imfreq>(gf<imfreq> x,matrix<std:complex<double>> y)")
|
||||
g.number_protocol['inplace_add'].add_overload(calling_pattern = "+=", signature = "void(gf_view<imfreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['inplace_subtract'].add_overload(calling_pattern = "-=", signature = "void(gf_view<imfreq> x,matrix<std::complex<double>> y)")
|
||||
|
||||
g.number_protocol['inplace_add'].add_overload(calling_pattern = "+=", signature = "void(gf_view<imfreq> x,std::complex<double> y)")
|
||||
g.number_protocol['inplace_subtract'].add_overload(calling_pattern = "-=", signature = "void(gf_view<imfreq> x,std::complex<double> y)")
|
||||
|
||||
g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<imfreq>(gf<imfreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<imfreq>(gf<imfreq> x,std::complex<double> y)")
|
||||
g.number_protocol['subtract'].add_overload(calling_pattern = "-", signature = "gf<imfreq>(gf<imfreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['subtract'].add_overload(calling_pattern = "-", signature = "gf<imfreq>(gf<imfreq> x,std::complex<double> y)")
|
||||
|
||||
module.add_class(g)
|
||||
|
||||
########################
|
||||
@ -467,6 +474,18 @@ g.add_method(name = "set_from_pade",
|
||||
calling_pattern = "pade(self_c,*gw,n_points, freq_offset)",
|
||||
doc = """TO BE WRITTEN""")
|
||||
|
||||
# For legacy Python code : authorize g + Matrix
|
||||
g.number_protocol['inplace_add'].add_overload(calling_pattern = "+=", signature = "void(gf_view<refreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['inplace_subtract'].add_overload(calling_pattern = "-=", signature = "void(gf_view<refreq> x,matrix<std::complex<double>> y)")
|
||||
|
||||
g.number_protocol['inplace_add'].add_overload(calling_pattern = "+=", signature = "void(gf_view<refreq> x,std::complex<double> y)")
|
||||
g.number_protocol['inplace_subtract'].add_overload(calling_pattern = "-=", signature = "void(gf_view<refreq> x,std::complex<double> y)")
|
||||
|
||||
g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<refreq>(gf<refreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['add'].add_overload(calling_pattern = "+", signature = "gf<refreq>(gf<refreq> x,std::complex<double> y)")
|
||||
g.number_protocol['subtract'].add_overload(calling_pattern = "-", signature = "gf<refreq>(gf<refreq> x,matrix<std::complex<double>> y)")
|
||||
g.number_protocol['subtract'].add_overload(calling_pattern = "-", signature = "gf<refreq>(gf<refreq> x,std::complex<double> y)")
|
||||
|
||||
module.add_class(g)
|
||||
|
||||
########################
|
||||
|
@ -243,6 +243,12 @@ namespace arrays {
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename V> matrix<V> make_unit_matrix(int dim,V const &v) {
|
||||
matrix<V> r(dim, dim);
|
||||
r() = v;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename ArrayType>
|
||||
matrix_view<typename ArrayType::value_type, typename ArrayType::traversal_order_t, true> make_matrix_view(ArrayType const& a) {
|
||||
static_assert(ArrayType::rank == 2, "make_matrix_view only works for array of rank 2");
|
||||
|
@ -160,16 +160,46 @@ namespace gfs {
|
||||
|
||||
} // gfs_implementation
|
||||
|
||||
// FOR LEGACY PYTHON CODE ONLY
|
||||
// THIS MUST be kept for python operations
|
||||
// specific operations (for legacy python code).
|
||||
// +=, -= with a matrix
|
||||
inline void operator+=(gf_view<imfreq> g, arrays::matrix<std::complex<double>> m) {
|
||||
inline void operator+=(gf_view<imfreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
for (int u = 0; u < int(first_dim(g.data())); ++u) g.data()(u, arrays::ellipsis()) += m;
|
||||
g.singularity()(0) += m;
|
||||
}
|
||||
|
||||
inline void operator-=(gf_view<imfreq> g, arrays::matrix<std::complex<double>> m) {
|
||||
inline void operator-=(gf_view<imfreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
for (int u = 0; u < int(first_dim(g.data())); ++u) g.data()(u, arrays::ellipsis()) -= m;
|
||||
g.singularity()(0) -= m;
|
||||
}
|
||||
|
||||
inline void operator+=(gf_view<imfreq> g, std::complex<double> a) {
|
||||
operator+=(g, arrays::make_unit_matrix(get_target_shape(g)[0], a));
|
||||
}
|
||||
inline void operator-=(gf_view<imfreq> g, std::complex<double> a) {
|
||||
operator-=(g, arrays::make_unit_matrix(get_target_shape(g)[0], a));
|
||||
}
|
||||
|
||||
|
||||
inline gf<imfreq> operator+(gf<imfreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
g() += m;
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<imfreq> operator+(gf<imfreq> g, std::complex<double> const &m) {
|
||||
g() += m; // () is critical of infinite loop -> segfault
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<imfreq> operator-(gf<imfreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
g() -= m;
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<imfreq> operator-(gf<imfreq> g, std::complex<double> const &m) {
|
||||
g() -= m;
|
||||
return g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,48 @@ namespace gfs {
|
||||
template <typename Opt> struct data_proxy<refreq, matrix_valued, Opt> : data_proxy_array<std::complex<double>, 3> {};
|
||||
template <typename Opt> struct data_proxy<refreq, scalar_valued, Opt> : data_proxy_array<std::complex<double>, 1> {};
|
||||
}
|
||||
|
||||
// FOR LEGACY PYTHON CODE ONLY
|
||||
// THIS MUST be kept for python operations
|
||||
// specific operations (for legacy python code).
|
||||
// +=, -= with a matrix
|
||||
inline void operator+=(gf_view<refreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
for (int u = 0; u < int(first_dim(g.data())); ++u) g.data()(u, arrays::ellipsis()) += m;
|
||||
g.singularity()(0) += m;
|
||||
}
|
||||
|
||||
inline void operator-=(gf_view<refreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
for (int u = 0; u < int(first_dim(g.data())); ++u) g.data()(u, arrays::ellipsis()) -= m;
|
||||
g.singularity()(0) -= m;
|
||||
}
|
||||
|
||||
inline void operator+=(gf_view<refreq> g, std::complex<double> a) {
|
||||
operator+=(g, arrays::make_unit_matrix(get_target_shape(g)[0], a));
|
||||
}
|
||||
inline void operator-=(gf_view<refreq> g, std::complex<double> a) {
|
||||
operator-=(g, arrays::make_unit_matrix(get_target_shape(g)[0], a));
|
||||
}
|
||||
|
||||
|
||||
inline gf<refreq> operator+(gf<refreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
g() += m;
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<refreq> operator+(gf<refreq> g, std::complex<double> const &m) {
|
||||
g() += m; // () is critical of infinite loop -> segfault
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<refreq> operator-(gf<refreq> g, arrays::matrix<std::complex<double>> const &m) {
|
||||
g() -= m;
|
||||
return g;
|
||||
}
|
||||
|
||||
inline gf<refreq> operator-(gf<refreq> g, std::complex<double> const &m) {
|
||||
g() -= m;
|
||||
return g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user