Skip to content

feat(label_tensor): add dim parameter to LabelTensor.stack method - #835

Merged
dario-coscia merged 1 commit into
PINA-org:devfrom
s-chudmunge:feat/labeltensor-stack-dim
Oct 3, 2026
Merged

dario-coscia merged 1 commit into
PINA-org:devfrom
s-chudmunge:feat/labeltensor-stack-dim

Conversation

@s-chudmunge

Copy link
Copy Markdown

Resolves #770

Summary

Exposes the dim parameter in LabelTensor.stack(tensors, dim=0) to align with torch.stack.

Key Changes

  • Added dim=0 argument to LabelTensor.stack with support for positive and negative dimension indices.
  • Validates bounds [-(ndim + 1), ndim] matching torch.stack.
  • Dynamically updates _labels dimension indices by shifting indices at or after dim by +1.
  • Validates consistency of input tensors and their stored labels.
  • Added comprehensive unit tests in tests/test_label_tensor/test_label_tensor.py covering dim=0, dim=1, and negative indexing.

@s-chudmunge
s-chudmunge requested a review from ndem0 as a code owner September 10, 2026 07:15
@dario-coscia
dario-coscia changed the base branch from master to dev September 28, 2026 09:47
@GiovanniCanali
GiovanniCanali self-requested a review October 1, 2026 11:27
@GiovanniCanali GiovanniCanali self-assigned this Oct 1, 2026
@dario-coscia

Copy link
Copy Markdown
Member

Hi @s-chudmunge ! Thanks for submitting. Are you able to rebase from dev? I see some commits that are not labeltensor based from this PR after changing the destination merge branch

@dario-coscia dario-coscia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, great job! I added a comment on the test for labeltensors to also check additional dimensions where the stack is performed. After that addition I think it will be good to go 👍🏻

assert lt_stacked.full_labels[1]["name"] == "second"


def test_stack_dim():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make an extra test here to check all labels' dimensions and not just the last one?

@GiovanniCanali GiovanniCanali left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @s-chudmunge, for contributing to PINA. The feature looks clean!

I agree with @dario-coscia’s suggestion: please rebase the branch onto dev so that the PR includes only the commits relevant to LabelTensor.

Also, consider adding tests covering higher-dimensional cases, similar to test_vstack_2D and test_vstack_3D.

@s-chudmunge
s-chudmunge force-pushed the feat/labeltensor-stack-dim branch from 4bb264d to b49be15 Compare October 1, 2026 19:30
@s-chudmunge
s-chudmunge requested a review from a team as a code owner October 1, 2026 19:30
@s-chudmunge

Copy link
Copy Markdown
Author

Hi @dario-coscia @GiovanniCanali,

Thanks for the feedback!

  1. I have rebased the branch onto dev so that only the commits relevant to LabelTensor are included.
  2. I have expanded the unit tests with test_stack_2D and test_stack_3D covering higher-dimensional tensors across all positive/negative dimension indices and verifying full_labels on all dimensions, as well as edge and error cases.

Please let me know if anything else is needed!

@GiovanniCanali GiovanniCanali left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @s-chudmunge, for addressing the minor issues discussed above. Everything looks good to me!

@GiovanniCanali GiovanniCanali added enhancement New feature or request pr-to-review Label for PR that are ready to been reviewed labels Oct 2, 2026
@dario-coscia
dario-coscia merged commit 266f964 into PINA-org:dev Oct 3, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pr-to-review Label for PR that are ready to been reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add dim parameter to LabelTensor.stack method

4 participants