Cytnx icon indicating copy to clipboard operation
Cytnx copied to clipboard

CombineBond should exist as non-member function

Open manuschneider opened this issue 2 years ago • 3 comments

It is a bit counterintuitive that combineBond is a member function:

bond1 = cytnx.Bond(10)
bond2 = cytnx.Bond(2)
bond12 = bond1.combineBond(bond2)

In this case there should be no difference between bond1 and bond2. I would suggest to have a non-member function instead:

bond1 = cytnx.Bond(10)
bond2 = cytnx.Bond(2)
bond12 = cytnx.CombineBonds([bond1, bond2])

manuschneider avatar Nov 03 '23 04:11 manuschneider

What does no difference between bond1 and bond2 mean?

IvanaGyro avatar Apr 17 '25 04:04 IvanaGyro

We want to combine bond1 and bond2 into a new bond=bond12. In terms of physics, bond1 is not special. So, why bond1.combineBond(bond2) and not bond2.combineBond(bond1).

I would say the only different is memery layout.

bond12 = cytnx.CombineBonds([bond1, bond2]) bond21 = cytnx.CombineBonds([bond2, bond1])

differ only in memory layout.

I also tend to use bond12 = cytnx.CombineBonds([bond1, bond2]). And the order in the bond list naturally corresonds to diffetnt memory latyout.

pcchen avatar Apr 17 '25 05:04 pcchen

The reason they stay for member function is because you might need different implementation depending on the impl of UniTensor (e.g. Fermion/Dense/Sparse)

kaihsin avatar Apr 21 '25 13:04 kaihsin