Skip to content

Fix issue when reshape with none edge. - #67

Merged
gausshj merged 1 commit into
mainfrom
dev/add-support-for-reshape-with-none
Oct 22, 2025
Merged

Fix issue when reshape with none edge.#67
gausshj merged 1 commit into
mainfrom
dev/add-support-for-reshape-with-none

Conversation

@hzhangxyz

Copy link
Copy Markdown
Member

No description provided.

@hzhangxyz

Copy link
Copy Markdown
Member Author

@gausshj 你试试实现对 GrassmannTensor((), (), torch.tensor(2333)).reshape(((0, 1), (0, 1))).reshape(()) 这种操作的支持,代码上面可能有一定难度,你尽量试试。

@hzhangxyz hzhangxyz linked an issue Sep 2, 2025 that may be closed by this pull request
@hzhangxyz

Copy link
Copy Markdown
Member Author

@gausshj 你也思考一下,除了这个情况,是否已经覆盖所有的corner case了。

@gausshj

gausshj commented Sep 2, 2025

Copy link
Copy Markdown
Collaborator

@gausshj 你试试实现对 GrassmannTensor((), (), torch.tensor(2333)).reshape(((0, 1), (0, 1))).reshape(()) 这种操作的支持,代码上面可能有一定难度,你尽量试试。

好的,我试试。

@gausshj 你也思考一下,除了这个情况,是否已经覆盖所有的corner case了。

好的。

@codecov

codecov Bot commented Sep 5, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.03922% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
grassmann_tensor/tensor.py 98.03% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Comment thread tests/reshape_test.py
@gausshj
gausshj marked this pull request as ready for review September 25, 2025 04:09
Comment thread grassmann_tensor/tensor.py
Comment thread grassmann_tensor/tensor.py Outdated
)
cursor_self = self.tensor.dim() - 1
else:
if cursor_plan != len(new_shape) and new_shape[cursor_plan] == -1:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

为什么要加上这个判断 cursor_plan != len(new_shape) ?

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.

因为对于没有0维度的grassmann张量分解时,如果不加上这个判断会出现问题,cursor_plan这个变量可能会出现边界值。

Comment thread grassmann_tensor/tensor.py Outdated
# One dimension included, check if we can stop
if plan_total == self.tensor.shape[cursor_self]:
# new_shape block has been verified to be always tuple[int, int] before
if self.tensor.dim() == 0:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

你在整个流程多次判断self.tensor.dim不如直接放在外面,这样时不时判断一下有点考验可读性。。。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

如果你经过思考,确认确实只有前后dim=0的情况会触发问题,直接在最外面做判断吧。

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.

但是对于0维度张量的merge和split的逻辑基本是相同的,只是对这些特殊情况进行了处理,如果在最外层判断,可能得把相同的代码逻辑移植到外面,可能会使这个函数更长。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

好,目前这个版本 2a2ab4e 可读性还行。

@hzhangxyz

Copy link
Copy Markdown
Member Author

看起来没啥大问题。我这两天再想想有没有啥情况漏的,你也想一想,如果没啥问题,周一合吧。

- Fix dimension handling when reshaping with None edges
- Update assertions for None-edge reshape
- Address bugs introduced by recent features
- Refactor: flatten if-else for readability
- Tests: add reshape tests and fix typos

Signed-off-by: Gausshj <kylin_0@qq.com>
@gausshj
gausshj force-pushed the dev/add-support-for-reshape-with-none branch from 2a2ab4e to c0904be Compare October 22, 2025 09:46
@gausshj
gausshj merged commit b712ec3 into main Oct 22, 2025
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reshape need more tests.

2 participants