From e49bef9b9486665ce3390835eced55b3964bddce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Zwie=C3=9Fele?= Date: Thu, 4 Sep 2014 17:30:06 +0100 Subject: [PATCH] [param] indexing fix, this can be memory intensive if millions of parameters --- GPy/core/parameterization/param.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/GPy/core/parameterization/param.py b/GPy/core/parameterization/param.py index d5822825..ff8cc638 100644 --- a/GPy/core/parameterization/param.py +++ b/GPy/core/parameterization/param.py @@ -246,24 +246,9 @@ class Param(Parameterizable, ObsAr): # get a int-array containing all indices in the first axis. if slice_index is None: slice_index = self._current_slice_ - if isinstance(slice_index, (tuple, list)): - clean_curr_slice = [s for s in slice_index if numpy.any(s != Ellipsis)] - for i in range(self._realndim_-len(clean_curr_slice)): - i+=1 - clean_curr_slice += [range(self._realshape_[i])] - if (all(isinstance(n, (numpy.ndarray, list, tuple)) for n in clean_curr_slice) - and len(set(map(len, clean_curr_slice))) <= 1): - return numpy.fromiter(itertools.izip(*clean_curr_slice), - dtype=[('', int)] * self._realndim_, count=len(clean_curr_slice[0])).view((int, self._realndim_)) - try: - expanded_index = list(self._expand_index(slice_index)) - indices = numpy.fromiter(itertools.product(*expanded_index), - dtype=[('', int)] * self._realndim_, count=reduce(lambda a, b: a * b.size, expanded_index, 1)).view((int, self._realndim_)) - except: - print "Warning: extended indexing was used" - indices = np.indices(self._realshape_, dtype=int) - indices = indices[(slice(None),)+slice_index] - indices = np.rollaxis(indices, 0, indices.ndim) + indices = np.indices(self._realshape_, dtype=int) + indices = indices[(slice(None),)+slice_index] + indices = np.rollaxis(indices, 0, indices.ndim) return indices def _max_len_names(self, gen, header): gen = map(lambda x: " ".join(map(str, x)), gen)