Mayank447 / Pseudo-Spectral-Discretization

GNU General Public License v3.0
0 stars 1 forks source link

Cache eigenvalues in `Fermion2D` #40

Open chillenzer opened 3 months ago

chillenzer commented 3 months ago

The standard way to use properties would be something like this


_eigenvalues = None

@property
def eigenvalues(self):
    if self._eigenvalues is None:
        self._eigenvalues = self._compute_eigenvalues()
    return self._eigenvalues

We should come back to this if querying the eigenvalues ever becomes a bottleneck.

Mayank447 commented 3 months ago

This will throw an error imo cause there is no setter for eigenvalues

chillenzer commented 3 months ago

Please note the underscores in the variable name discriminating it from the property.

Mayank447 commented 3 months ago

Ahh.. I missed that. Actually this is a pretty good idea in terms of keeping the variable privative and the user unable to being able to modify it besides caching

Mayank447 commented 3 months ago

Will open a PR for the same

Mayank447 commented 3 months ago

Resolved in #41 for eigenvalues. I will be doing the same for few more variable like p_x, p_t as well

chillenzer commented 3 months ago

As we're handling numpy arrays mostly, attempting to do this one should be aware of https://stackoverflow.com/questions/60810463/is-this-a-correct-way-to-create-a-read-only-view-of-a-numpy-array.