apaszke:

actually it seems that the align function from your code could be replaced with expand_as, right?


@apaszke, aligning two tensors for broadcasting requires more than what expand_as provides. In particular, it’s not at all unusual to have each tensor have a unit axis in a different place, so each tensor needs to be expanded along different axes. expand_as does not do this, and the API doesn’t make it possible, since it has to be able to change both tensors and return them both.
Let me know if you need more info - I’m not sure I’ve done a great job of explaining!