mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-11-29 11:51:14 +00:00
Changed IndexedByteSegment to use numpy array as order so fancy indexing works in __getitem__
This commit is contained in:
parent
cfaca75052
commit
18a12c0225
@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
|
||||
from errors import *
|
||||
from utils import to_numpy_list
|
||||
|
||||
|
||||
class SegmentSaver(object):
|
||||
@ -264,7 +265,8 @@ class IndexedStyleWrapper(object):
|
||||
|
||||
class IndexedByteSegment(DefaultSegment):
|
||||
def __init__(self, data, style, byte_order, **kwargs):
|
||||
self.order = byte_order
|
||||
# Convert to numpy list so fancy indexing works as argument to __getitem__
|
||||
self.order = to_numpy_list(byte_order)
|
||||
DefaultSegment.__init__(self, data, IndexedStyleWrapper(style, byte_order), 0, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -9,3 +9,9 @@ def to_numpy(value):
|
||||
elif type(value) is types.StringType:
|
||||
return np.fromstring(value, dtype=np.uint8)
|
||||
raise TypeError("Can't convert to numpy data")
|
||||
|
||||
|
||||
def to_numpy_list(value):
|
||||
if type(value) is np.ndarray:
|
||||
return value
|
||||
return np.asarray(value, dtype=np.uint32)
|
||||
|
Loading…
Reference in New Issue
Block a user