mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-12-01 09:49:42 +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
|
import numpy as np
|
||||||
|
|
||||||
from errors import *
|
from errors import *
|
||||||
|
from utils import to_numpy_list
|
||||||
|
|
||||||
|
|
||||||
class SegmentSaver(object):
|
class SegmentSaver(object):
|
||||||
@ -264,7 +265,8 @@ class IndexedStyleWrapper(object):
|
|||||||
|
|
||||||
class IndexedByteSegment(DefaultSegment):
|
class IndexedByteSegment(DefaultSegment):
|
||||||
def __init__(self, data, style, byte_order, **kwargs):
|
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)
|
DefaultSegment.__init__(self, data, IndexedStyleWrapper(style, byte_order), 0, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -9,3 +9,9 @@ def to_numpy(value):
|
|||||||
elif type(value) is types.StringType:
|
elif type(value) is types.StringType:
|
||||||
return np.fromstring(value, dtype=np.uint8)
|
return np.fromstring(value, dtype=np.uint8)
|
||||||
raise TypeError("Can't convert to numpy data")
|
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