mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
ENH: store the 'codes' for a labelarray in the narrowest int type possible
This commit is contained in:
@@ -69,6 +69,13 @@ INT_DTYPES_BY_SIZE_BYTES = OrderedDict([
|
||||
(8, dtype('int64')),
|
||||
])
|
||||
|
||||
UNSIGNED_INT_DTYPES_BY_SIZE_BYTES = OrderedDict([
|
||||
(1, dtype('uint8')),
|
||||
(2, dtype('uint16')),
|
||||
(4, dtype('uint32')),
|
||||
(8, dtype('uint64')),
|
||||
])
|
||||
|
||||
|
||||
def int_dtype_with_size_in_bytes(size):
|
||||
try:
|
||||
@@ -77,6 +84,15 @@ def int_dtype_with_size_in_bytes(size):
|
||||
raise ValueError("No integral dtype whose size is %d bytes." % size)
|
||||
|
||||
|
||||
def unsigned_int_dtype_with_size_in_bytes(size):
|
||||
try:
|
||||
return UNSIGNED_INT_DTYPES_BY_SIZE_BYTES[size]
|
||||
except KeyError:
|
||||
raise ValueError(
|
||||
"No unsigned integral dtype whose size is %d bytes." % size
|
||||
)
|
||||
|
||||
|
||||
class NoDefaultMissingValue(Exception):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user