Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify reshape_ and permute_ to return itself. #478

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

hunghaoti
Copy link
Collaborator

I modified reshape_, permute_ functions in both UniTensor and Tensor object. So now they will return itself, just like relabel_(), instead of None as a void function.
I have test the following code and work well:

A = cytnx.UniTensor.zeros([2,3])
B = A.permute([1,0]) # A and B share tensor elements, different metadata
B[0,1] = 1.
C = A.clone().permute([1,0]) # C is independent of A
C[0,1] = 2.
print(A) # Original shape, element A[1,0] == 1.
print(B) # Permuted shape, element B[0,1] == 1.
print(C) # Permuted shape, element C[0,1] == 2.
D = A.permute_([1,0])
# D is a reference to A
print(A) # Permuted shape, element A[0,1] == 1.
print(D is A) # Output: True
A = cytnx.zeros([2,3])
A[0,1] = 1 
print(A)
D = A.permute_(1,0)
print(D)
print(D is A) # Output: True

print(D is A) gives True
This PR solve the issue #380

…y will return itself instead of None as a void function.
@hunghaoti hunghaoti merged commit c266ec2 into dev-master Oct 8, 2024
1 of 2 checks passed
@hunghaoti hunghaoti deleted the haoti/Fix_underline branch October 8, 2024 00:59
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.

2 participants