Skip to content

Question: Element-wise matrix addition #119

@kheyer

Description

@kheyer

Thanks for creating this library!

I'm trying to use keops to implement a formula that involves element-wise addition between two 2D matrices. This is the basic format:

# x = (N,F), y=(M,F)

x_i = LazyTensor(x[:, None, :])
y_j = LazyTensor(x[None, :, :])

C_ij = ((x_i - y_j)**2).sum(dim=2)**0.5 # (N,M)

# Z_ij = (N,M)
O_ij = C_ij + Z_ij # (N,M)

Z_ij is a pre-defined torch tensor. When I try to convert Z_ij to a LazyTensor (ie Z_ij = LazyTensor(Z_torch, 0)), the axis specification causes the addition to return a tensor of size (N,M,M) rather than a (N,M) tensor.

Is element-wise addition between two 2D matrices possible with LazyTensors?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions