artofscience / SAOR

Sequential Approximate Optimization Repository
GNU General Public License v3.0
5 stars 1 forks source link

Iterator #27

Closed aatmdelissen closed 3 years ago

aatmdelissen commented 3 years ago

I've made this object for my other code. It might be very handy in this project since you can keep track of multiple iteration counts in a 'global' way (without global variables). From anywhere in the code you can call Iterator, which provides the iteration count. In all ways, it works like a normal int.

Let me know if we can use this :)

MaxvdKolk commented 3 years ago

This could be a nice way to deal with iterations for #26, by passing access to one of these iterations. I'm fine with merging this already, or only once we need it.

Regarding extract_val. I guess you could also support any instance, as long as it has .value, but not sure if that makes sense, as it's pretty specific to this class anyway.

def extract_val(x):
    try: 
        value = x.value
    except AttributeError:
        value = x
    return x 

Would it be possible to make this a subclass of int to have some of the __x__ routines automatically from int? This might clutter up all the other code though, with __super__() calls... Not sure if that's worth it