UniTensor.arange(int lst) does not exist
It would be great if arange would work with different shapes than vectors as well. In the draft, there is a codeline:
uT = cytnx.UniTensor.arange([2,3,4], labels=["a","b","c"], name="tensor uT")
It does not work, since arange only takes integer arguments as size. I would suggest that this is implemented, otherwise it is a bit complicated to use arange (then reshape, then relabel).
this is not consistent with numpy
I don't see why you can't reshape after create this
Sure, reshaping works. I agree that it is not so nice creating inconsistency with numpy and providing both versions (arguments int list or int) to do the same thing is often not a good idea. In this case, I thought that it might be confusing to users though, because the typical initialization is very different for arange then.
uT=cytnx.UniTensor.ones([2,3,4], labels=["a", "b", "c"], rowrank=2)
works the same way for ones, zeros, uniform etc.
But for arange I need to create a UniTensor with the wrong/uninitialized attributes and then set each one by one
uT=cytnx.UniTensor.arange(2*3*4, labels=["a", "b", "c"], rowrank=2)
ut.reshape_([2,3,4])
ut.relabels_(["a", "b", "c"])
ut.set_rowrank_(2)
This is very different from how we initialize UniTensors everywhere else (in the paper).
Why not do:
uT=cytnx.UniTensor.arange(2*3*4).reshape([2,3,4],rowrank=2).relabel(["a","b","c"])
I reopen this issue to discuss reshape and reshape_ for UniTensor.
In response to one of the referee's question, my current thinking is as follows.
- cytnx.Tensor should behave like numpy.array, so it should support reshape with the same syntax.
- It is not rewlly well-define how to do reshape for UniTensor. One should not apply reshape to symmetric UniTensor. For non-symmetric tensor, one can define in a way similar to Tensor. But there will be some ambiguities. For example, what is the default row-rank? For existing label, if reshape essentially merge them, how do we handle it?
- It seems to me that we can drop the support of reshape to UniTensor. If something like that is really needed, then use get_block->reshape->put_block.
This is current behaviour. Depending on how you do the reshape, you got different default row-rank.
X = cytnx.UniTensor.zeros([2,3,4])
X.print_diagram()
Y=X.reshape(4,3,2)
X.print_diagram()
X.reshape_(4,3,2)
Y.print_diagram()
-----------------------
tensor Name :
tensor Rank : 3
block_form : False
is_diag : False
on device : cytnx device: CPU
---------
/ \
0 ____| 2 3 |____ 1
| |
| 4 |____ 2
\ /
---------
-----------------------
tensor Name :
tensor Rank : 3
block_form : False
is_diag : False
on device : cytnx device: CPU
--------
/ \
| 4 |____ 0
| |
| 3 |____ 1
| |
| 2 |____ 2
\ /
--------
-----------------------
tensor Name :
tensor Rank : 3
block_form : False
is_diag : False
on device : cytnx device: CPU
--------
/ \
| 4 |____ 0
| |
| 3 |____ 1
| |
| 2 |____ 2
\ /
--------
I think current behavior of reshape will make row rank=0. Which we can just change it to be new_rank/2
On Wed, Sep 4, 2024, 03:28 Pochung Chen @.***> wrote:
This is current behaviour. Depending on how you do the reshape, you got different default row-rank.
X = cytnx.UniTensor.zeros([2,3,4]) X.print_diagram()
Y=X.reshape(4,3,2) X.print_diagram()
X.reshape_(4,3,2) Y.print_diagram()
tensor Name : tensor Rank : 3 block_form : False is_diag : False on device : cytnx device: CPU --------- /
0 | 2 3 | 1 | | | 4 |____ 2 \ / ---------tensor Name : tensor Rank : 3 block_form : False is_diag : False on device : cytnx device: CPU -------- /
| 4 |____ 0 | | | 3 |____ 1 | | | 2 |____ 2 \ / --------tensor Name : tensor Rank : 3 block_form : False is_diag : False on device : cytnx device: CPU -------- /
| 4 |____ 0 | | | 3 |____ 1 | | | 2 |____ 2 \ / --------— Reply to this email directly, view it on GitHub https://github.com/Cytnx-dev/Cytnx/issues/325#issuecomment-2328117460, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFCX3SMHE5TR3W6W5YOMESLZU2ZBPAVCNFSM6AAAAABNTPH52WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRYGEYTONBWGA . You are receiving this because you modified the open/close state.Message ID: @.***>