From e93adc0b846e92817bad908d09cae41daf1a6942 Mon Sep 17 00:00:00 2001 From: Hartmut Hafermann Date: Mon, 13 Oct 2014 17:40:32 +0200 Subject: [PATCH] [gfs] add << operator for gfs kept <<= for backward compatibility TODO: clean doc and examples, possibly add deprecation warning --- pytriqs/gf/local/_gf_common.py | 3 +++ pytriqs/gf/local/block_gf.py | 11 +++++++++++ pytriqs/gf/local/gf_desc.py | 3 +++ 3 files changed, 17 insertions(+) diff --git a/pytriqs/gf/local/_gf_common.py b/pytriqs/gf/local/_gf_common.py index 497af4b1..6ffd74a2 100644 --- a/pytriqs/gf/local/_gf_common.py +++ b/pytriqs/gf/local/_gf_common.py @@ -73,6 +73,9 @@ def mul_precall (self, y): def div_precall (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): """ A can be two things: diff --git a/pytriqs/gf/local/block_gf.py b/pytriqs/gf/local/block_gf.py index da6e88c3..50964ebb 100644 --- a/pytriqs/gf/local/block_gf.py +++ b/pytriqs/gf/local/block_gf.py @@ -232,6 +232,17 @@ class BlockGf(object): def __le__(self, other) : 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): """ A can be 2 things : * G <<= any_init will init all the BlockGf with the initializer diff --git a/pytriqs/gf/local/gf_desc.py b/pytriqs/gf/local/gf_desc.py index 0365f42a..570c6b60 100644 --- a/pytriqs/gf/local/gf_desc.py +++ b/pytriqs/gf/local/gf_desc.py @@ -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['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.add_method(name = "invert", calling_pattern = "invert_in_place(self_c)" , signature = "void()", doc = "Invert (in place)")