cornellius-gp / linear_operator

A LinearOperator implementation to wrap the numerical nuts and bolts of GPyTorch
MIT License
95 stars 28 forks source link

Add short path for LinearOperator.repeat() #70

Closed Turakar closed 1 year ago

Turakar commented 1 year ago

This adds a short path for LinearOperator.repeat() if we would otherwise create a new BatchRepeatLinearOperator which would be a no-op.

repeat() is called like this for example by the constructor of KroneckerProductLinearOperator.

By reducing one level of indirection, we gain two benefits: a) slightly better performance (obviously), and b) some more optimizations by calling native functions instead of default LinearOperator functions, e.g. for _diagonal().

Turakar commented 1 year ago

Seems like there were no unit tests before, so I added tests for both cases: A No-Op case and a true case. I also allowed the repeat(1, 1) case as this is a no-op, too.