JuliaApproximation / DomainSets.jl

A Julia package for describing domains as continuous sets of elements
MIT License
72 stars 12 forks source link

conditional generators #134

Closed daanhb closed 1 year ago

daanhb commented 1 year ago

It's fun to create domains with generator syntax, but we've been doing it wrong. Currently, we have

julia> Domain(x > 0 for x in -1..1)
indicator function bounded by: -1..1

This domain corresponds to the half-open interval (0,1] (although the code does not realize that), based on the boolean-valued indicator function x -> x>0.

In hindsight, that was not the right call. An indicator function is best specified as a conditional clause:

julia> Domain(x for x in -1..1 if x > 0)
indicator function bounded by: -1..1

This PR adds support for the latter.

In the future, perhaps we can use the generator syntax to create mapped domains, i.e. Domain(2x for x in -1..1) would correspond to [-2,2]. But right now the syntax is taken, so that would be a breaking change.

For now, I've just added if clauses to generators.

codecov[bot] commented 1 year ago

Codecov Report

Base: 85.82% // Head: 85.71% // Decreases project coverage by -0.11% :warning:

Coverage data is based on head (1284066) compared to base (5189b92). Patch coverage: 73.33% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #134 +/- ## ========================================== - Coverage 85.82% 85.71% -0.11% ========================================== Files 32 33 +1 Lines 2624 2632 +8 ========================================== + Hits 2252 2256 +4 - Misses 372 376 +4 ``` | [Impacted Files](https://codecov.io/gh/JuliaApproximation/DomainSets.jl/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaApproximation) | Coverage Δ | | |---|---|---| | [src/domains/indicator.jl](https://codecov.io/gh/JuliaApproximation/DomainSets.jl/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaApproximation#diff-c3JjL2RvbWFpbnMvaW5kaWNhdG9yLmps) | `82.75% <25.00%> (-11.00%)` | :arrow_down: | | [src/generic/generator.jl](https://codecov.io/gh/JuliaApproximation/DomainSets.jl/pull/134?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaApproximation#diff-c3JjL2dlbmVyaWMvZ2VuZXJhdG9yLmps) | `90.90% <90.90%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaApproximation). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaApproximation)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.