f-dangel / curvlinops

PyTorch linear operators for curvature matrices (Hessian, Fisher/GGN, KFAC, ...)
https://curvlinops.readthedocs.io/en/latest/
MIT License
18 stars 8 forks source link

Unnecessary conversion to Iterator? #135

Closed BrunoKM closed 1 month ago

BrunoKM commented 1 month ago

In the following line, self._data is converted to an Iterator type before being either 1) passed to tqdm or 2) used in a for-loop.

https://github.com/f-dangel/curvlinops/blob/8e47e5795487344830e591e7e6a568bc6e579c04/curvlinops/_base.py#L343

In either case, it seems to me that Iterator type is not required, and an Iterable type will do. Python just treats the Iterator type as an Iterable. Hence, calling iter() seems unnecessary.

This is not a big issue by all means; I've been working on a project where instead of a DataLoader, I use a different iterable type, and the extra call to iter() in the KFAC implementation makes it a little bit annoying to ensure the tqdm progressbar receives a Sized object in the end.

f-dangel commented 1 month ago

Hi Bruno,

thanks for this suggestion. Do you want to set up a PR? Happy to merge.

BrunoKM commented 1 month ago

Thanks!