Skip to content

Commit 4cf5d7d

Browse files
authored
Speedup deepcopy for Rating objects (#108)
* Speedup deepcopy Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com> * Add changelog Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com> --------- Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com>
1 parent a03847b commit 4cf5d7d

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

changes/108.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize rating objects for deepcopy

openskill/models/weng_lin/bradley_terry_full.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ def __str__(self) -> str:
7575
def __hash__(self) -> int:
7676
return hash((self.id, self.mu, self.sigma))
7777

78+
def __deepcopy__(self, memodict={}):
79+
blf = BradleyTerryFullRating(self.mu, self.sigma, self.name)
80+
blf.id = self.id
81+
return blf
82+
7883
def __eq__(self, other: object) -> bool:
7984
if isinstance(other, BradleyTerryFullRating):
8085
if self.mu == other.mu and self.sigma == other.sigma:

openskill/models/weng_lin/bradley_terry_part.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def __str__(self) -> str:
8080
def __hash__(self) -> int:
8181
return hash((self.id, self.mu, self.sigma))
8282

83+
def __deepcopy__(self, memodict={}):
84+
blp = BradleyTerryPartRating(self.mu, self.sigma, self.name)
85+
blp.id = self.id
86+
return blp
87+
8388
def __eq__(self, other: object) -> bool:
8489
if isinstance(other, BradleyTerryPartRating):
8590
if self.mu == other.mu and self.sigma == other.sigma:

openskill/models/weng_lin/plackett_luce.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import copy
66
import itertools
7+
import marshal
78
import math
89
import uuid
910
from functools import reduce
@@ -74,6 +75,11 @@ def __str__(self) -> str:
7475
def __hash__(self) -> int:
7576
return hash((self.id, self.mu, self.sigma))
7677

78+
def __deepcopy__(self, memodict={}):
79+
plr = PlackettLuceRating(self.mu, self.sigma, self.name)
80+
plr.id = self.id
81+
return plr
82+
7783
def __eq__(self, other: object) -> bool:
7884
if isinstance(other, PlackettLuceRating):
7985
if self.mu == other.mu and self.sigma == other.sigma:

openskill/models/weng_lin/thurstone_mosteller_full.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def __str__(self) -> str:
8383
def __hash__(self) -> int:
8484
return hash((self.id, self.mu, self.sigma))
8585

86+
def __deepcopy__(self, memodict={}):
87+
tmf = ThurstoneMostellerFullRating(self.mu, self.sigma, self.name)
88+
tmf.id = self.id
89+
return tmf
90+
8691
def __eq__(self, other: object) -> bool:
8792
if isinstance(other, ThurstoneMostellerFullRating):
8893
if self.mu == other.mu and self.sigma == other.sigma:

openskill/models/weng_lin/thurstone_mosteller_part.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def __str__(self) -> str:
8484
def __hash__(self) -> int:
8585
return hash((self.id, self.mu, self.sigma))
8686

87+
def __deepcopy__(self, memodict={}):
88+
tmp = ThurstoneMostellerPartRating(self.mu, self.sigma, self.name)
89+
tmp.id = self.id
90+
return tmp
91+
8792
def __eq__(self, other: object) -> bool:
8893
if isinstance(other, ThurstoneMostellerPartRating):
8994
if self.mu == other.mu and self.sigma == other.sigma:

0 commit comments

Comments
 (0)