mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Handle completely empty veclists
This commit is contained in:
@@ -238,7 +238,8 @@ class Hdf5Sample(Sample):
|
||||
else:
|
||||
data = np.array(padded)
|
||||
break
|
||||
assert data is not None
|
||||
if data is None:
|
||||
data = np.array(padded)
|
||||
ds = self._put(key, data)
|
||||
ds.attrs["lengths"] = lens
|
||||
|
||||
@@ -254,7 +255,7 @@ def _pad(veclist: VectorList) -> Tuple[VectorList, List[int]]:
|
||||
maxlen = max(lens)
|
||||
|
||||
# Find appropriate constant to pad the vectors
|
||||
constant: Union[int, float, str, None] = None
|
||||
constant: Union[int, float, str] = 0
|
||||
for v in veclist:
|
||||
if v is None or len(v) == 0:
|
||||
continue
|
||||
@@ -266,7 +267,6 @@ def _pad(veclist: VectorList) -> Tuple[VectorList, List[int]]:
|
||||
constant = ""
|
||||
else:
|
||||
assert False, f"Unsupported data type: {v[0]}"
|
||||
assert constant is not None, "veclist must not be completely empty"
|
||||
|
||||
# Pad vectors
|
||||
for (i, vi) in enumerate(veclist):
|
||||
|
||||
@@ -34,6 +34,7 @@ def _test_sample(sample: Sample) -> None:
|
||||
_assert_roundtrip_vector_list(sample, [[True], [False, False], None])
|
||||
_assert_roundtrip_vector_list(sample, [[1], None, [2, 2], [3, 3, 3]])
|
||||
_assert_roundtrip_vector_list(sample, [[1.0], None, [2.0, 2.0], [3.0, 3.0, 3.0]])
|
||||
_assert_roundtrip_vector_list(sample, [None, None])
|
||||
|
||||
# Bytes
|
||||
_assert_roundtrip_bytes(sample, b"\x00\x01\x02\x03\x04\x05")
|
||||
@@ -68,6 +69,7 @@ def _assert_roundtrip_vector_list(sample: Sample, expected: Any) -> None:
|
||||
actual = sample.get_vector_list("key")
|
||||
assert actual == expected
|
||||
assert actual is not None
|
||||
if actual[0] is not None:
|
||||
_assert_same_type(actual[0][0], expected[0][0])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user