mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2025-01-04 00:29:36 +00:00
Added copy function to raw data
This commit is contained in:
parent
476f0cd568
commit
bd4ff9569a
@ -97,6 +97,10 @@ class OrderWrapper(object):
|
|||||||
"""
|
"""
|
||||||
return self.order[index]
|
return self.order[index]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def shape(self):
|
||||||
|
return (len(self),)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unindexed(self):
|
def unindexed(self):
|
||||||
return self.np_data[self.order]
|
return self.np_data[self.order]
|
||||||
@ -217,6 +221,18 @@ class SegmentData(object):
|
|||||||
s = self.style[index]
|
s = self.style[index]
|
||||||
e = self.extra
|
e = self.extra
|
||||||
return SegmentData(d, s, e, order=order)
|
return SegmentData(d, s, e, order=order)
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
if self.is_indexed:
|
||||||
|
d = self.data.np_data.copy()
|
||||||
|
s = self.style.np_data.copy()
|
||||||
|
copy = SegmentData(d, s, order=self.order)
|
||||||
|
else:
|
||||||
|
d = self.data
|
||||||
|
s = self.style
|
||||||
|
start, end = self.byte_bounds_offset()
|
||||||
|
copy = SegmentData(d[start:end], s[start:end])
|
||||||
|
return copy
|
||||||
|
|
||||||
def get_bases(self):
|
def get_bases(self):
|
||||||
if self.data.base is None:
|
if self.data.base is None:
|
||||||
@ -226,7 +242,7 @@ class SegmentData(object):
|
|||||||
data_base = self.data.base
|
data_base = self.data.base
|
||||||
style_base = self.style.base
|
style_base = self.style.base
|
||||||
return data_base, style_base
|
return data_base, style_base
|
||||||
|
|
||||||
def get_indexed(self, index):
|
def get_indexed(self, index):
|
||||||
index = to_numpy_list(index)
|
index = to_numpy_list(index)
|
||||||
if self.is_indexed:
|
if self.is_indexed:
|
||||||
|
@ -16,7 +16,7 @@ class TestSegment1(object):
|
|||||||
def setup(self):
|
def setup(self):
|
||||||
self.segments = []
|
self.segments = []
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
data = np.ones([1024], dtype=np.uint8) * i
|
data = np.arange(1024, dtype=np.uint8) * i
|
||||||
r = SegmentData(data)
|
r = SegmentData(data)
|
||||||
self.segments.append(DefaultSegment(r, i * 1024))
|
self.segments.append(DefaultSegment(r, i * 1024))
|
||||||
|
|
||||||
@ -33,8 +33,16 @@ class TestSegment1(object):
|
|||||||
# 6 bytes for the last segment run address
|
# 6 bytes for the last segment run address
|
||||||
# 4 bytes per segment for start, end address
|
# 4 bytes per segment for start, end address
|
||||||
size = reduce(lambda a, b:a + 4 + len(b), s, 0)
|
size = reduce(lambda a, b:a + 4 + len(b), s, 0)
|
||||||
|
print size, len(bytes)
|
||||||
assert len(bytes) == 2 + 6 + size
|
assert len(bytes) == 2 + 6 + size
|
||||||
|
|
||||||
|
def test_copy(self):
|
||||||
|
for s in self.segments:
|
||||||
|
c = s.rawdata.copy()
|
||||||
|
print c.data.shape, c.is_indexed
|
||||||
|
print c.data.np_data, s.data.np_data
|
||||||
|
assert np.all((c.data - s.data) == 0)
|
||||||
|
|
||||||
|
|
||||||
class TestIndexed(object):
|
class TestIndexed(object):
|
||||||
def setup(self):
|
def setup(self):
|
||||||
@ -154,6 +162,17 @@ class TestIndexed(object):
|
|||||||
a[5::6] = s2[2::3]
|
a[5::6] = s2[2::3]
|
||||||
assert np.array_equal(s[:], a)
|
assert np.array_equal(s[:], a)
|
||||||
|
|
||||||
|
def test_copy(self):
|
||||||
|
s, indexes = get_indexed(self.segment, 1024, 3)
|
||||||
|
c = s.rawdata.copy()
|
||||||
|
print c.data.shape, c.is_indexed
|
||||||
|
print id(c.data.np_data), id(s.data.np_data)
|
||||||
|
assert c.data.shape == s.data.shape
|
||||||
|
assert id(c) != id(s)
|
||||||
|
assert np.all((c.data[:] - s.data[:]) == 0)
|
||||||
|
c.data[0:100] = 1
|
||||||
|
assert not np.all((c.data[:] - s.data[:]) == 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
t = TestIndexed()
|
t = TestIndexed()
|
||||||
@ -161,3 +180,7 @@ if __name__ == "__main__":
|
|||||||
t.test_indexed()
|
t.test_indexed()
|
||||||
t.test_indexed_sub()
|
t.test_indexed_sub()
|
||||||
t.test_interleave()
|
t.test_interleave()
|
||||||
|
#t = TestSegment1()
|
||||||
|
#t.setup()
|
||||||
|
#t.test_xex()
|
||||||
|
t.test_copy()
|
||||||
|
Loading…
Reference in New Issue
Block a user