Skip to content

Commit

Permalink
Update order of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dustalov committed Aug 24, 2024
1 parent f08b3d9 commit 2efc970
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions python/evalica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,24 +483,24 @@ class EloResult(Generic[T]):
Attributes:
scores: The element scores.
index: The index.
win_weight: The win weight.
tie_weight: The tie weight.
initial: The initial score of each element.
base: The base of the exponent.
scale: The scale factor.
k: The K-factor.
win_weight: The win weight.
tie_weight: The tie weight.
solver: The solver.
"""

scores: pd.Series[float]
index: dict[T, int]
win_weight: float
tie_weight: float
initial: float
base: float
scale: float
k: float
win_weight: float
tie_weight: float
solver: str


Expand All @@ -509,12 +509,12 @@ def elo(
ys: Collection[T],
ws: Collection[Winner],
index: dict[T, int] | None = None,
win_weight: float = 1.0,
tie_weight: float = 0.5,
initial: float = 1000.,
base: float = 10.,
scale: float = 400.,
k: float = 4.,
win_weight: float = 1.0,
tie_weight: float = 0.5,
solver: Literal["naive", "pyo3"] = "pyo3",
) -> EloResult[T]:
"""
Expand All @@ -528,12 +528,12 @@ def elo(
ys: The right-hand side elements.
ws: The winner elements.
index: The index.
win_weight: The win weight.
tie_weight: The tie weight.
initial: The initial score of each element.
base: The base of the exponent.
scale: The scale factor.
k: The K-factor.
win_weight: The win weight.
tie_weight: The tie weight.
solver: The solver.
Returns:
Expand All @@ -545,19 +545,19 @@ def elo(
assert index is not None, "index is None"

if solver == "pyo3":
scores = elo_pyo3(xs_indexed, ys_indexed, ws, len(index), win_weight, tie_weight, initial, base, scale, k)
scores = elo_pyo3(xs_indexed, ys_indexed, ws, len(index), initial, base, scale, k, win_weight, tie_weight)
else:
scores = elo_naive(xs_indexed, ys_indexed, ws, len(index), win_weight, tie_weight, initial, base, scale, k)
scores = elo_naive(xs_indexed, ys_indexed, ws, len(index), initial, base, scale, k, win_weight, tie_weight)

return EloResult(
scores=pd.Series(scores, index=index, name=elo.__name__).sort_values(ascending=False, kind="stable"),
index=index,
win_weight=win_weight,
tie_weight=tie_weight,
initial=initial,
base=base,
scale=scale,
k=k,
win_weight=win_weight,
tie_weight=tie_weight,
solver=solver,
)

Expand Down
4 changes: 2 additions & 2 deletions python/evalica/evalica.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def elo_pyo3(
ys: npt.ArrayLike,
ws: Collection[Winner],
total: int,
win_weight: float,
tie_weight: float,
initial: float,
base: float,
scale: float,
k: float,
win_weight: float,
tie_weight: float,
) -> npt.NDArray[np.float64]: ...


Expand Down
4 changes: 2 additions & 2 deletions python/evalica/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def elo(
ys: Collection[int],
ws: Collection[Winner],
total: int,
win_weight: float = 1.0,
tie_weight: float = 0.5,
initial: float = 1000.,
base: float = 10.,
scale: float = 400.,
k: float = 30.,
win_weight: float = 1.0,
tie_weight: float = 0.5,
) -> npt.NDArray[np.float64]:
if len(xs) != len(ys) or len(xs) != len(ws) or len(ys) != len(ws):
raise LengthMismatchError
Expand Down
12 changes: 6 additions & 6 deletions python/evalica/test_evalica.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ def test_newman(comparison: Comparison, v_init: float) -> None:

@given(
comparison=comparisons(),
win_weight=st.floats(0., 10.),
tie_weight=st.floats(0., 10.),
initial=st.floats(0., 1000.),
base=st.floats(0., 1000.),
scale=st.floats(0., 1000.),
k=st.floats(0., 1000.),
win_weight=st.floats(0., 10.),
tie_weight=st.floats(0., 10.),
)
def test_elo(
comparison: Comparison,
Expand All @@ -227,23 +227,23 @@ def test_elo(

result_pyo3 = evalica.elo(
xs, ys, ws,
win_weight=win_weight,
tie_weight=tie_weight,
initial=initial,
base=base,
scale=scale,
k=k,
win_weight=win_weight,
tie_weight=tie_weight,
solver="pyo3",
)

result_naive = evalica.elo(
xs, ys, ws,
win_weight=win_weight,
tie_weight=tie_weight,
initial=initial,
base=base,
scale=scale,
k=k,
win_weight=win_weight,
tie_weight=tie_weight,
solver="naive",
)

Expand Down
4 changes: 2 additions & 2 deletions src/elo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pub fn elo<A: Float + AddAssign>(
ys: &ArrayView1<usize>,
ws: &ArrayView1<Winner>,
total: usize,
win_weight: A,
tie_weight: A,
initial: A,
base: A,
scale: A,
k: A,
win_weight: A,
tie_weight: A,
) -> Result<Array1<A>, ShapeError> {
check_lengths!(xs.len(), ys.len(), ws.len());

Expand Down
8 changes: 4 additions & 4 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,24 @@ fn elo_pyo3<'py>(
ys: PyArrayLike1<'py, usize>,
ws: PyArrayLike1<'py, Winner>,
total: usize,
win_weight: f64,
tie_weight: f64,
initial: f64,
base: f64,
scale: f64,
k: f64,
win_weight: f64,
tie_weight: f64,
) -> PyResult<Py<PyArray1<f64>>> {
match elo(
&xs.as_array(),
&ys.as_array(),
&ws.as_array(),
total,
win_weight,
tie_weight,
initial,
base,
scale,
k,
win_weight,
tie_weight,
) {
Ok(scores) => Ok(scores.into_pyarray_bound(py).unbind()),
Err(_) => Err(LengthMismatchError::new_err("mismatching input shapes")),
Expand Down

0 comments on commit 2efc970

Please sign in to comment.