Define operations between WeightedTensor statically
What does the code in the MR do ?
This MR is a replacement for !134
It proposes to rewrite the operations between WeightedTensor and Tensor objects in a less flexible style.
On the other hand, it drops everything related to "unsafe" operations which were experimented in !134 as the performance bottleneck was identified since then in differences in logging settings.
Having the operations defined "statically" rather than at runtime is still interesting to have though. The benefits are primarily related to speed, code readability, and the static code analysis capabilities of modern IDEs.
Prior to this MR, an IDE like PyCharm would flag an operation (i.e. an addition for example) between two WeightedTensor objects because the __add__
method is only defined at runtime.
Where should the reviewer start ?
Changes are pretty self-contained in the _weighted_tensor.py
module.