Skip to content

Interpolation of a 2D tensor doesnt behave as expected #24

Description

@anegi19

Hello,

The interp1d function is unable to interpolate a 2-D tensor

For example

import torch

# Define x, y, and xnew with appropriate shapes
D, N, P = 3, 5, 4  # D = number of batches, N = original points, P = new points

# `y` is a 2D tensor with `D` rows, each representing an independent 1D function
y = torch.tensor([
    [1.0, 2.0, 3.0, 4.0, 5.0],
    [2.0, 3.0, 5.0, 7.0, 11.0],
    [1.0, 4.0, 9.0, 16.0, 25.0]
], requires_grad=True)

# `x` is the corresponding x-coordinates, can be either 1D (shared across all `y` rows) or 2D
x = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0])  # Shape (N, )

# `xnew` is where we want the interpolated values, can be 1D or 2D
xnew = torch.tensor([0.5, 1.5, 2.5, 3.5])  # Shape (P, )

# Perform interpolation
ynew = interp1d(x, y, xnew)
print("Interpolated values (ynew):", ynew)

gives me the output
Interpolated values (ynew): tensor([[1.5000, 2.5000, 3.5000, 4.5000]], grad_fn=<Interp1dBackward>)

Is this behavior expected? Or this is buggy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions