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

Should basis have __getitem__? #290

Open
billbrod opened this issue Jan 14, 2025 · 0 comments
Open

Should basis have __getitem__? #290

billbrod opened this issue Jan 14, 2025 · 0 comments

Comments

@billbrod
Copy link
Member

With #289 , basis objects have __len__ and __iter__ methods. Should they also have __getitem__? This is only useful for AdditiveBasis, and would rely on storing something like np.fromiter(self.__iter__(), np.object_) (using arrays allows us to work with boolean indexing).

But the difficulty comes about with a tree structure, e.g.,:

a = Add(
    Add(b1, b2),
    Add(b3, b4),
)

Should a[1:] return

a = Add(
    b1,
    Add(b3, b4),
)

or

a = Add(
    Add(b2, b3),
    b4,
)

The first one respects the existing structure of a, but the second is much easier to create (just map sum over the remaining basis objects). The two should function identically, regardless.

Could get the first if we keep track of the tree structure, as used by the label.

(the atomic basis and multiplicative basis all can only accept 0 as just return themselves)

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

No branches or pull requests

1 participant