Fixed segment resize that wasn't updating data/style attrs in DefaultSegment

This commit is contained in:
Rob McMullen 2017-05-02 16:17:45 -07:00
parent a739b19cf2
commit 3efb3d1afa
2 changed files with 32 additions and 14 deletions

View File

@ -3,7 +3,6 @@ import cStringIO
import uuid
import numpy as np
from profilehooks import coverage
from errors import *
from utils import to_numpy, to_numpy_list
@ -170,6 +169,8 @@ class SegmentData(object):
else:
self.data = newdata
self.style = newstyle
else:
raise ValueError("Can't resize a view of a segment")
def replace_arrays(self, base_raw):
newsize = len(base_raw)
@ -365,13 +366,16 @@ class DefaultSegment(object):
def set_raw(self, rawdata):
self.rawdata = rawdata
self.data = rawdata.get_data()
self.style = rawdata.get_style()
self._search_copy = None
self.update_raw_pointers()
def get_raw(self):
return self.rawdata
def update_raw_pointers(self):
self.data = self.rawdata.get_data()
self.style = self.rawdata.get_style()
self._search_copy = None
def resize(self, newsize, zeros=True):
""" Resize the data arrays.
@ -404,6 +408,7 @@ class DefaultSegment(object):
def replace_data(self, container):
self.rawdata.replace_arrays(container.rawdata)
self.update_raw_pointers()
def __getstate__(self):
"""Custom jsonpickle state save routine

View File

@ -349,29 +349,39 @@ class TestResize(object):
self.container.can_resize = True
def test_subset(self):
# check to see data a view of some rawdata will be the same when the
# rawdata is resized.
c = self.container
assert not c.rawdata.is_indexed
offset = 1000
s = DefaultSegment(c.rawdata[offset:offset + offset], 0)
assert not s.rawdata.is_indexed
# Check that the small view has the same data as its parent
for i in range(offset):
assert s[i] == c[i + offset]
requested = 8192
# keep a copy of the old raw data of the subset
oldraw = s.rawdata.copy()
oldid = id(s.rawdata)
requested = 8192
oldsize, newsize = c.resize(requested)
assert newsize == requested
s.replace_data(c)
assert id(s.rawdata) == oldid
assert id(oldraw.order) == id(s.rawdata.order)
for i in range(offset):
s.replace_data(c) # s should point to the same offset in the resized data
assert id(s.rawdata) == oldid # segment rawdata object should be same
assert id(oldraw.order) == id(s.rawdata.order) # order the same
for i in range(offset): # check values compared to parent
assert s[i] == c[i + offset]
# check for changes in parent/view reflected so we see that it's
# pointing to the same array in memory
newbase = c.rawdata
newsub = s.rawdata
print c.rawdata.data
print c.rawdata.data[offset:offset+offset]
print s.rawdata.data[:]
s.rawdata.data[:] = 111
print c.rawdata.data
print c.rawdata.data[offset:offset+offset]
print s.rawdata.data[:]
for i in range(offset):
assert s[i] == c[i + offset]
@ -411,11 +421,14 @@ if __name__ == "__main__":
# t.test_indexed()
# t.test_indexed_sub()
# t.test_interleave()
t = TestSegment1()
t.setup()
t.test_xex()
# t = TestSegment1()
# t.setup()
# t.test_xex()
# t.test_copy()
# t = TestComments()
# t.setup()
# t.test_split_data_at_comment()
# t.test_restore_comments()
t = TestResize()
t.setup()
t.test_subset()