k2
k2 copied to clipboard
empty Fsas and RaggedTensors are truthy
I encountered a case where best_paths = k2.shortest_path(fsa, use_double_scores=True)
can return an emtpy Fsa and was surprised that bool(best_paths)
returns True
.
Is this by design or would you consider adding something like:
class Fsa(object):
[...]
def __bool__(self) -> bool:
return self.num_arcs > 0
[...]
I noticed the same behaviour for RaggedTensor
where bool(k2.RaggedTensor([], dtype=torch.int32))
returns True
.