From cfe3532c94a1dbd4df0458e9750a21c759320b19 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Thu, 22 May 2014 14:51:26 +0200 Subject: [PATCH] array & gf transpose - implement transposed_view for arrays. - .transpose method for gf - wrapped to python - add call op. for GfImTime, using C++ - Added ChangeLog - rm matrix_stack - start cleaning old code --- ChangeLog | 10 ++ pytriqs/gf/local/OLD/functions.pxd | 31 ---- pytriqs/gf/local/OLD/gf.pxd | 62 -------- pytriqs/gf/local/OLD/gf.pyx | 26 ---- pytriqs/gf/local/OLD/imfreq.pxd | 57 -------- pytriqs/gf/local/OLD/imtime.pxd | 58 -------- pytriqs/gf/local/OLD/legendre.pxd | 54 ------- pytriqs/gf/local/OLD/matrix_stack.pxd | 17 --- pytriqs/gf/local/OLD/matrix_stack.pyx | 34 ----- pytriqs/gf/local/OLD/mesh_imfreq.pyx | 36 ----- pytriqs/gf/local/OLD/mesh_imtime.pyx | 37 ----- pytriqs/gf/local/OLD/mesh_refreq.pyx | 34 ----- pytriqs/gf/local/OLD/mesh_retime.pyx | 34 ----- pytriqs/gf/local/OLD/nothing.py | 43 ------ pytriqs/gf/local/OLD/refreq.pxd | 56 -------- pytriqs/gf/local/OLD/refreq.pyx | 79 ----------- pytriqs/gf/local/OLD/retime.pxd | 56 -------- pytriqs/gf/local/OLD/retime.pyx | 76 ---------- pytriqs/gf/local/OLD/tail.pxd | 37 ----- pytriqs/gf/local/OLD/tail.pyx | 140 +------------------ pytriqs/gf/local/OLD/two_real_times.pxd | 59 -------- pytriqs/gf/local/gf_desc.py | 32 +++-- test/triqs/arrays/mat_stack.cpp | 89 ------------ triqs/arrays/array.hpp | 14 +- triqs/arrays/indexmaps/cuboid/domain.hpp | 5 +- triqs/arrays/indexmaps/cuboid/map.hpp | 48 ++++--- triqs/arrays/indexmaps/cuboid/mem_layout.hpp | 19 +-- triqs/arrays/matrix_stack_view.hpp | 86 ------------ triqs/gfs/gf.hpp | 13 +- triqs/gfs/local/tail.hpp | 2 + triqs/gfs/tools.hpp | 11 ++ triqs/python_tools/wrapper_tools.hpp | 12 +- 32 files changed, 109 insertions(+), 1258 deletions(-) create mode 100644 ChangeLog delete mode 100644 pytriqs/gf/local/OLD/functions.pxd delete mode 100644 pytriqs/gf/local/OLD/gf.pxd delete mode 100644 pytriqs/gf/local/OLD/gf.pyx delete mode 100644 pytriqs/gf/local/OLD/imfreq.pxd delete mode 100644 pytriqs/gf/local/OLD/imtime.pxd delete mode 100644 pytriqs/gf/local/OLD/legendre.pxd delete mode 100644 pytriqs/gf/local/OLD/matrix_stack.pxd delete mode 100644 pytriqs/gf/local/OLD/matrix_stack.pyx delete mode 100644 pytriqs/gf/local/OLD/mesh_imfreq.pyx delete mode 100644 pytriqs/gf/local/OLD/mesh_imtime.pyx delete mode 100644 pytriqs/gf/local/OLD/mesh_refreq.pyx delete mode 100644 pytriqs/gf/local/OLD/mesh_retime.pyx delete mode 100644 pytriqs/gf/local/OLD/nothing.py delete mode 100644 pytriqs/gf/local/OLD/refreq.pxd delete mode 100644 pytriqs/gf/local/OLD/refreq.pyx delete mode 100644 pytriqs/gf/local/OLD/retime.pxd delete mode 100644 pytriqs/gf/local/OLD/retime.pyx delete mode 100644 pytriqs/gf/local/OLD/tail.pxd delete mode 100644 pytriqs/gf/local/OLD/two_real_times.pxd delete mode 100644 test/triqs/arrays/mat_stack.cpp delete mode 100644 triqs/arrays/matrix_stack_view.hpp diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 00000000..c04fc6fd --- /dev/null +++ b/ChangeLog @@ -0,0 +1,10 @@ + +From version 1.0 to 1.2 + +Python +---------- + +gf: + + * transpose method now returns a NEW green function, like conjugate, etc... + diff --git a/pytriqs/gf/local/OLD/functions.pxd b/pytriqs/gf/local/OLD/functions.pxd deleted file mode 100644 index 8e35d880..00000000 --- a/pytriqs/gf/local/OLD/functions.pxd +++ /dev/null @@ -1,31 +0,0 @@ -############### Density ######################### - -cdef extern from "triqs/gfs/local/functions.hpp": - matrix_view density(gf_imfreq &) - matrix_view density(gf_legendre &) - void enforce_discontinuity(gf_legendre &, array_view[double,TWO]) - -############### Fourier ######################### - -cdef extern from "triqs/gfs/local/fourier_matsubara.hpp" : - gf_imfreq fourier (gf_imtime & ) - gf_imtime inverse_fourier (gf_imfreq & ) - -cdef extern from "triqs/gfs/local/fourier_real.hpp" : - gf_refreq fourier (gf_retime & ) - gf_retime inverse_fourier (gf_refreq & ) - #gf_refreq fourier (gf_retime & ) except + - #gf_retime inverse_fourier (gf_refreq & ) except + - -############### Legendre ######################### - -cdef extern from "triqs/gfs/local/legendre_matsubara.hpp" : - gf_imfreq legendre_to_imfreq (gf_legendre &) - gf_imtime legendre_to_imtime (gf_legendre &) - gf_legendre imfreq_to_legendre (gf_imfreq &) - gf_legendre imtime_to_legendre (gf_imtime &) - -############### Pade ######################### - -cdef extern from "triqs/gfs/local/pade.hpp": - void pade(gf_refreq &, gf_imfreq &, int, double) except + diff --git a/pytriqs/gf/local/OLD/gf.pxd b/pytriqs/gf/local/OLD/gf.pxd deleted file mode 100644 index a068fe31..00000000 --- a/pytriqs/gf/local/OLD/gf.pxd +++ /dev/null @@ -1,62 +0,0 @@ -from dcomplex cimport * -from arrays cimport * -from libcpp.vector cimport vector -from libcpp.string cimport string as std_string -from shared_ptr cimport * -from extractor cimport * -from h5 cimport * - -# -------------------- Some generic tools ------------------------------- - -cdef extern from "triqs/gfs/tools.hpp" namespace "triqs::gfs" : - cdef enum statistic_enum "triqs::gfs::statistic_enum" : - Boson,Fermion - - cdef cppclass nothing : - nothing () - - cdef cppclass freq_infty: - freq_infty () - - cdef cppclass mesh_pt_generator "triqs::gfs::mesh_pt_generator" [MeshType] : - mesh_pt_generator( MeshType * ) - mesh_pt_generator() - complex to_point() - mesh_pt_generator operator++() - bint at_end() - void increment() - - cdef cppclass indices_2_t : - indices_2_t( ) - indices_2_t( vector[vector[std_string]] &) - vector[std_string] & operator[](int) - vector[vector[std_string]] & operator()() - bint same() - -cdef extern from "triqs/gfs/meshes/linear.hpp" namespace "triqs::gfs" : - - cdef enum mesh_enum "triqs::gfs::mesh_kind": - half_bins, full_bins, without_last - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass discrete_domain : - discrete_domain () - discrete_domain (vector[std_string] &) - vector[std_string] & names() - - cdef cppclass discrete_mesh : - discrete_mesh () - discrete_mesh (discrete_mesh &) - discrete_domain & domain() - long size() - bint operator ==( discrete_mesh &) - -include "tail.pxd" -include "imfreq.pxd" -include "imtime.pxd" -include "refreq.pxd" -include "retime.pxd" -include "legendre.pxd" -#include "two_real_times.pxd" - diff --git a/pytriqs/gf/local/OLD/gf.pyx b/pytriqs/gf/local/OLD/gf.pyx deleted file mode 100644 index 17551603..00000000 --- a/pytriqs/gf/local/OLD/gf.pyx +++ /dev/null @@ -1,26 +0,0 @@ -#!python -#cython: embedsignature=True -from cython.operator cimport dereference as deref, preincrement as inc #dereference and increment operators -cimport cython -import numpy -import string -import warnings -from block_gf import BlockGf -from math import pi -from h5 cimport * - -include "mesh_imfreq.pyx" -include "mesh_imtime.pyx" -include "mesh_refreq.pyx" -include "mesh_retime.pyx" -#include "mesh_two_real_times.pyx" -include "mesh_legendre.pyx" -include "imfreq.pyx" -include "imtime.pyx" -include "refreq.pyx" -include "retime.pyx" -#include "two_real_times.pyx" -include "legendre.pyx" -include "tail.pyx" -include "functions.pxd" - diff --git a/pytriqs/gf/local/OLD/imfreq.pxd b/pytriqs/gf/local/OLD/imfreq.pxd deleted file mode 100644 index 0104dbf4..00000000 --- a/pytriqs/gf/local/OLD/imfreq.pxd +++ /dev/null @@ -1,57 +0,0 @@ -cdef extern from "triqs/gfs/imfreq.hpp" namespace "triqs::gfs" : - - cdef cppclass imfreq_domain : - double beta - statistic_enum statistic - imfreq_domain () - - cdef cppclass mesh_imfreq "triqs::gfs::gf_mesh" : - mesh_imfreq () - mesh_imfreq (mesh_imfreq &) - imfreq_domain & domain() - double x_min() - long size() - bint positive_only() - bint operator ==( mesh_imfreq &) - - cdef mesh_imfreq make_mesh_imfreq "triqs::gfs::gf_mesh" (double beta, statistic_enum S, size_t n_max, bint positive_only) - #cdef mesh_imfreq make_mesh_imfreq "triqs::gfs::gf_implementation::gf_factories::make_mesh" (double beta, statistic_enum S, size_t n_max) - - cdef cppclass gf_imfreq "triqs::python_tools::cython_proxy >" : - gf_imfreq() - gf_imfreq(gf_imfreq &) - # The constructor must be no_except, or the cython code won't be correct... - gf_imfreq(mesh_imfreq, array_view[dcomplex, THREE], tail, nothing) #except + - void operator << (gf_imfreq &) - mesh_imfreq mesh() - array_view[dcomplex, THREE] data() - tail singularity() - -cdef extern from "triqs/gfs/imfreq.hpp" : - cdef void h5_write (h5_group, char *, gf_imfreq &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_imfreq &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_imfreq &) - -# Python -> C -cdef gf_imfreq as_gf_imfreq (g) except + - -# C -> Python -cdef make_GfImFreq (gf_imfreq x, indices_pack=*, name=*) - -############### Blocks of Im Freq ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_imfreq "triqs::python_tools::cython_proxy>>" : - gf_block_imfreq() - gf_imfreq & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_imfreq make_gf_block_imfreq "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" (vector[gf_imfreq] &) - #cdef gf_block_imfreq make_gf_block_imfreq "triqs::gfs::make_gf_view>" ( vector[gf_imfreq] &) - -cdef gf_block_imfreq as_gf_block_imfreq (G) except + -cdef make_BlockGfImFreq (gf_block_imfreq G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/OLD/imtime.pxd b/pytriqs/gf/local/OLD/imtime.pxd deleted file mode 100644 index 0074eccc..00000000 --- a/pytriqs/gf/local/OLD/imtime.pxd +++ /dev/null @@ -1,58 +0,0 @@ -cdef extern from "triqs/gfs/imtime.hpp" namespace "triqs::gfs" : - - cdef cppclass imtime_domain : - double beta - statistic_enum statistic - imtime_domain () - - cdef cppclass mesh_imtime "triqs::gfs::gf_mesh" : - mesh_imtime () - mesh_imtime (mesh_imtime &) - imtime_domain & domain() - double x_min() - long size() - long kind() - bint operator ==( mesh_imtime &) - - cdef mesh_imtime make_mesh_imtime "triqs::gfs::gf_mesh" (double beta, statistic_enum S, size_t n_time_slices, mesh_enum mk) - #cdef mesh_imtime make_mesh_imtime "triqs::gfs::gf_factories::make_mesh" (double beta, statistic_enum S, size_t n_time_slices, mesh_enum mk) - - cdef cppclass gf_imtime "triqs::python_tools::cython_proxy>" : - gf_imtime() - gf_imtime(gf_imtime &) - # The constructor must be no_except, or the cython code won't be correct... - gf_imtime(mesh_imtime, array_view[double, THREE], tail, nothing) #except + - void operator << (gf_imtime &) - mesh_imtime mesh() - array_view[double, THREE] data() - matrix_view[double] operator()(double) - tail singularity() - -cdef extern from "triqs/gfs/imtime.hpp" : - cdef void h5_write (h5_group, char *, gf_imtime &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_imtime &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_imtime &) - -# Python -> C -cdef gf_imtime as_gf_imtime (g) except + - -# C -> Python -cdef make_GfImTime (gf_imtime x, indices_pack=*, name=*) - -############### Blocks of Im Time ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_imtime "triqs::python_tools::cython_proxy>>" : - gf_block_imtime() - gf_imtime & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_imtime make_gf_block_imtime "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" (vector[gf_imtime] &) - #cdef gf_block_imtime make_gf_block_imtime "triqs::gfs::make_gf_view>" ( vector[gf_imtime] &) - -cdef gf_block_imtime as_gf_block_imtime (G) except + -cdef make_BlockGfImTime (gf_block_imtime G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/OLD/legendre.pxd b/pytriqs/gf/local/OLD/legendre.pxd deleted file mode 100644 index 28643c54..00000000 --- a/pytriqs/gf/local/OLD/legendre.pxd +++ /dev/null @@ -1,54 +0,0 @@ -cdef extern from "triqs/gfs/legendre.hpp" namespace "triqs::gfs" : - - cdef cppclass legendre_domain : - size_t Nmax - double beta - statistic_enum statistic - legendre_domain () - - cdef cppclass mesh_legendre "triqs::gfs::gf_mesh" : - mesh_legendre () - mesh_legendre (mesh_legendre &) - legendre_domain & domain() - long size() - bint operator == (mesh_legendre &) - - cdef mesh_legendre make_mesh_legendre "triqs::gfs::gf_mesh" (double beta, statistic_enum S, size_t n_leg) - #cdef mesh_legendre make_mesh_legendre "triqs::gfs::gf_factories::make_mesh" (double beta, statistic_enum S, size_t n_leg) - - cdef cppclass gf_legendre "triqs::python_tools::cython_proxy>" : - gf_legendre() - gf_legendre(gf_legendre &) - gf_legendre(mesh_legendre, array_view[double, THREE], nothing, nothing) #except + - void operator << (gf_legendre &) - mesh_legendre mesh() - array_view[double, THREE] data() - -cdef extern from "triqs/gfs/legendre.hpp" : - cdef void h5_write (h5_group, char *, gf_legendre &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_legendre &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_legendre &) - -# Python -> C -cdef gf_legendre as_gf_legendre(g) except + - -# C -> Python -cdef make_GfLegendre(gf_legendre x, indices_pack=*, name=*) - -############### Blocks of Im Time ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_legendre "triqs::python_tools::cython_proxy>>" : - gf_block_legendre() - gf_legendre & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_legendre make_gf_block_legendre "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" (vector[gf_legendre] &) - #cdef gf_block_legendre make_gf_block_legendre "triqs::gfs::make_gf_view>" ( vector[gf_legendre] &) - -cdef gf_block_legendre as_gf_block_legendre (G) except + -cdef make_BlockGfLegendre (gf_block_legendre G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/OLD/matrix_stack.pxd b/pytriqs/gf/local/OLD/matrix_stack.pxd deleted file mode 100644 index dec5c32f..00000000 --- a/pytriqs/gf/local/OLD/matrix_stack.pxd +++ /dev/null @@ -1,17 +0,0 @@ -include "arrays.pxd" -include "dcomplex.pxd" - -cdef extern from "" namespace "triqs::arrays": - - cdef cppclass matrix_stack "triqs::arrays::matrix_stack_view" [T]: - - matrix_stack(object) - - void iadd "operator +=" (matrix_view[T] &) except + - void isub "operator -=" (matrix_view[T] &) except + - - void imul "operator *=" (matrix_view[T] &) except + - void idiv "operator /=" (matrix_view[T] &) except + - - void invert() except + - void onsite_matmul_L_R(matrix_view[T] &, matrix_stack &, matrix_view[T] &) except + diff --git a/pytriqs/gf/local/OLD/matrix_stack.pyx b/pytriqs/gf/local/OLD/matrix_stack.pyx deleted file mode 100644 index 76b54753..00000000 --- a/pytriqs/gf/local/OLD/matrix_stack.pyx +++ /dev/null @@ -1,34 +0,0 @@ -import numpy - -class MatrixStack: - - def __init__(self, A): - """ - """ - self.data = A - self.is_double = A.dtype in [numpy.float, numpy.float32, numpy.float64, numpy.float_] - - def add(self, M): - if self.is_double: - matrix_stack[double](self.data).iadd(matrix_view[double](M)) - else: - matrix_stack[dcomplex](self.data).iadd(matrix_view[dcomplex](M.astype(numpy.complex))) - - def sub(self, M): - if self.is_double: - matrix_stack[double](self.data).isub(matrix_view[double](M)) - else: - matrix_stack[dcomplex](self.data).isub(matrix_view[dcomplex](M.astype(numpy.complex))) - - def matmul_L_R(self, L, D, R): - if self.is_double: - matrix_stack[double](self.data).onsite_matmul_L_R(matrix_view[double](L), matrix_stack[double](D), matrix_view[double](R)) - else: - matrix_stack[dcomplex](self.data).onsite_matmul_L_R( - matrix_view[dcomplex](L.astype(numpy.complex)), matrix_stack[dcomplex](D), matrix_view[dcomplex](R.astype(numpy.complex))) - - def invert(self): - if self.is_double: - matrix_stack[double](self.data).invert() - else: - matrix_stack[dcomplex](self.data).invert() diff --git a/pytriqs/gf/local/OLD/mesh_imfreq.pyx b/pytriqs/gf/local/OLD/mesh_imfreq.pyx deleted file mode 100644 index 21b4d5a1..00000000 --- a/pytriqs/gf/local/OLD/mesh_imfreq.pyx +++ /dev/null @@ -1,36 +0,0 @@ -cdef class MeshImFreq: - cdef mesh_imfreq _c - - def __init__(self, beta, stat, int n_pts, bint positive_only=True): - self._c = make_mesh_imfreq(beta,{'F' :Fermion, 'B' : Boson}[stat], n_pts, positive_only) - - def __len__ (self) : return self._c.size() - - property beta : - """Inverse temperature""" - def __get__(self): return self._c.domain().beta - - property statistic : - def __get__(self): return 'F' if self._c.domain().statistic==Fermion else 'B' - - property positive_only : - def __get__(self): return self._c.positive_only() - - def __iter__(self) : # I use the C++ generator ! - cdef mesh_pt_generator[mesh_imfreq ] g = mesh_pt_generator[mesh_imfreq ](&self._c) - while not g.at_end() : - yield g.to_point() - g.increment() - - def __richcmp__(MeshImFreq self, MeshImFreq other,int op) : - if op ==2 : # == - return self._c == other._c - - def __reduce__(self): - return self.__class__, (self.beta, self.statistic, len(self)) - -# C -> Python -cdef inline make_MeshImFreq (mesh_imfreq x) : - return MeshImFreq( x.domain().beta, 'F' if x.domain().statistic==Fermion else 'B', x.size(), x.positive_only() ) - - diff --git a/pytriqs/gf/local/OLD/mesh_imtime.pyx b/pytriqs/gf/local/OLD/mesh_imtime.pyx deleted file mode 100644 index 8294f45c..00000000 --- a/pytriqs/gf/local/OLD/mesh_imtime.pyx +++ /dev/null @@ -1,37 +0,0 @@ -cdef class MeshImTime: - cdef mesh_imtime _c - - def __init__(self, beta, stat, int n_max, kind): - self._c = make_mesh_imtime(beta, {'F' :Fermion, 'B' : Boson}[stat], n_max, {'H':half_bins, 'F':full_bins, 'W':without_last}[kind]) - - def __len__ (self) : return self._c.size() - - property beta : - """Inverse temperature""" - def __get__(self): return self._c.domain().beta - - property kind : - """Inverse temperature""" - def __get__(self): return {half_bins: 'H', full_bins: 'F', without_last: 'W'}[self._c.kind()] - - property statistic : - def __get__(self): return 'F' if self._c.domain().statistic==Fermion else 'B' - - def __iter__(self) : # I use the C++ generator ! - cdef mesh_pt_generator[mesh_imtime ] g = mesh_pt_generator[mesh_imtime ](&self._c) - while not g.at_end() : - yield g.to_point() - g.increment() - - def __richcmp__(MeshImTime self, MeshImTime other,int op) : - if op ==2 : # == - return self._c == other._c - - def __reduce__(self): - return self.__class__, (self.beta, self.statistic, len(self), self.kind) - -# C -> Python -cdef inline make_MeshImTime ( mesh_imtime x) : - return MeshImTime( x.domain().beta, 'F' if x.domain().statistic==Fermion else 'B', - x.size(), {half_bins: 'H', full_bins: 'F', without_last: 'W'}[x.kind()] ) - diff --git a/pytriqs/gf/local/OLD/mesh_refreq.pyx b/pytriqs/gf/local/OLD/mesh_refreq.pyx deleted file mode 100644 index 9cd8cc30..00000000 --- a/pytriqs/gf/local/OLD/mesh_refreq.pyx +++ /dev/null @@ -1,34 +0,0 @@ -cdef class MeshReFreq: - cdef mesh_refreq _c - - def __init__(self, double omega_min, double omega_max, int n_max, kind): - self._c = make_mesh_refreq(omega_min, omega_max, n_max, {'H':half_bins, 'F':full_bins, 'W':without_last}[kind]) - - property omega_min: - def __get__(self): return self._c.x_min() - - property omega_max: - def __get__(self): return self._c.x_max() - - property kind: - def __get__(self): return {half_bins: 'H', full_bins: 'F', without_last: 'W'}[self._c.kind()] - - def __len__ (self) : return self._c.size() - - def __iter__(self) : # I use the C++ generator ! - cdef mesh_pt_generator[mesh_refreq] g = mesh_pt_generator[mesh_refreq](&self._c) - while not g.at_end() : - yield g.to_point() - g.increment() - - def __richcmp__(MeshReFreq self, MeshReFreq other, int op) : - if op ==2 : # == - return self._c == other._c - - def __reduce__(self): - return self.__class__, (self.omega_min, self.omega_max, len(self), self.kind) - -# C -> Python -cdef inline make_MeshReFreq ( mesh_refreq x) : - return MeshReFreq( x.x_min(), x.x_max(), x.size(), {half_bins: 'H', full_bins: 'F', without_last: 'W'}[x.kind()] ) - diff --git a/pytriqs/gf/local/OLD/mesh_retime.pyx b/pytriqs/gf/local/OLD/mesh_retime.pyx deleted file mode 100644 index 5789d4cf..00000000 --- a/pytriqs/gf/local/OLD/mesh_retime.pyx +++ /dev/null @@ -1,34 +0,0 @@ -cdef class MeshReTime: - cdef mesh_retime _c - - def __init__(self, double t_min, double t_max, int n_max, kind): - self._c = make_mesh_retime(t_min, t_max, n_max, {'H':half_bins, 'F':full_bins, 'W':without_last}[kind]) - - property t_min: - def __get__(self): return self._c.x_min() - - property t_max: - def __get__(self): return self._c.x_max() - - property kind: - def __get__(self): return {half_bins: 'H', full_bins: 'F', without_last: 'W'}[self._c.kind()] - - def __len__ (self) : return self._c.size() - - def __iter__(self) : # I use the C++ generator ! - cdef mesh_pt_generator[mesh_retime] g = mesh_pt_generator[mesh_retime](&self._c) - while not g.at_end() : - yield g.to_point() - g.increment() - - def __richcmp__(MeshReTime self, MeshReTime other, int op) : - if op ==2 : # == - return self._c == other._c - - def __reduce__(self): - return self.__class__, (self.t_min, self.t_max, len(self), self.kind) - -# C -> Python -cdef inline make_MeshReTime ( mesh_retime x) : - return MeshReTime( x.x_min(), x.x_max(), x.size(), {half_bins: 'H', full_bins: 'F', without_last: 'W'}[x.kind()] ) - diff --git a/pytriqs/gf/local/OLD/nothing.py b/pytriqs/gf/local/OLD/nothing.py deleted file mode 100644 index 6f5cc3c5..00000000 --- a/pytriqs/gf/local/OLD/nothing.py +++ /dev/null @@ -1,43 +0,0 @@ - -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2011-2012 by M. Ferrero, O. Parcollet -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ - -class Nothing (object): - - def __init__(self): pass - def __getitem__(self, key): return Nothing() - def __setitem__(self, key, val): pass - def __iadd__(self, arg): return Nothing() - def __add__(self, y): return Nothing() - def __radd__(self, y): return Nothing() - def __isub__(self, arg): return Nothing() - def __sub__(self, y): return Nothing() - def __rsub__(self, y): return Nothing() - def __imul__(self, arg): return Nothing() - def __mul__(self, arg): return Nothing() - def __rmul__(self, x): return Nothing() - def __idiv__(self, arg): return Nothing() - def __div__(self, arg): return Nothing() - def _make_slice(self, sl1, sl2): return Nothing() - def invert(self): pass - def transpose(self): return Nothing() - def conjugate(self): return Nothing() - def copy(self): return Nothing() diff --git a/pytriqs/gf/local/OLD/refreq.pxd b/pytriqs/gf/local/OLD/refreq.pxd deleted file mode 100644 index f237a292..00000000 --- a/pytriqs/gf/local/OLD/refreq.pxd +++ /dev/null @@ -1,56 +0,0 @@ -cdef extern from "triqs/gfs/refreq.hpp" namespace "triqs::gfs" : - - cdef cppclass refreq_domain : - refreq_domain() - - cdef cppclass mesh_refreq "triqs::gfs::gf_mesh" : - mesh_refreq () - mesh_refreq (mesh_refreq &) - refreq_domain & domain() - double x_min() - double x_max() - long size() - long kind() - bint operator ==( mesh_refreq &) - - cdef mesh_refreq make_mesh_refreq "triqs::gfs::gf_mesh" (double omega_min, double omega_max, size_t n_freq, mesh_enum mk) - #cdef mesh_refreq make_mesh_refreq "triqs::gfs::gf_factories::make_mesh" (double omega_min, double omega_max, size_t n_freq, mesh_enum mk) - - cdef cppclass gf_refreq "triqs::python_tools::cython_proxy>" : - gf_refreq() - gf_refreq(gf_refreq &) - # The constructor must be no_except, or the cython code won't be correct... - gf_refreq(mesh_refreq, array_view[dcomplex, THREE], tail, nothing) #except + - void operator << (gf_refreq &) - mesh_refreq mesh() - array_view[dcomplex, THREE] data() - tail singularity() - -cdef extern from "triqs/gfs/refreq.hpp" : - cdef void h5_write (h5_group, char *, gf_refreq &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_refreq &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_refreq &) - -# Python -> C -cdef gf_refreq as_gf_refreq (g) except + - -# C -> Python -cdef make_GfReFreq (gf_refreq x, indices_pack=*, name=*) - -############### Blocks of Im Time ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_refreq "triqs::python_tools::cython_proxy>>" : - gf_block_refreq() - gf_refreq & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_refreq make_gf_block_refreq "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" (vector[gf_refreq] &) - #cdef gf_block_refreq make_gf_block_refreq "triqs::gfs::make_gf_view>" ( vector[gf_refreq] &) - -cdef gf_block_refreq as_gf_block_refreq (G) except + -cdef make_BlockGfReFreq (gf_block_refreq G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/OLD/refreq.pyx b/pytriqs/gf/local/OLD/refreq.pyx deleted file mode 100644 index 7b03b040..00000000 --- a/pytriqs/gf/local/OLD/refreq.pyx +++ /dev/null @@ -1,79 +0,0 @@ -from gf_refreq import GfReFreq - -cdef class GfReFreq_cython: - cdef gf_refreq _c - def __init__(self, MeshReFreq mesh, data, TailGf tail): - self._c = gf_refreq(mesh._c, array_view[dcomplex,THREE](data), tail._c, nothing()) - - def __write_hdf5_cython__ (self, gr , char * key) : - h5_write (make_h5_group(gr), key, self._c) - - def set_from_fourier(self, GfReTime_cython gt) : - """Fills self with the Fourier transform of gt""" - self._c << fourier( gt._c ) - - # put if back with make_gf_from_fourier when approved - #def inverse_fourier(self): - # return make_GfReTime(inverse_fourier(self._c)) - - def set_from_pade(self, GfImFreq_cython gw, n_points = 100, freq_offset = 0.0) : - pade(self._c, gw._c, n_points, freq_offset) - - def __dealloc__ (self): - pass - -#---------------- Reading from h5 --------------------------------------- - -def h5_read_GfReFreq(gr, key): - try: - indicesL = gr[key]['indices']['left'] - indicesR = gr[key]['indices']['right'] - pack = [indicesL, indicesR] - except: - pack = [] - try: - name = gr[key]['name'] - except: - name = key - return make_GfReFreq(h5_extractor[gf_refreq]()(make_h5_group(gr),key), pack, name) - -from pytriqs.archive.hdf_archive_schemes import register_class -register_class (GfReFreq, read_fun = h5_read_GfReFreq) - -#---------------- Convertions functions --------------------------------------- - -# Python -> C -cdef gf_refreq as_gf_refreq (g) except +: - return (g)._c - -# C -> Python. Do NOT add except + -cdef make_GfReFreq (gf_refreq x, indices_pack = [], name = "g"): - data = x.data().to_python() - if indices_pack == []: - indices_pack = [range(data.shape[1]), range(data.shape[2])] - return GfReFreq( - mesh = make_MeshReFreq (x.mesh()), - data = data, - tail = make_TailGf (x.singularity()), - indices_pack = indices_pack, - name = name) - -# Python -> C for blocks -cdef gf_block_refreq as_gf_block_refreq (G) except +: - cdef vector[gf_refreq] v_c - for n,g in G: - v_c.push_back(as_gf_refreq(g)) - return make_gf_block_refreq (v_c) - -# C -> Python for block -cdef make_BlockGfReFreq (gf_block_refreq G, block_indices_pack = [], name = "G"): - gl = [] - name_list = G.mesh().domain().names() - if block_indices_pack == []: - for i,n in enumerate(name_list): - sha = G[i].data().to_python().shape[1:3] - block_indices_pack.append( [range(sha[0]), range(sha[1])] ) - for i,n in enumerate(name_list): - gl.append( make_GfReFreq(G[i], block_indices_pack[i]) ) - return BlockGf( name_list = name_list, block_list = gl, name = name ) - diff --git a/pytriqs/gf/local/OLD/retime.pxd b/pytriqs/gf/local/OLD/retime.pxd deleted file mode 100644 index a271b1f6..00000000 --- a/pytriqs/gf/local/OLD/retime.pxd +++ /dev/null @@ -1,56 +0,0 @@ -cdef extern from "triqs/gfs/retime.hpp" namespace "triqs::gfs" : - - cdef cppclass retime_domain : - retime_domain() - - cdef cppclass mesh_retime "triqs::gfs::gf_mesh" : - mesh_retime () - mesh_retime (mesh_retime &) - retime_domain & domain() - double x_min() - double x_max() - long size() - long kind() - bint operator ==( mesh_retime &) - - cdef mesh_retime make_mesh_retime "triqs::gfs::gf_mesh" (double t_min, double t_max, size_t n_freq, mesh_enum mk) - #cdef mesh_retime make_mesh_retime "triqs::gfs::gf_factories::make_mesh" (double t_min, double t_max, size_t n_freq, mesh_enum mk) - - cdef cppclass gf_retime "triqs::python_tools::cython_proxy>" : - gf_retime() - gf_retime(gf_retime &) - # The constructor must be no_except, or the cython code won't be correct... - gf_retime(mesh_retime, array_view[dcomplex, THREE], tail, nothing) #except + - void operator << (gf_retime &) - mesh_retime mesh() - array_view[dcomplex, THREE] data() - tail singularity() - -cdef extern from "triqs/gfs/retime.hpp" : - cdef void h5_write (h5_group, char *, gf_retime &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_retime &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_retime &) - -# Python -> C -cdef gf_retime as_gf_retime (g) except + - -# C -> Python -cdef make_GfReTime (gf_retime x, indices_pack=*, name=*) - -############### Blocks of Im Time ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_retime "triqs::python_tools::cython_proxy>>" : - gf_block_retime() - gf_retime & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_retime make_gf_block_retime "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" (vector[gf_retime] &) - #cdef gf_block_retime make_gf_block_retime "triqs::gfs::make_gf_view>" ( vector[gf_retime] &) - -cdef gf_block_retime as_gf_block_retime (G) except + -cdef make_BlockGfReTime (gf_block_retime G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/OLD/retime.pyx b/pytriqs/gf/local/OLD/retime.pyx deleted file mode 100644 index 26212767..00000000 --- a/pytriqs/gf/local/OLD/retime.pyx +++ /dev/null @@ -1,76 +0,0 @@ -from gf_retime import GfReTime - -cdef class GfReTime_cython: - cdef gf_retime _c - def __init__(self, MeshReTime mesh, data, TailGf tail): - self._c = gf_retime(mesh._c, array_view[dcomplex,THREE](data), tail._c, nothing()) - - def __write_hdf5_cython__ (self, gr , char * key) : - h5_write (make_h5_group(gr), key, self._c) - - # Put it back ? - #def fourier(self): - # return make_GfReFreq(fourier(self._c)) - - def set_from_inverse_fourier(self, GfReFreq_cython gw) : - """Fills self with the Inverse Fourier transform of gw""" - self._c << inverse_fourier( gw._c) - - def __dealloc__ (self): - pass - -#---------------- Reading from h5 --------------------------------------- - -def h5_read_GfReTime(gr, key): - try: - indicesL = gr[key]['indices']['left'] - indicesR = gr[key]['indices']['right'] - pack = [indicesL, indicesR] - except: - pack = [] - try: - name = gr[key]['name'] - except: - name = key - return make_GfReTime(h5_extractor[gf_retime]()(make_h5_group(gr),key), pack, name) - -from pytriqs.archive.hdf_archive_schemes import register_class -register_class (GfReTime, read_fun = h5_read_GfReTime) - -#---------------- Convertions functions --------------------------------------- - -# Python -> C -cdef gf_retime as_gf_retime (g) except +: - return (g)._c - -# C -> Python. Do NOT add except + -cdef make_GfReTime (gf_retime x, indices_pack = [], name = "g"): - data = x.data().to_python() - if indices_pack == []: - indices_pack = [range(data.shape[1]), range(data.shape[2])] - return GfReTime( - mesh = make_MeshReTime (x.mesh()), - data = data, - tail = make_TailGf (x.singularity()), - indices_pack = indices_pack, - name = name) - -# Python -> C for blocks -cdef gf_block_retime as_gf_block_retime (G) except +: - cdef vector[gf_retime] v_c - for n,g in G: - v_c.push_back(as_gf_retime(g)) - return make_gf_block_retime (v_c) - -# C -> Python for block -cdef make_BlockGfReTime (gf_block_retime G, block_indices_pack = [], name = "G"): - gl = [] - name_list = G.mesh().domain().names() - if block_indices_pack == []: - for i,n in enumerate(name_list): - sha = G[i].data().to_python().shape[1:3] - block_indices_pack.append( [range(sha[0]), range(sha[1])] ) - for i,n in enumerate(name_list): - gl.append( make_GfReTime(G[i], block_indices_pack[i]) ) - return BlockGf( name_list = name_list, block_list = gl, name = name ) - diff --git a/pytriqs/gf/local/OLD/tail.pxd b/pytriqs/gf/local/OLD/tail.pxd deleted file mode 100644 index 1143871a..00000000 --- a/pytriqs/gf/local/OLD/tail.pxd +++ /dev/null @@ -1,37 +0,0 @@ -from dcomplex cimport * -from arrays cimport * -cdef extern from "triqs/gfs/local/tail.hpp" : - cdef cppclass tail "triqs::python_tools::cython_proxy" : - tail() - tail(array_view[dcomplex,THREE], array_view[long,TWO], long) except + - matrix_view[dcomplex] operator()(int) except + - array_view[dcomplex,THREE] data() - array_view[long,TWO] mask_view() except + - void operator << (tail &) except + - void operator << (dcomplex &) except + - long order_min() except + - long order_max() except + - size_t size() except + - size_t shape(int) except + - - cdef tail operator +( tail &, tail &) except + - cdef tail operator -( tail &, tail &) except + - - cdef tail operator *( tail&, tail &) except + - - cdef tail operator *( double, tail &) except + - cdef tail operator *( tail &, double) except + - cdef tail operator /( double, tail &) except + - cdef tail operator /( tail &, double) except + - - cdef tail operator *( dcomplex, tail &) except + - cdef tail operator *( tail &, dcomplex) except + - cdef tail operator /( dcomplex, tail &) except + - cdef tail operator /( tail &, dcomplex) except + - cdef tail inverse_c "inverse" ( tail &) except + - - cdef void h5_write (h5_group, char *, tail &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (tail &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, tail &) diff --git a/pytriqs/gf/local/OLD/tail.pyx b/pytriqs/gf/local/OLD/tail.pyx index c5f9e05f..fbba8a69 100644 --- a/pytriqs/gf/local/OLD/tail.pyx +++ b/pytriqs/gf/local/OLD/tail.pyx @@ -8,19 +8,7 @@ cdef class TailGf: TailGf ( shape ) TailGf ( data, mask, order_min ) """ - c_obj = d.pop('encapsulated_c_object', None) - if c_obj : - assert d == {} - self._c = extractor [tail] (c_obj) () - return - - bss = d.pop('boost_serialization_string', None) - if bss : - assert d == {}, "Internal error : boost_serialization_string must be the only argument" - boost_unserialize_into(bss,self._c) - return - - # default values + # default values omin = -1 omax = 8 @@ -39,50 +27,12 @@ cdef class TailGf: self._c = tail(array_view[dcomplex,THREE](a), array_view[long,TWO](m), o) - #-------------- Reduction ------------------------------- - - def __reduce__(self): - return py_deserialize, (self.__class__,boost_serialize(self._c),) - - #-------------- Properties ------------------------------- - - property data : - """Access to the data array""" - def __get__(self) : - return self._c.data().to_python() - - property mask: - """Access to the mask""" - def __get__(self) : - return self._c.mask_view().to_python() - - property shape : - def __get__(self) : return self.data.shape[1:3] - - property order_min : - """Min order of the expansion""" - def __get__(self) : return self._c.order_min() - - property order_max : - """Max order of the expansion""" - def __get__(self) : return self._c.order_max() - property N1 : def __get__(self): return self.shape[0] property N2 : def __get__(self): return self.shape[1] - property size : - """Length of the expansion""" - def __get__(self) : return self._c.size() - - def copy(self) : - return self.__class__(data = self.data.copy(), mask = self.mask.copy()) - - def copy_from(self, TailGf T) : - self._c << T._c - def _make_slice(self, sl1, sl2): return self.__class__(data = self.data[:,sl1,sl2], mask = self.mask[sl1,sl2]) @@ -95,85 +45,13 @@ cdef class TailGf: else: return string.join([ "%s"%self[r]+ (" /" if r>0 else "") + " Om^%s"%(abs(r)) for r in range(omin, self.order_max+1) ] , " + ") - def __getitem__(self,i) : - """Returns the i-th coefficient of the expansion, or order Om^i""" - if not self.has_coef(i) : raise IndexError, "Index %s is out of range"%i - return self.data[i-self.order_min,:,:] - - def __setitem__(self,i, val) : - """Sets the i-th coefficient of the expansion, or order Om^i""" - if not self.has_coef(i) : raise IndexError, "Index %s is out of range"%i - self.data[i-self.order_min,:,:] = val - - def has_coef(self, i): - return (i >= self.order_min) and (i <= self.order_max) - def __call__(self, x) : val = 0.0 for n in range(self.order_min, self.order_max+1): val += self[n] * x**(-n) return val - - def invert(self) : - self._c << inverse_c (self._c) - - ######### arithmetic operations ################# - - def __iadd__(self, TailGf arg): - self._c << self._c + arg._c - return self - - def __add__(self, TailGf y): - cdef tail t = (self)._c + y._c - return make_TailGf(t) - #c = self.copy() - #c += y - #return c - - def __isub__(self, TailGf arg): - self._c << self._c - arg._c - return self - - def __sub__(self,TailGf y): - cdef tail t = (self)._c - y._c - return make_TailGf(t) - #c = self.copy() - #c -= y - #return c - - def __imul__(self,arg): - n = type(arg).__name__ - if n == 'TailGf' : - self._c << self._c * (arg)._c - elif descriptors.is_scalar(arg): - self._c << as_dcomplex(arg)* self._c - else : - raise RuntimeError, " argument type not recognized in imul for %s"%arg - return self - - def __mul__(self,arg): - c = self.copy() - c *= arg - return c - - def __idiv__(self,arg): - if descriptors.is_scalar(arg): - self._c << self._c / as_dcomplex(arg) - else: - raise RuntimeError, "rhs must be a scalar" - return self - - def __div__(self,arg): - c = self.copy() - c /= arg - return c #---- other operations ---- - - def zero(self) : - """Sets the expansion to 0""" - self._c << as_dcomplex(0.0) - def transpose (self) : """Transpose the array : new view as in numpy""" return TailGf(data=self.data.transpose(), mask=self.mask.transpose()) @@ -182,21 +60,5 @@ cdef class TailGf: """Transpose the array : new view as in numpy""" return TailGf(data=self.data.conjugate(), mask=self.mask) - def __write_hdf5__ (self, gr , char * key) : - h5_write (make_h5_group(gr), key, self._c) -#---------------- Reading from h5 --------------------------------------- - -def h5_read_TailGf( gr, std_string key) : - return make_TailGf( h5_extractor[tail]()(make_h5_group(gr),key)) - -from pytriqs.archive.hdf_archive_schemes import register_class -register_class (TailGf, read_fun = h5_read_TailGf) - -#----------------------------------------------------- -# C -> Python -#----------------------------------------------------- - -cdef inline make_TailGf ( tail x) : - return TailGf(encapsulated_c_object = encapsulate (&x)) diff --git a/pytriqs/gf/local/OLD/two_real_times.pxd b/pytriqs/gf/local/OLD/two_real_times.pxd deleted file mode 100644 index 27fbd795..00000000 --- a/pytriqs/gf/local/OLD/two_real_times.pxd +++ /dev/null @@ -1,59 +0,0 @@ -cdef extern from "triqs/gfs.hpp" namespace "triqs::gfs" : - - cdef cppclass two_real_times_domain : - two_real_times_domain() - - cdef cppclass mesh_two_real_times "triqs::gfs::gf_mesh" : - mesh_two_real_times () - mesh_two_real_times (mesh_two_real_times &) - two_real_times_domain & domain() - double x_min() - double x_max() - long size() - double kind() - bint operator ==( mesh_two_real_times &) - - cdef mesh_two_real_times make_mesh_two_real_times "triqs::gfs::gf_mesh" (double t_max, double n_time_slices) - - cdef mesh_retime & get_1d_mesh_from_2times_mesh "triqs::gfs::get_1d_mesh_from_2times_mesh" (mesh_two_real_times &) - - cdef cppclass gf_two_real_times "triqs::python_tools::cython_proxy>" : - gf_two_real_times() - gf_two_real_times(gf_two_real_times &) - # The constructor must be no_except, or the cython code won't be correct... - gf_two_real_times(mesh_two_real_times, array_view[dcomplex, THREE], nothing, nothing) #except + - void operator << (gf_two_real_times &) - mesh_two_real_times mesh() - array_view[dcomplex, THREE] data() - tail singularity() - - cdef gf_retime slice1d "triqs::gfs::slice" (gf_two_real_times &, double t) except + - -cdef extern from "triqs/gfs/two_real_times.hpp" : - cdef void h5_write (h5_group, char *, gf_two_real_times &) - -cdef extern from "triqs/utility/serialization.hpp" : - cdef std_string boost_serialize "triqs::serialize" (gf_two_real_times &) - cdef void boost_unserialize_into "triqs::deserialize_into_view" (std_string, gf_two_real_times &) - -# Python -> C -cdef gf_two_real_times as_gf_two_real_times (g) except + - -# C -> Python -cdef make_GfTwoRealTime (gf_two_real_times x, indices_pack=*, name=*) - -############### Blocks of Im Time ######################### - -cdef extern from "triqs/gfs/block.hpp" namespace "triqs::gfs" : - - cdef cppclass gf_block_two_real_times "triqs::python_tools::cython_proxy>>" : - gf_block_two_real_times() - gf_two_real_times & operator [](int) - discrete_mesh & mesh() - - cdef gf_block_two_real_times make_gf_block_two_real_times "triqs::gfs::make_block_gf_view_from_vector_of_cython_proxy>" ( vector[gf_two_real_times] &) - #cdef gf_block_two_real_times make_gf_block_two_real_times "triqs::gfs::make_gf_view>" ( vector[gf_two_real_times] &) - -cdef gf_block_two_real_times as_gf_block_two_real_times (G) except + -cdef make_BlockGfTwoRealTime (gf_block_two_real_times G, block_indices_pack=*, name=*) - diff --git a/pytriqs/gf/local/gf_desc.py b/pytriqs/gf/local/gf_desc.py index 3990a2e5..13732343 100644 --- a/pytriqs/gf/local/gf_desc.py +++ b/pytriqs/gf/local/gf_desc.py @@ -20,7 +20,7 @@ t = class_( py_type = "TailGf", is_printable= True, arithmetic = ("algebra","double") ) - + t.add_constructor(signature = "(int N1, int N2, int size=10, int order_min=-1)", doc = "DOC of constructor") #t.add_constructor(doc = "DOC of constructor", signature = "(array_view d, array_view m, long i)", python_precall = "tail_aux.tail_construct") @@ -68,7 +68,7 @@ t.add_call(calling_pattern = "auto result = self_c.evaluate(u)", t.number_protocol['multiply'].add_overload(calling_pattern = "*", signature = "tail(matrix x,tail_view y)") #'x'), (self.c_type,'y')], rtype = self.c_type) t.number_protocol['multiply'].add_overload(calling_pattern = "*", signature = "tail(tail_view x,matrix y)") #'x'), (self.c_type,'y')], rtype = self.c_type) - + # ok, but MISSING CHECK SIZE t.add_getitem(c_name = "operator()", signature = "matrix_view(int i)", @@ -122,14 +122,10 @@ def make_mesh( py_type, c_tag, has_kind=True, is_im=False) : getter = cfunction(calling_pattern="mesh_kind result = self_c.kind()", signature = "mesh_kind()"), doc = "") - #def __richcmp__(MeshImFreq self, MeshImFreq other,int op) : # if op ==2 : # == # return self._c == other._c - #def __reduce__(self): - # return self.__class__, (self.beta, self.statistic, len(self)) - return m ######################## @@ -290,18 +286,23 @@ def make_gf( py_type, c_tag, is_complex_data = True, is_im = False) : g.number_protocol['inplace_lshift'] = pyfunction(py_name ="__inplace_lshift__", python_precall = "pytriqs.gf.local._gf_common._ilshift_", arity = 2) g.add_method(py_name = "invert", calling_pattern = "invert_in_place(self_c)" , signature = "void()", doc = "Invert (in place)") - - if c_tag != "imtime" : + + g.add_method(py_name = "transpose", + calling_pattern = "auto result = transpose(self_c)", + signature = "gf<%s>()"%c_tag, + doc = "Returns a NEW gf, with transposed data...") + + if c_tag != "imtime" : g.add_method(py_name = "conjugate", calling_pattern = "auto result = conj(self_c)" , signature = "gf<%s>()"%c_tag, doc = "Return a new function, conjugate of self.") g.number_protocol['multiply'].add_overload(calling_pattern = "*", signature = "gf<%s>(matrix<%s> x,gf<%s> y)"%(c_tag,data_type,c_tag)) #'x'), (self.c_type,'y')], rtype = self.c_type) g.number_protocol['multiply'].add_overload(calling_pattern = "*", signature = "gf<%s>(gf<%s> x,matrix<%s> y)"%(c_tag,c_tag,data_type)) #'x'), (self.c_type,'y')], rtype = self.c_type) - - g.add_method(py_name = "from_L_G_R", - calling_pattern = "self_c = L_G_R(l,g,r)", - signature = "void(matrix<%s> l,gf<%s> g,matrix<%s> r)"%(data_type,c_tag,data_type), + + g.add_method(py_name = "from_L_G_R", + calling_pattern = "self_c = L_G_R(l,g,r)", + signature = "void(matrix<%s> l,gf<%s> g,matrix<%s> r)"%(data_type,c_tag,data_type), doc = "self <<= l * g * r") - + g.add_method(py_name = "zero", calling_pattern = "self_c = 0", signature = "void()", @@ -353,6 +354,9 @@ g.add_method(py_name = "set_from_inverse_fourier", calling_pattern = "self_c = inverse_fourier(*gw)", doc = """Fills self with the Inverse Fourier transform of gw""") +# add the call operator using the interpolation +g.add_call(signature = "matrix(double tau)", doc = "G(tau) using interpolation") + module.add_class(g) ######################## @@ -397,4 +401,4 @@ module.add_function(name = "make_gf_from_inverse_fourier", signature="gf_view - -using namespace triqs::arrays; -using namespace triqs; - -int main() { - - clef::placeholder<0> i_; - clef::placeholder<1> j_; - clef::placeholder<2> k_; - - { - std::cerr<< "------------- Testing inversion ---------------"<< std::endl; - array A(4,2,2); - - A(k_,i_,j_) << clef::if_else(i_ == j_, i_ + k_+1, 0); // + 2.3* j_; - - matrix_stack_view S (std::move(A)); - - std::cout << S(0) << S(1)<< S(2) << std::endl ; - - S.invert(); - std::cout << S(0) << S(1)<< S(2)<< std::endl ; - } - - { - std::cerr<< "------------- Testing += matrix ---------------"<< std::endl; - array A(4,2,3); - matrix M(2,3); M()= 1; - - A(k_,i_,j_) << i_ + 2*j_ + k_/2.0; - - matrix_stack_view S (std::move(A)); - - std::cout << S(0) << S(1)<< S(2) << std::endl ; - - S += M; - std::cout << S(0) << S(1)<< S(2)<< std::endl ; - } - - { - std::cerr<< "------------- Testing += me---------------"<< std::endl; - array A(4,2,3); - matrix M(2,3); M()= 1; - - A(k_,i_,j_) << i_ + 2*j_ + k_/2.0; - - matrix_stack_view S (std::move(A)); - - std::cout << S(0) << S(1)<< S(2) << std::endl ; - - S += S; - std::cout << S(0) << S(1)<< S(2)<< std::endl ; - } -{ - std::cerr<< "------------- Testing *= 2---------------"<< std::endl; - array A(4,2,3); - matrix M(2,3); M()= 1; - - A(k_,i_,j_) << i_ + 2*j_ + k_/2.0; - - matrix_stack_view S (std::move(A)); - - std::cout << S(0) << S(1)<< S(2) << std::endl ; - - S *= 2; - std::cout << S(0) << S(1)<< S(2)<< std::endl ; - } - - -{ - std::cerr<< "------------- Testing R, L mul ---------------"<< std::endl; - array A(4,3,3); - matrix L(2,3); L()= 2; - matrix R(3,2); R()= 3; - - A(k_,i_,j_) << i_ + 2*j_ + k_/2.0; - - matrix_stack_view S (std::move(A)); - - std::cout << S(0) << S(1)<< S(2) << std::endl ; - - auto Sb = matmul_L_R(L,S,R); - std::cout << Sb(0) << Sb(1)<< Sb(2)<< std::endl ; - std::cout << S(0) << std::endl ; - } - -} diff --git a/triqs/arrays/array.hpp b/triqs/arrays/array.hpp index 1db3ac36..b53aafc7 100644 --- a/triqs/arrays/array.hpp +++ b/triqs/arrays/array.hpp @@ -95,8 +95,11 @@ namespace triqs { namespace arrays { TRIQS_DEFINE_COMPOUND_OPERATORS(array_view); // to forbid serialization of views... //template void serialize(Archive & ar, const unsigned int version) = delete; - - }; + + template friend array_view transposed_view(array_view const& a, INT... is) { + return array_view{transpose(a.indexmap_, is...), a.storage_}; + } + }; #undef IMPL_TYPE @@ -213,6 +216,13 @@ namespace triqs { namespace arrays { TRIQS_DEFINE_COMPOUND_OPERATORS(array); + template friend const_view_type transposed_view(array const& a, INT... is) { + return view_type{transpose(a.indexmap_, is...), a.storage_}; + }; + template friend view_type transposed_view(array& a, INT... is) { + return view_type{transpose(a.indexmap_, is...), a.storage_}; + }; + };//array class #undef IMPL_TYPE diff --git a/triqs/arrays/indexmaps/cuboid/domain.hpp b/triqs/arrays/indexmaps/cuboid/domain.hpp index 1b571e55..90727b6d 100644 --- a/triqs/arrays/indexmaps/cuboid/domain.hpp +++ b/triqs/arrays/indexmaps/cuboid/domain.hpp @@ -48,10 +48,9 @@ namespace triqs { namespace arrays { namespace indexmaps { namespace cuboid { domain_t () =default; domain_t (const domain_t & C) = default; - domain_t (domain_t && C) { *this = std::move(C);} - friend void swap( domain_t & a, domain_t & b) { swap(a.lengths_,b.lengths_);} + domain_t (domain_t && C) = default; domain_t & operator =( domain_t const &) = default; - domain_t & operator =( domain_t && x) { swap(*this,x); return *this;} + domain_t & operator =( domain_t && x)= default; domain_t (n_uple lengths):lengths_(std::move(lengths)) {} domain_t (mini_vector const & lengths):lengths_(lengths) {} diff --git a/triqs/arrays/indexmaps/cuboid/map.hpp b/triqs/arrays/indexmaps/cuboid/map.hpp index 585477aa..c2d7b4e1 100644 --- a/triqs/arrays/indexmaps/cuboid/map.hpp +++ b/triqs/arrays/indexmaps/cuboid/map.hpp @@ -60,31 +60,36 @@ namespace triqs { namespace arrays { namespace indexmaps { namespace cuboid { typedef domain_t domain_type; domain_type const & domain() const { return mydomain;} - // basic construction - map (memory_layout const & ml = memory_layout(traversal_order)):mydomain(), start_shift_(0), memory_order_(ml) {} - map(domain_type const & C): mydomain(C), start_shift_(0), memory_order_(traversal_order) {compute_stride_compact();} - map(domain_type const & C, memory_layout ml): mydomain(C), start_shift_(0), memory_order_(ml) {compute_stride_compact();} - - /// Construction from the length, the stride, start_shift - map(lengths_type const & Lengths, strides_type const & strides, std::ptrdiff_t start_shift ): - mydomain(Lengths), strides_(strides), start_shift_(start_shift), - memory_order_ (memory_layout_from_strides(strides_)) {} - - /// Construction from the length, the stride, start_shift - map(lengths_type && Lengths, strides_type && strides, std::ptrdiff_t start_shift ): - mydomain(std::move(Lengths)), strides_(std::move(strides)), start_shift_(start_shift), - memory_order_ (memory_layout_from_strides(strides_)) {} - - /// Construction from another map with the same order (used in grouping indices) - template map (map const & C): - mydomain(C.domain()), strides_(C.strides()), start_shift_(C.start_shift()), memory_order_ (C.memory_indices_layout()) {} - - // regular type + // semi-regular type + map (): start_shift_(0), memory_order_(memory_layout(traversal_order)) {} map (map const & C) = default; map (map && C) = default; map & operator = (map const & m) = default; map & operator = (map && m) = default; + // basic construction + map(memory_layout const & ml):mydomain(), start_shift_(0), memory_order_(ml) {} + map(domain_type const & C): mydomain(C), start_shift_(0), memory_order_(traversal_order) {compute_stride_compact();} + map(domain_type const & C, memory_layout ml): mydomain(C), start_shift_(0), memory_order_(ml) {compute_stride_compact();} + + /// Construction from the length, the stride, start_shift + map(lengths_type Lengths, strides_type strides, std::ptrdiff_t start_shift ): + mydomain(std::move(Lengths)), strides_(std::move(strides)), start_shift_(start_shift), + memory_order_ (memory_layout_from_strides(strides_)) {} + + /// Construction from the length, the stride, start_shift, ml + map(lengths_type Lengths, strides_type strides, std::ptrdiff_t start_shift, memory_layout const & ml ): + mydomain(std::move(Lengths)), strides_(std::move(strides)), start_shift_(start_shift), memory_order_ (ml) {} + + /// Construction from another map with the same order (used in grouping indices) + template map (map const & C): + mydomain(C.domain()), strides_(C.strides()), start_shift_(C.start_shift()), memory_order_ (C.memory_indices_layout()) {} + + // transposition + template friend map transpose(map const& m, INT... is) { + return map{{m.domain().lengths()[is]...}, {m.strides_[is]...}, m.start_shift_, transpose(m.memory_order_, is...)}; + } + /// Returns the shift in position of the element key. template size_t operator[] (KeyType const & key ) const { @@ -192,6 +197,9 @@ namespace triqs { namespace arrays { namespace indexmaps { namespace cuboid { }; }; //------------- end class --------------------- + + + }//namespace cuboid template diff --git a/triqs/arrays/indexmaps/cuboid/mem_layout.hpp b/triqs/arrays/indexmaps/cuboid/mem_layout.hpp index 873a72e9..f8c83e96 100644 --- a/triqs/arrays/indexmaps/cuboid/mem_layout.hpp +++ b/triqs/arrays/indexmaps/cuboid/mem_layout.hpp @@ -65,8 +65,6 @@ namespace triqs { namespace arrays { template< int rank, ull_t fl, ull_t to> struct get_traversal_order { static constexpr ull_t value = _get_traversal_order (rank,fl,to); }; }} - - struct memory_layout_fortran {}; struct memory_layout_c {}; @@ -90,18 +88,23 @@ namespace triqs { namespace arrays { static_assert( sizeof...(in)==Rank-2, "Error"); } memory_layout (const memory_layout & C) = default; - memory_layout (memory_layout && C) { *this = std::move(C);} - friend void swap( memory_layout & a, memory_layout & b){ std::swap(a.value,b.value);} + memory_layout (memory_layout && C) = default; memory_layout & operator =( memory_layout const &) = default; - memory_layout & operator =( memory_layout && x) { swap(*this,x); return *this;} + memory_layout & operator =( memory_layout && x) = default; bool operator ==( memory_layout const & ml) const { return value == ml.value;} bool operator !=( memory_layout const & ml) const { return value != ml.value;} - friend std::ostream & operator <<( std::ostream & out, memory_layout const & s) { permutations::print(out,s.value); return out;} + friend std::ostream &operator<<(std::ostream &out, memory_layout const &s) { + permutations::print(out, s.value); + return out; + + } }; - //template void swap( memory_layout & a, memory_layout & b) { std::swap(a.value,b.value);} - + template memory_layout transpose(memory_layout ml, INT... is) { + static_assert(sizeof...(INT)==R, "!"); + return memory_layout{permutations::compose(ml.value, permutations::inverse(permutations::permutation(is...)))}; + } }}//namespace triqs::arrays #endif diff --git a/triqs/arrays/matrix_stack_view.hpp b/triqs/arrays/matrix_stack_view.hpp deleted file mode 100644 index 39f1b42c..00000000 --- a/triqs/arrays/matrix_stack_view.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * - * TRIQS: a Toolbox for Research in Interacting Quantum Systems - * - * Copyright (C) 2013 by O. Parcollet - * - * TRIQS is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * TRIQS. If not, see . - * - ******************************************************************************/ -#ifndef TRIQS_ARRAYS_MATRIX_STACK_VIEW_H -#define TRIQS_ARRAYS_MATRIX_STACK_VIEW_H -#include "./array.hpp" -#include "./matrix.hpp" -#include "./matrix_tensor_proxy.hpp" -#include - -namespace triqs { namespace arrays { - - template class matrix_stack_view { - array_view a; - public: - typedef array_view array_view_t; - - matrix_stack_view( typename array_view_t::view_type const & a_):a(a_) {} - matrix_stack_view( array_view_t && a_):a(std::move(a_)) {} - -#ifdef TRIQS_WITH_PYTHON_SUPPORT - /// Build from a numpy.array (X is a borrowed reference) : throws if X is not a numpy.array - explicit matrix_stack_view (PyObject * X):a(typename array_view_t::view_type (X)){} -#endif - - //matrix_view_proxy operator()(size_t i) { return matrix_view_proxy (a,i);} - //const_matrix_view_proxy operator()(size_t i) const { return const_matrix_view_proxy (a,i);} - auto operator()(long i) DECL_AND_RETURN(make_matrix_proxy(this->a, i)); - auto operator()(long i) const DECL_AND_RETURN(make_const_matrix_proxy(this->a, i)); - - matrix_view view(size_t i) const { return a(i,range(),range());} - - size_t size() const { return a.shape(0);} - // BE CAREFUL to the shift : it is 1, 2, not 0,1, because of the stack ! - friend size_t first_dim (matrix_stack_view const & m) { return second_dim(m.a);} - friend size_t second_dim (matrix_stack_view const & m) { return third_dim(m.a);} - - matrix_stack_view & operator +=(matrix_stack_view const & arg) { a += arg.a; return *this; } - matrix_stack_view & operator -=(matrix_stack_view const & arg) { a -= arg.a; return *this; } - - template - typename std::enable_if::type - operator +=(RHS const & arg) { for (size_t i=0; i - typename std::enable_if::type - operator -=(RHS const & arg) { for (size_t i=0; i matrix_stack_view & operator *=(RHS const & arg) { a*= arg; return *this; } - template matrix_stack_view & operator /=(RHS const & arg) { a/= arg; return *this; } - - void invert() {for (size_t i=0; i const & L, matrix_stack_view const & M, matrix_view const & R) { - matrix_stack_view res (typename array_view_t::regular_type (M.size(), first_dim(L), second_dim(R))); - for (size_t i=0; i const & L, matrix_stack_view const & M, matrix_view const & R) { - if ((first_dim(*this) != first_dim(L)) || (second_dim(*this) != second_dim(R)) || (second_dim(L) != first_dim(R))) - TRIQS_RUNTIME_ERROR << "dimensions do not match!"; - for (size_t i=0; i - gf_view invert_in_place(gf_view g) { - return { g.mesh(), transpose( g.data(), xxxx), transpose(g.singularity()), g.symmetry(), g.indices() XXX, g.name}; - } -*/ + // ---- transpose : a new gf + template + gf transpose(gf_view g) { + return {g.mesh(), transposed_view(g.data(), 0, 2, 1), transpose(g.singularity()), g.symmetry(), transpose(g.indices()), g.name}; + } + // ---- conjugate : always a new function -> changelog template gf conj(gf_view g) { diff --git a/triqs/gfs/local/tail.hpp b/triqs/gfs/local/tail.hpp index d017e578..f8dcbfed 100644 --- a/triqs/gfs/local/tail.hpp +++ b/triqs/gfs/local/tail.hpp @@ -281,6 +281,8 @@ namespace triqs { namespace gfs { namespace local { inline tail conj(tail_view t) { return {conj(t.data()), t.mask_view(),t.order_min()};} + inline tail transpose(tail_view t) { return {transposed_view(t.data(),0,2,1), transposed_view(t.mask_view(),1,0),t.order_min()};} + /// Slice in orbital space //template tail_view slice_target(tail_impl const & t, tqa::range R1, tqa::range R2) { inline tail_view slice_target(tail_view t, tqa::range R1, tqa::range R2) { diff --git a/triqs/gfs/tools.hpp b/triqs/gfs/tools.hpp index cb583954..6382aa36 100644 --- a/triqs/gfs/tools.hpp +++ b/triqs/gfs/tools.hpp @@ -142,6 +142,16 @@ namespace gfs { TRIQS_RUNTIME_ERROR << "Not implemented : slice of string indices"; } + inline indices_2 transpose(indices_2 const &x) { + auto ind2 = x.ind; + if (x.ind.size() > 0) { + int im = x.ind.size(), jm = x.ind[0].size(); + for (int i = 0; i < im; ++i) + for (int j = 0; j < jm; ++j) ind2[i][j] = x.ind[j][i]; + } + return indices_2(std::move(ind2)); + } + //------------------------------------------------------ // A simple replacement of tail when there is none to maintain generic code simple... @@ -162,6 +172,7 @@ namespace gfs { template bool check_size(A) {return true;} }; + inline nothing transpose(nothing) { return {};} template nothing slice_target(nothing, T...) { return nothing(); } template nothing operator+(nothing, T const &) { return nothing(); } template nothing operator-(nothing, T const &) { return nothing(); } diff --git a/triqs/python_tools/wrapper_tools.hpp b/triqs/python_tools/wrapper_tools.hpp index abba8030..a422189d 100644 --- a/triqs/python_tools/wrapper_tools.hpp +++ b/triqs/python_tools/wrapper_tools.hpp @@ -1,4 +1,5 @@ -#pragma once + + #pragma once #include #include "structmember.h" #include @@ -198,11 +199,14 @@ template <> struct py_converter { template <> struct py_converter> { static PyObject *c2py(std::complex x) { return PyComplex_FromDoubles(x.real(), x.imag()); } static std::complex py2c(PyObject *ob) { - auto r = PyComplex_AsCComplex(ob); - return {r.real, r.imag}; + if (PyComplex_Check(ob)) { + auto r = PyComplex_AsCComplex(ob); + return {r.real, r.imag}; + } + return PyFloat_AsDouble(ob); } static bool is_convertible(PyObject *ob, bool raise_exception) { - if (PyComplex_Check(ob)) return true; + if (PyComplex_Check(ob) || PyFloat_Check(ob) || PyInt_Check(ob)) return true; if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Can not convert to complex");} return false; }