Skip to content

torch_addmm does not broadcast addition. #1325

Open
@ralmond

Description

@ralmond

I'm getting the following error when running torch_addmm()

he expanded size of the tensor (1) must match the existing size (2) at non-singleton dimension 1.  Target sizes: [4, 1].  Tensor sizes: [1, 2]
Exception raised from inferExpandGeometryImpl at ../aten/src/ATen/ExpandUtils.cpp:95 (most recent call first):

This seems to be happening at the add step. Shouldn't the addition of a [1,2] and a [4,1] tensor broadcast to a [4,2] tensor?

Here is a short script that reveals the problem.

pt <- torch_tensor(matrix(c(0,0,1,0,01,11,4,2,byrow=TRUE)))
at <- torch_tensor(matrix(1:2,2,1))
bt <- torch_tensor(matrix(c(0,-10),1,2))
torch_addmm(bt,pt,at)

This produces an error, but

torch_add(bt,torch_matmul(pt,at))

Produces the expected [4,2] tensor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions