Skip to content

Commit dd1201a

Browse files
committed
added support for empty sequence of sequences in Product
1 parent 4cb7d68 commit dd1201a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

larray/util/misc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,14 +904,17 @@ class Product:
904904
[('b', 2), ('c', 1), ('c', 2)]
905905
>>> list(p)
906906
[('a', 1), ('a', 2), ('b', 1), ('b', 2), ('c', 1), ('c', 2)]
907+
>>> list(Product([['a', 'b', 'c']]))
908+
[('a',), ('b',), ('c',)]
909+
>>> list(Product([]))
910+
[()]
907911
"""
908912
def __init__(self, sequences):
909913
self.sequences = sequences
910-
assert len(sequences)
911914
shape = [len(a) for a in self.sequences]
912915
self._div_mod = [(int(np.prod(shape[i + 1:])), shape[i])
913916
for i in range(len(shape))]
914-
self._length = np.prod(shape)
917+
self._length = np.prod(shape, dtype=int)
915918

916919
def __len__(self):
917920
return self._length

0 commit comments

Comments
 (0)