Opened 10 years ago
Closed 9 years ago
#6253 closed enhancement (fixed)
[with patch, positive review] Constant functions
Reported by: | nthiery | Owned by: | nthiery |
---|---|---|---|
Priority: | major | Milestone: | sage-4.1.2 |
Component: | misc | Keywords: | constant functions |
Cc: | sage-combinat, mhansen, jason | Merged in: | Sage 4.1.2.alpha0 |
Authors: | Nicolas M. Thiéry | Reviewers: | Florent Hivert, Minh Van Nguyen |
Report Upstream: | Work issues: | ||
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
This trivial patch adds basic support for constant functions
Such a function could be written as lambda x: constant, but that's not picklable. Besides, this should eventually be cythoned for speed.
Prerequisite for #4326.
Attachments (3)
Change History (13)
comment:1 Changed 10 years ago by
comment:2 follow-up: ↓ 4 Changed 10 years ago by
- Cc mhansen added
How is this intended to be used? What are your typical constants? Are there instances where you'd want a non-constant function to be used in the same place?
comment:3 Changed 10 years ago by
- Cc jason added
comment:4 in reply to: ↑ 2 Changed 10 years ago by
- Description modified (diff)
- Status changed from new to assigned
Replying to mhansen:
How is this intended to be used?
One of my use case looks like:
def my_objects(<some parameters>, predicate = ConstantFunction?(True)):
""" Returns all the objects blah blah blah (as an EnumeratedSet?) Optionally, a predicate can be specified to select only those objects satisfying the predicate
Another one looks like:
def generating_series(..., weight = ConstantFunction?(1)):
...
What are your typical constants?
So far, True, 1, Integer(1)
Btw: with UniqueRepresentation?, the two first yield the same constant function with the current implementation, thanks to this horror:
sage: { 1: 'a', True: 'b' } {1: 'b'}
Fixed patch in a couple minutes.
Are there instances where you'd want a non-constant function to be used in the same place?
Yes. Actually, that's the case in all the situations I encountered so far
Changed 10 years ago by
Changed 10 years ago by
comment:5 Changed 10 years ago by
- Reviewers set to Florent Hivert
The updated patch removes two unused imports spotted by Florent. Apply only this one.
comment:6 Changed 10 years ago by
- Summary changed from [with patch, needs review] Constant functions to [with patch, positive review] Constant functions
The patch looks good ! Positive review !
Florent
comment:7 follow-up: ↓ 9 Changed 9 years ago by
This is great stuff! So let's put it in the reference manual. The reviewer patch trac_6253-reviewer.patch
adds the module sage/misc/constant_function.py
to the reference manual. It also fixes some typos so that the reference manual builds without any warnings. If people are happy with my changes, then patches should be merged in this order:
trac_6253-constant_function-nt.patch
trac_6253-reviewer.patch
comment:8 Changed 9 years ago by
- Summary changed from [with patch, positive review] Constant functions to [with patch, needs review] Constant functions
comment:9 in reply to: ↑ 7 Changed 9 years ago by
Replying to mvngu:
This is great stuff! So let's put it in the reference manual. The reviewer patch
trac_6253-reviewer.patch
adds the modulesage/misc/constant_function.py
to the reference manual. It also fixes some typos so that the reference manual builds without any warnings. If people are happy with my changes, then patches should be merged in this order:
trac_6253-constant_function-nt.patch
trac_6253-reviewer.patch
Thanks Minh! (again)
Positive review on your reviewer patch.
comment:10 Changed 9 years ago by
- Merged in set to Sage 4.1.2.alpha0
- Resolution set to fixed
- Reviewers changed from Florent Hivert to Florent Hivert, Minh Van Nguyen
- Status changed from assigned to closed
- Summary changed from [with patch, needs review] Constant functions to [with patch, positive review] Constant functions
Merged patches in this order:
trac_6253-constant_function-nt.patch
trac_6253-reviewer.patch
Oh, I forgot to mention: let me know if this readily exists somewhere and I missed it.