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

Introduce USet and UInterval classes with withrepr decorator #59

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bleudev
Copy link
Member

@bleudev bleudev commented Nov 9, 2024

Description (optional)

Added:

  • utils.withrepr() decorator

TO-DO list (optional)

  • USet
  • UInterval
  • Booleans USets
  • Standart math sets such as R, Q, I, Z, N
  • Tests
  • Examples

Issue you want to close (optional)

closes #58

Summary by Sourcery

Introduce the USet class for mathematical set operations and add a withrepr decorator for improved function representation.

New Features:

  • Introduce the USet class to represent mathematical sets with various operations such as union, intersection, and implication.

Enhancements:

  • Add a withrepr decorator to enhance the representation of functions.

@bleudev bleudev added this to the 0.3 milestone Nov 9, 2024
@bleudev bleudev self-assigned this Nov 9, 2024
@bleudev bleudev linked an issue Nov 9, 2024 that may be closed by this pull request
Copy link
Contributor

sourcery-ai bot commented Nov 9, 2024

Reviewer's Guide by Sourcery

This PR introduces a new USet class for handling mathematical sets and adds a withrepr decorator for improved function representation. The implementation includes refactoring of the math_op.py module to improve code organization and readability through the introduction of helper functions.

Class diagram for the new USet class and withrepr decorator

classDiagram
    class USet {
        +USet(*values: T, iterable: Optional<Iterable<T>> = None, auto_update_U: bool = True)
        +set: set<T>
        +__repr__() str
        +__iter__() Iterator<T>
        +_or(other: Iterable<OT> | OT) USet<T | OT>
        +__or__(other: Iterable<OT> | OT) USet<T | OT>
        +__add__(other: Iterable<OT> | OT) USet<T | OT>
        +sub(other: Iterable<OT> | OT) USet<T>
        +__sub__(other: Iterable<OT> | OT) USet<T>
        +__rsub__(other: Iterable<OT> | OT) USet<T>
        +__truediv__(other: Iterable<OT> | OT) USet<T>
        +_and(other: Iterable<OT> | OT) USet
        +__and__(other: Iterable<OT> | OT) USet
        +__mul__(other: Iterable<OT> | OT) USet
        +_not(s: Optional<USet<OT>> = None) USet<OT>
        +__neg__() USet
        +implicate(other: Iterable<OT> | OT) USet
        +__gt__(other: Iterable<OT> | OT) USet
        +__ge__(other: Iterable<OT> | OT) USet
        +__lt__(other: Iterable<OT> | OT) USet
        +__le__(other: Iterable<OT> | OT) USet
    }

    class _U {
        +_U(*values: T)
    }

    class __reprwrapper {
        +__init__(repr, func)
        +__call__(*args, **kw)
        +__repr__()
    }

    class withrepr {
        +withrepr(f: Callable[[T], str])
    }

    USet <|-- _U
    withrepr o-- __reprwrapper
Loading

File-Level Changes

Change Details Files
Refactored operator generation code to improve readability and maintainability
  • Introduced check() helper function to verify operator existence
  • Added check_i() and check_r() helper functions for inplace and reverse operators
  • Simplified operator checks using the new helper functions
ufpy/math_op.py
Added new utility functions and decorators
  • Implemented withrepr decorator for custom function representation
  • Added __reprwrapper class to handle decorated function representation
  • Added is_iterable utility function
ufpy/utils.py
Implemented USet class for mathematical set operations
  • Created base USet class with type parameter support
  • Implemented core set operations (union, intersection, difference)
  • Added support for operator overloading (+, -, *, /, &,
)
  • Implemented implication operations using comparison operators
  • Added universal set handling with _U class
  • Implemented automatic universal set updates
  • Assessment against linked issues

    Issue Objective Addressed Explanation
    #58 Add USet class with basic set operations (union, intersection, difference, complement)
    #58 Add interval functionality to USet class The PR adds the basic USet class but does not implement the interval functionality (USet.interval()) as mentioned in the TO-DO list
    #58 Support automatic universal set (USet.U) updates

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time. You can also use
      this command to specify where the summary should be inserted.

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    @bleudev bleudev changed the title Basic functional for USets. Added withrepr() decorator algebra.USet, similar variables and functions and more! Nov 9, 2024
    @bleudev bleudev changed the title algebra.USet, similar variables and functions and more! algebra.USet, similar variables and functions and more! @sourcery-ai Nov 10, 2024
    @sourcery-ai sourcery-ai bot changed the title algebra.USet, similar variables and functions and more! @sourcery-ai Introduce USet class and add withrepr decorator Nov 10, 2024
    @bleudev
    Copy link
    Member Author

    bleudev commented Nov 10, 2024

    @sourcery-ai review

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey @bleudev - I've reviewed your changes - here's some feedback:

    Overall Comments:

    • Using os.environ for storing the universal set U state is problematic - it's not thread-safe and could cause issues in concurrent environments. Consider using a proper singleton pattern or class-level storage instead.
    • The USet class is mixing set operations with global U state management. Consider separating these responsibilities into different classes for better maintainability.
    Here's what I looked at during the review
    • 🟡 General issues: 4 issues found
    • 🟢 Security: all looks good
    • 🟢 Testing: all looks good
    • 🟢 Complexity: all looks good
    • 🟢 Documentation: all looks good

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    ufpy/algebra/sets.py Outdated Show resolved Hide resolved
    if iterable else
    USet(*values, auto_update_U=False)))

    def _convert_type(s: str):
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    issue (bug_risk): Type conversion logic is fragile and could lead to incorrect interpretations

    The current string-based type guessing could lead to ambiguous or incorrect conversions. Consider implementing a more robust type conversion system with explicit type information.

    ufpy/algebra/sets.py Outdated Show resolved Hide resolved
    ufpy/algebra/sets.py Show resolved Hide resolved
    ufpy/algebra/sets.py Outdated Show resolved Hide resolved
    @bleudev
    Copy link
    Member Author

    bleudev commented Nov 10, 2024

    Implemented Universal Set (USet) class with basic set operations

    Sorry, but this is Useful Set, not Universal :)

    bleudev and others added 2 commits November 10, 2024 19:46
    Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
    @bleudev
    Copy link
    Member Author

    bleudev commented Nov 11, 2024

    @sourcery-ai review

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hey @bleudev - I've reviewed your changes - here's some feedback:

    Overall Comments:

    • Consider adding tests before merging - mathematical set operations need thorough testing to ensure correctness, especially for edge cases.
    • Please document the behavior and performance implications of auto_update_U, particularly its effect on the universal set U.
    Here's what I looked at during the review
    • 🟢 General issues: all looks good
    • 🟢 Security: all looks good
    • 🟢 Testing: all looks good
    • 🟡 Complexity: 2 issues found
    • 🟢 Documentation: all looks good

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    ufpy/algebra/sets.py Show resolved Hide resolved
    ufpy/math_op.py Show resolved Hide resolved
    ufpy/algebra/sets.py Outdated Show resolved Hide resolved
    @bleudev bleudev changed the title Introduce USet class and add withrepr decorator Introduce USet class and add withrepr decorator @sourcery-ai Nov 12, 2024
    @sourcery-ai sourcery-ai bot changed the title Introduce USet class and add withrepr decorator @sourcery-ai Introduce USet class and withrepr decorator for enhanced functionality Nov 12, 2024
    @bleudev bleudev changed the title Introduce USet class and withrepr decorator for enhanced functionality @sourcery-ai Nov 12, 2024
    @sourcery-ai sourcery-ai bot changed the title @sourcery-ai Introduce USet and UInterval classes with withrepr decorator Nov 12, 2024
    @bleudev
    Copy link
    Member Author

    bleudev commented Nov 12, 2024

    @sourcery-ai summary

    Copy link
    Contributor

    sourcery-ai bot commented Nov 12, 2024

    I'm sorry, I don't understand the command @sourcery-ai summary.

    Please use @sourcery-ai review to request a review.

    @bleudev
    Copy link
    Member Author

    bleudev commented Nov 12, 2024

    @sourcery-ai summary

    Copy link
    Contributor

    sourcery-ai bot commented Nov 12, 2024

    I'm sorry, I don't understand the command @sourcery-ai summary.

    Please use @sourcery-ai review to request a review.

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

    Successfully merging this pull request may close these issues.

    Add USet class
    1 participant