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

Enumerated ConditionSet #32315

Closed
mjungmath opened this issue Jul 30, 2021 · 25 comments
Closed

Enumerated ConditionSet #32315

mjungmath opened this issue Jul 30, 2021 · 25 comments

Comments

@mjungmath
Copy link

We implement a support for enumerated sets of ConditionSet (see #32089).

CC: @mkoeppe @tscrim @trevorkarn

Component: symbolics

Author: Michael Jung

Branch/Commit: b5e4168

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/32315

@mjungmath mjungmath added this to the sage-9.4 milestone Jul 30, 2021
@mjungmath
Copy link
Author

Branch: public/32315_conditionset_enumerated

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Commit: d9b6ddb

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

d9b6ddbTrac #32315: support enumerated sets

@mjungmath
Copy link
Author

comment:3

Feel free to add more examples or make some changes. I removed the pre-processing with __private_classcall__ and shifted it to a factory method.

If you agree with the changes, it's ready for review.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

c8062e4Trac #32315: add new line at the end

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Changed commit from d9b6ddb to c8062e4

@tscrim
Copy link
Collaborator

tscrim commented Jul 30, 2021

comment:5

Strong -1 on factory functions. It further separates the code from what it works on and now you don't have a natural "isinstance"

@mjungmath
Copy link
Author

comment:6

The problem I faced was that __private_classcall__ should delegate to the enumerated sub-class version. But then the whole code in __private_classcall__ should be copied to the sub-class again. This is bad for maintenance.

Do you have a better idea?

@tscrim
Copy link
Collaborator

tscrim commented Jul 30, 2021

comment:7

If it does need to be used by subclasses, then it should be __classcall__. However, you can do all of thebpreprocessing in the private version, then pass off to the correct subclass. What I am saying is it would be your factory function.

Also, thank you for adding this feature.

@mjungmath
Copy link
Author

comment:8

And leave a note that the sub-class, i.e. enumerated version, is not intended to be used by the end-user?

@mjungmath
Copy link
Author

comment:9

Otherwise, if __classcall__ delegates to the sub-class and is used by the sub-class again, this leads to an infinite loop...

@tscrim
Copy link
Collaborator

tscrim commented Jul 30, 2021

comment:10

They are never meant to be called directly, no. Although I don't necessarily see why we need a subclass. I also don't get how you are getting an infinite loop. It is how function inheritance works.

@mjungmath
Copy link
Author

comment:11

Replying to @tscrim:

Also, thank you for adding this feature.

Thank you Travis for suggesting this, and your help in general! :)

Replying to @tscrim:

They are never meant to be called directly, no. Although I don't necessarily see why we need a subclass.

A non-enumerated set is not supposed to have an __iter__ method, no? That's why I thought that sub-classing is necessary. Or what would have been your approach?

I also don't get how you are getting an infinite loop. It is how function inheritance works.

Well, __classcall__ of the base-class returns an invokation of the enumerated class. But that invokes the same __classcall__ method, invoking the class constructor again... Or do I have a flaw in my thinking?

@tscrim
Copy link
Collaborator

tscrim commented Jul 30, 2021

comment:12

Replying to @mjungmath:

They are never meant to be called directly, no. Although I don't necessarily see why we need a subclass.

A non-enumerated set is not supposed to have an __iter__ method, no? That's why I thought that sub-classing is necessary. Or what would have been your approach?

set also has an iterator. It just doesn't promise anything precise about the iteration order.

I also don't get how you are getting an infinite loop. It is how function inheritance works.

Well, __classcall__ of the base-class returns an invokation of the enumerated class. But that invokes the same __classcall__ method, invoking the class constructor again... Or do I have a flaw in my thinking?

You would likely have a __classcall_private__ to handle delegating to which subclass, then the processing of the input is done in __classcall__. Although another option is just a _process_inputs type method.

@mjungmath
Copy link
Author

comment:13

I see, then no sub-classing is necessary. That makes this ticket indeed minimal-invasive.

The latter is good to know. Does __classcall_private__ always go over __classcall__?

@tscrim
Copy link
Collaborator

tscrim commented Jul 30, 2021

comment:14

I am actually sure if a class has both of them implemented what happens. If it is in a base class, then the order is clear I think.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

b5e4168Trac #32315: support iteration and enumerated sets

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2021

Changed commit from c8062e4 to b5e4168

@mjungmath
Copy link
Author

comment:16

Alright. Small misunderstanding, huge impact.

This should be fine now.

@mjungmath
Copy link
Author

comment:17

Thank you Travis for pointing these things out.

@tscrim
Copy link
Collaborator

tscrim commented Jul 31, 2021

comment:18

Thanks. LGTM.

@tscrim
Copy link
Collaborator

tscrim commented Jul 31, 2021

Reviewer: Travis Scrimshaw

@mkoeppe
Copy link
Member

mkoeppe commented Aug 1, 2021

comment:19

Thanks for implementing this!

@mjungmath

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 9, 2021
@vbraun
Copy link
Member

vbraun commented Sep 5, 2021

Changed branch from public/32315_conditionset_enumerated to b5e4168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants