pathpyG icon indicating copy to clipboard operation
pathpyG copied to clipboard

Extend `IndexMap.to_idxs(...)` to any shape

Open M-Lampert opened this issue 1 year ago • 0 comments

The method IndexMap.to_idxs(...) is meant as a shortcut if you want to convert an iterable of ids to the corresponding idx. In some cases one might want to input an numpy.array or a torch.Tensor with a specific shape. Currently we only allow conversions for one dimensional iterable objects but it would be great if you could input any shape and the output has the same shape and potentially also type. For the other direction (i.e. to_ids(....)) it would also make sense. Example for the desired behaviour:

>>> mapping = IndexMap(["a", "b", "c"])
>>> print(mapping.to_idxs(np.array([
>>>         ["a", "a", "b"],
>>>         ["b", "c", "c"]]))
np.array([
   [0, 0, 1],
   [1, 2, 2]])

M-Lampert avatar Apr 10 '24 11:04 M-Lampert