[devel] pickling files...

This commit is contained in:
mzwiessele 2015-11-05 09:27:59 +00:00
parent 5d605277bc
commit 0fb7cf2ff3
4 changed files with 33 additions and 25 deletions

View file

@ -14,9 +14,16 @@ from . import testing
from . import kern
from . import plotting
# backwards compatibility
import sys
backwards_compatibility = ['lists_and_dicts', 'observable_array', 'ties_and_remappings', 'index_operations']
for bc in backwards_compatibility:
sys.modules['GPy.core.parameterization.{!s}'.format(bc)] = getattr(core.parameterization, bc)
# Direct imports for convenience:
from .core import Model
from GPy.core.parameterization import priors
from .core.parameterization import priors
from paramz import Param, Parameterized, ObsAr, transformations as constraints
from .__version__ import __version__
@ -40,27 +47,23 @@ def load(file_or_path):
:param file_name: path/to/file.pickle
"""
# This is the pickling pain when changing _src -> src
import inspect
sys.modules['GPy.kern._src'] = kern.src
for name, module in inspect.getmembers(kern.src):
if not name.startswith('_'):
sys.modules['GPy.kern._src.{}'.format(name)] = module
try:
try:
import cPickle as pickle
if isinstance(file_or_path, basestring):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else:
m = pickle.load(file_or_path)
except:
import pickle
if isinstance(file_or_path, str):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else:
m = pickle.load(file_or_path)
except ImportError:
import sys
import inspect
sys.modules['GPy.kern._src'] = kern.src
for name, module in inspect.getmembers(kern.src):
if not name.startswith('_'):
sys.modules['GPy.kern._src.{}'.format(name)] = module
m = load(file_or_path)
import cPickle as pickle
if isinstance(file_or_path, basestring):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else:
m = pickle.load(file_or_path)
except:
import pickle
if isinstance(file_or_path, str):
with open(file_or_path, 'rb') as f:
m = pickle.load(f)
else:
m = pickle.load(file_or_path)
return m