3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 05:43:40 +01:00

[gfs] add << operator for gfs

kept <<= for backward compatibility
TODO: clean doc and examples, possibly add deprecation warning
This commit is contained in:
Hartmut Hafermann 2014-10-13 17:40:32 +02:00
parent 2f2374ea29
commit e93adc0b84
3 changed files with 17 additions and 0 deletions

View File

@ -73,6 +73,9 @@ def mul_precall (self, y):
def div_precall (self, y): def div_precall (self, y):
if descriptor_base.is_lazy(y): return lazy_expressions.make_lazy(self) / y if descriptor_base.is_lazy(y): return lazy_expressions.make_lazy(self) / y
def _lshift_(self, A):
return _ilshift_(self, A)
def _ilshift_(self, A): def _ilshift_(self, A):
""" A can be two things: """ A can be two things:

View File

@ -232,6 +232,17 @@ class BlockGf(object):
def __le__(self, other) : def __le__(self, other) :
raise RuntimeError, " Operator <= not defined " raise RuntimeError, " Operator <= not defined "
def __lshift__(self, A):
""" A can be 2 things :
* G << any_init will init all the BlockGf with the initializer
* G << g2 where g2 is a BlockGf will copy g2 into self
"""
if isinstance(A, self.__class__):
for (i,g) in self : g.copy_from(A[i])
else:
for i,g in self: g << A
return self
def __ilshift__(self, A): def __ilshift__(self, A):
""" A can be 2 things : """ A can be 2 things :
* G <<= any_init will init all the BlockGf with the initializer * G <<= any_init will init all the BlockGf with the initializer

View File

@ -313,6 +313,9 @@ def make_gf( py_type, c_tag, is_complex_data = True, is_im = False, has_tail = T
g.number_protocol['multiply'].python_precall = "pytriqs.gf.local._gf_common.mul_precall" g.number_protocol['multiply'].python_precall = "pytriqs.gf.local._gf_common.mul_precall"
g.number_protocol['divide'].python_precall = "pytriqs.gf.local._gf_common.div_precall" g.number_protocol['divide'].python_precall = "pytriqs.gf.local._gf_common.div_precall"
g.number_protocol['lshift'] = pyfunction(name ="__lshift__", python_precall = "pytriqs.gf.local._gf_common._lshift_", arity = 2)
# For backward compatibility
g.number_protocol['inplace_lshift'] = pyfunction(name ="__inplace_lshift__", python_precall = "pytriqs.gf.local._gf_common._ilshift_", arity = 2) g.number_protocol['inplace_lshift'] = pyfunction(name ="__inplace_lshift__", python_precall = "pytriqs.gf.local._gf_common._ilshift_", arity = 2)
g.add_method(name = "invert", calling_pattern = "invert_in_place(self_c)" , signature = "void()", doc = "Invert (in place)") g.add_method(name = "invert", calling_pattern = "invert_in_place(self_c)" , signature = "void()", doc = "Invert (in place)")