Changeset 843


Ignore:
Timestamp:
11/23/15 06:38:51 (6 months ago)
Author:
mmckerns
Message:

add deepcopy method for abstract_solver to better support 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/abstract_solver.py

    r835 r843  
    840840        return 
    841841 
     842    def __copy__(self): 
     843        cls = self.__class__ 
     844        result = cls.__new__(cls) 
     845        result.__dict__.update(self.__dict__) 
     846        return result 
     847 
     848    def __deepcopy__(self, memo): 
     849        import copy 
     850        import dill 
     851        cls = self.__class__ 
     852        result = cls.__new__(cls) 
     853        memo[id(self)] = result 
     854        for k, v in self.__dict__.items(): 
     855            if v is self._cost: 
     856                setattr(result, k, tuple(dill.copy(i) for i in v)) 
     857            else: 
     858                try: #XXX: work-around instancemethods in python2.6 
     859                    setattr(result, k, copy.deepcopy(v, memo)) 
     860                except TypeError: 
     861                    setattr(result, k, dill.copy(v)) 
     862        return result 
     863 
    842864    # extensions to the solver interface 
    843865    evaluations = property(__evaluations ) 
Note: See TracChangeset for help on using the changeset viewer.