Skip to content

Commit

Permalink
Merge pull request #480 from mdekstrand/tweak/numpy-update
Browse files Browse the repository at this point in the history
Allow NumPy 2.0
  • Loading branch information
mdekstrand authored Aug 25, 2024
2 parents 2f5b8d1 + 6f63af5 commit d2a5cee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions lenskit-funksvd/lenskit/funksvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

@jitclass(
[
("user_features", n.double[:, :]),
("item_features", n.double[:, :]),
("user_features", n.float64[:, :]),
("item_features", n.float64[:, :]),
("feature_count", n.int32),
("user_count", n.int32),
("item_count", n.int32),
("initial_value", n.double),
("initial_value", n.float64),
]
) # type: ignore
class Model:
Expand All @@ -48,8 +48,8 @@ def __init__(self, umat, imat):


def _fresh_model(nfeatures, nusers, nitems, init=0.1):
umat = np.full([nusers, nfeatures], init, dtype=np.float_)
imat = np.full([nitems, nfeatures], init, dtype=np.float_)
umat = np.full([nusers, nfeatures], init, dtype=np.float64)
imat = np.full([nitems, nfeatures], init, dtype=np.float64)
model = Model(umat, imat)
model.initial_value = init
assert model.feature_count == nfeatures
Expand All @@ -61,10 +61,10 @@ def _fresh_model(nfeatures, nusers, nitems, init=0.1):
@jitclass(
[
("iter_count", n.int32),
("lrate", n.double),
("reg_term", n.double),
("rmin", n.double),
("rmax", n.double),
("lrate", n.float64),
("reg_term", n.float64),
("rmin", n.float64),
("rmax", n.float64),
]
) # type: ignore
class _Params:
Expand All @@ -86,7 +86,7 @@ def make_params(niters, lrate, reg, range):
return _Params(niters, lrate, reg, rmin, rmax)


@jitclass([("est", n.double[:]), ("feature", n.int32), ("trail", n.double)]) # type: ignore
@jitclass([("est", n.float64[:]), ("feature", n.int32), ("trail", n.float64)]) # type: ignore
class _FeatContext:
def __init__(self, est, feature, trail):
self.est = est
Expand All @@ -98,8 +98,8 @@ def __init__(self, est, feature, trail):
[
("users", n.int32[:]),
("items", n.int32[:]),
("ratings", n.double[:]),
("bias", n.double[:]),
("ratings", n.float64[:]),
("bias", n.float64[:]),
("n_samples", n.uint64),
]
) # type: ignore
Expand Down Expand Up @@ -277,11 +277,11 @@ def fit(self, data: Dataset, **kwargs):

users = np.array(rate_df["user_num"])
items = np.array(rate_df["item_num"])
ratings = np.array(rate_df["rating"], dtype=np.float_)
ratings = np.array(rate_df["rating"], dtype=np.float64)

_logger.debug("[%s] computing initial estimates", timer)
if self.bias:
initial = np.full(len(users), self.bias.mean_, dtype=np.float_)
initial = np.full(len(users), self.bias.mean_, dtype=np.float64)
if self.bias.item_offsets_ is not None:
initial += self.bias.item_offsets_.values[items]
if self.bias.user_offsets_ is not None:
Expand Down
2 changes: 1 addition & 1 deletion lenskit-implicit/tests/test_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_implicit_als_batch_accuracy(ml_100k, n_jobs):

def eval(train, test):
_log.info("running training")
train["rating"] = train.rating.astype(np.float_)
train["rating"] = train.rating.astype(np.float32)
algo = util.clone(algo_t)
algo.fit(from_interactions_df(train))
users = test.user.unique()
Expand Down
10 changes: 5 additions & 5 deletions lenskit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ license = { file = "LICENSE.md" }
dynamic = ["version"]
dependencies = [
"pandas >=1.5, <3",
"numpy >= 1.23,<2",
"numpy >= 1.23",
"scipy >= 1.9.0",
"torch ~=2.1", # conda: pytorch>=2.1,<3
"torch ~=2.1", # conda: pytorch>=2.1,<3
"threadpoolctl >=3.0",
"pydantic >=2.8,<3",
"seedbank >=0.2.0a2", # conda: @pip
"progress-api >=0.1.0a9", # conda: @pip
"manylog >=0.1.0a5", # conda: @pip
"seedbank >=0.2.0a2", # conda: @pip
"progress-api >=0.1.0a9", # conda: @pip
"manylog@git+https://github.com/mdekstrand/manylog.git", # conda: @pip
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/algorithms/test_als_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_als_implicit_batch_accuracy(ml_100k):
ratings = load_movielens_df(lktu.ml_100k_zip)

def eval(train, test):
train = train.astype({"rating": np.float_})
train = train.astype({"rating": np.float32})
_log.info("training implicit MF")
ials_algo = als.ImplicitMF(25, epochs=20)
ials_algo = Recommender.adapt(ials_algo)
Expand Down

0 comments on commit d2a5cee

Please sign in to comment.