## [83bb88]: PDSim / core / _core.pyx Maximize Restore History

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 63 64 65 66 67 68 69 70 71 72 73 74``` ```from __future__ import division import cython cimport cython import numpy as np cimport numpy as np from PDSim.misc.datatypes import arraym from PDSim.misc.datatypes cimport arraym cpdef list getcol(np.ndarray[np.float_t, ndim=2] mat, int colIndex, list indices): cdef int i,j cdef list values = [] for i in indices: values.append(mat[i,colIndex]) #print 'getcol,i=',i,'indices=',indices,'vals=',values return values cpdef setcol(np.ndarray[np.float_t, ndim=2] mat, int colIndex, list indices, arraym x): cdef int i,j cdef double val if not len(indices) == len(x): print 'indices:',indices, 'x:',x raise ValueError('Length of indices [{0:d}] and x [{1:d}] are not the same'.format(len(indices),len(x))) for j in range(len(x)): i = indices[j] val = x[j] mat[i,colIndex]=val return None cpdef delimit_vector(np.ndarray[np.float_t, ndim = 1] x, np.ndarray[np.float_t, ndim = 1] y): """ Break vectors into continuous chunks of real values as needed by splitting based on the y numpy array Parameters ---------- x : numpy array May not contain NAN values y : numpy array """ #Return the arrays back if there are no NAN values in y if not np.any(np.isnan(y)): return [x],[y] #A list of all the transitions between NAN and non-NAN values in y vector #Values are the indices at the left indices = list(np.where(np.diff(np.isnan(y)))[0]) segments = [] if not np.isnan(y[0]): segments.append((0,indices[0])) keep = False else: keep = True for i in range(len(indices)-1): if keep: segments.append((indices[i]+1,indices[i+1])) #Flip the keep flag keep = not keep if indices[-1] < len(y)-1: if keep: segments.append((indices[-1]+1,len(y)-1)) return [x[L:R+1] for L,R in segments], [y[L:R+1] for L,R in segments] cdef class _PDSimCore: pass ```