Adel Kara Slimane a écrit :
About the memory usage, I don't understand why it would take signifcantly more space, but maybe because I first suggested an array of Python objects instead of compiled objects, which take more space ?
A Python list of 1000 tinyarrays of two numbers each takes up much more
space than an array (numpy or tinyarray or array from the Python stdlib)
because it involves 1000 Python objects that each store three
pointer-sized data fields. Moreover, these 1000 chunks of memory are
allocated separately and this requires storing additional data and may
lead to additional waste due to holes.
The situation for a vector
I agree and I am interested by coding the solution you are suggesting, I would like to suggest further developpement to it: instead of returning a si! mple list of 2D arrays without copying anything, we use an "accesser" object that would enable matrix products :
1 It gets initialised with the system "syst"
2 Calling "accesser.wavefunction(bra, site, orbital)" (or some similar writing) returns "wavefunction[orbital + offset(site)]" with the right offset.
3 The matricial inner product is implemented: "accesser.wavefunction(bra, site) * accesser.hamiltonian(site) * accesser.wavefunction(ket, site)" would be a valid expression (or something similar, with the same idea to have an apparent matrix-vector or matrix-martix product).
So you suggest introducing a separate object, the "accesser", that is initialized with a system? First of all, why a separate object? After all, the system itself, that already knows its 'site_ranges' could take over this work. I will reply in another message for the rest. Christoph