__init__.py 1.94 KB
Newer Older
Marco Selig's avatar
Marco Selig committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## NIFTY (Numerical Information Field Theory) has been developed at the
## Max-Planck-Institute for Astrophysics.
##
## Copyright (C) 2013 Max-Planck-Society
##
## Author: Marco Selig
## Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/>
##
## This program 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.
##
## This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import division
from nifty_core import *
Marco Selig's avatar
Marco Selig committed
24
25
from nifty_cmaps import *
from nifty_power import *
Marco Selig's avatar
Marco Selig committed
26
from nifty_tools import *
Marco Selig's avatar
Marco Selig committed
27
from nifty_explicit import *
Marco Selig's avatar
Marco Selig committed
28

Marco Selig's avatar
Marco Selig committed
29
#from nifty_power_conversion import *
Marco Selig's avatar
Marco Selig committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


##-----------------------------------------------------------------------------

import copy_reg as cr
from types import MethodType as mt


def _pickle_method(method):
    fct_name = method.im_func.__name__
    obj = method.im_self
    cl = method.im_class
    ## handle mangled function name
    if(fct_name.startswith("__"))and(not fct_name.endswith("__")):
        cl_name = cl.__name__.lstrip("_")
        fct_name = "_" + cl_name + fct_name
    return _unpickle_method, (fct_name, obj, cl)


def _unpickle_method(fct_name, obj, cl):
    for oo in cl.__mro__:
        try:
            fct = oo.__dict__[fct_name]
        except(KeyError):
            pass
        else:
            break
    return fct.__get__(obj, cl)

## enable instance methods pickling
cr.pickle(mt, _pickle_method, _unpickle_method)

##-----------------------------------------------------------------------------