Fix contiguous

This commit is contained in:
Valentin Valls 2019-04-08 13:20:08 +02:00
parent 8e9a2ac675
commit 2cf2ba3586
1 changed files with 3 additions and 0 deletions

View File

@ -110,6 +110,7 @@ class PeakModel(AbstractModel):
assert(isinstance(coords, numpy.ndarray)) assert(isinstance(coords, numpy.ndarray))
assert(len(coords.shape) == 2) assert(len(coords.shape) == 2)
assert(coords.shape[1] == 2) assert(coords.shape[1] == 2)
coords = numpy.ascontiguousarray(coords)
coords.flags['WRITEABLE'] = False coords.flags['WRITEABLE'] = False
self.__coords = coords self.__coords = coords
self.wasChanged() self.wasChanged()
@ -138,12 +139,14 @@ class PeakModel(AbstractModel):
# Convert to structured array to use setdiff1d # Convert to structured array to use setdiff1d
dtype = self.__coords.dtype.descr * self.__coords.shape[1] dtype = self.__coords.dtype.descr * self.__coords.shape[1]
previous_coords = self.__coords.view(dtype) previous_coords = self.__coords.view(dtype)
coords = numpy.ascontiguousarray(coords)
new_coords = coords.view(dtype) new_coords = coords.view(dtype)
new_coords = numpy.setdiff1d(previous_coords, new_coords) new_coords = numpy.setdiff1d(previous_coords, new_coords)
if len(new_coords) == 0: if len(new_coords) == 0:
return return
new_coords = new_coords.view(self.__coords.dtype) new_coords = new_coords.view(self.__coords.dtype)
self.__coords = numpy.vstack((self.__coords, new_coords)) self.__coords = numpy.vstack((self.__coords, new_coords))
self.__coords = numpy.ascontiguousarray(self.__coords)
self.wasChanged() self.wasChanged()
def ringNumber(self): def ringNumber(self):