Changed IndexedByteSegment to use numpy array as order so fancy indexing works in __getitem__

This commit is contained in:
Rob McMullen 2016-02-18 10:17:21 -08:00
parent cfaca75052
commit 18a12c0225
2 changed files with 9 additions and 1 deletions

View File

@ -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):

View File

@ -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)