Skip to content

Commit

Permalink
Speedup deepcopy for Rating objects (#108)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
vivekjoshy committed Aug 21, 2023
1 parent a03847b commit 4cf5d7d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/108.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize rating objects for deepcopy
5 changes: 5 additions & 0 deletions openskill/models/weng_lin/bradley_terry_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return hash((self.id, self.mu, self.sigma))

def __deepcopy__(self, memodict={}):
blf = BradleyTerryFullRating(self.mu, self.sigma, self.name)
blf.id = self.id
return blf

def __eq__(self, other: object) -> bool:
if isinstance(other, BradleyTerryFullRating):
if self.mu == other.mu and self.sigma == other.sigma:
Expand Down
5 changes: 5 additions & 0 deletions openskill/models/weng_lin/bradley_terry_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return hash((self.id, self.mu, self.sigma))

def __deepcopy__(self, memodict={}):
blp = BradleyTerryPartRating(self.mu, self.sigma, self.name)
blp.id = self.id
return blp

def __eq__(self, other: object) -> bool:
if isinstance(other, BradleyTerryPartRating):
if self.mu == other.mu and self.sigma == other.sigma:
Expand Down
6 changes: 6 additions & 0 deletions openskill/models/weng_lin/plackett_luce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import copy
import itertools
import marshal

This comment has been minimized.

Copy link
@mrkvicka22

mrkvicka22 Aug 22, 2023

I am assuming this was added intially to perform the serialization but was not used in the end. I suggest removing this import.

This comment has been minimized.

Copy link
@vivekjoshy

vivekjoshy Aug 23, 2023

Author Owner

Yes, it's a stray import when I was experimenting with marshal.

import math
import uuid
from functools import reduce
Expand Down Expand Up @@ -74,6 +75,11 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return hash((self.id, self.mu, self.sigma))

def __deepcopy__(self, memodict={}):
plr = PlackettLuceRating(self.mu, self.sigma, self.name)
plr.id = self.id
return plr

def __eq__(self, other: object) -> bool:
if isinstance(other, PlackettLuceRating):
if self.mu == other.mu and self.sigma == other.sigma:
Expand Down
5 changes: 5 additions & 0 deletions openskill/models/weng_lin/thurstone_mosteller_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return hash((self.id, self.mu, self.sigma))

def __deepcopy__(self, memodict={}):
tmf = ThurstoneMostellerFullRating(self.mu, self.sigma, self.name)
tmf.id = self.id
return tmf

def __eq__(self, other: object) -> bool:
if isinstance(other, ThurstoneMostellerFullRating):
if self.mu == other.mu and self.sigma == other.sigma:
Expand Down
5 changes: 5 additions & 0 deletions openskill/models/weng_lin/thurstone_mosteller_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def __str__(self) -> str:
def __hash__(self) -> int:
return hash((self.id, self.mu, self.sigma))

def __deepcopy__(self, memodict={}):
tmp = ThurstoneMostellerPartRating(self.mu, self.sigma, self.name)
tmp.id = self.id
return tmp

def __eq__(self, other: object) -> bool:
if isinstance(other, ThurstoneMostellerPartRating):
if self.mu == other.mu and self.sigma == other.sigma:
Expand Down

0 comments on commit 4cf5d7d

Please sign in to comment.