k2 icon indicating copy to clipboard operation
k2 copied to clipboard

empty Fsas and RaggedTensors are truthy

Open svandiekendialpad opened this issue 1 year ago • 0 comments

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.

svandiekendialpad avatar May 11 '23 22:05 svandiekendialpad