Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/fasttext_module/fasttext/FastText.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def score_vs_true(self, label):
else:
y_scores, y_true = ([], ())

return np.array(y_scores, copy=False), np.array(y_true, copy=False)
return np.asarray(y_scores), np.asarray(y_true)

def precision_recall_curve(self, label=None):
"""Return precision/recall curve"""
Expand All @@ -53,7 +53,7 @@ def precision_recall_curve(self, label=None):
else:
precision, recall = ([], ())

return np.array(precision, copy=False), np.array(recall, copy=False)
return np.asarray(precision), np.asarray(recall)

def precision_at_recall(self, recall, label=None):
"""Return precision for a given recall"""
Expand Down
21 changes: 21 additions & 0 deletions python/fasttext_module/fasttext/tests/test_meter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileContributor: Arthit Suriyawongkul
# SPDX-FileCopyrightText: 2026-present, fasttext-community
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: MIT

"""Meter curves must work with NumPy 2 (np.array copy=False raises there)."""

import numpy as np

from .helpers import build_supervised_model, get_random_data


def test_meter_returns_arrays(tmp_path):
data = get_random_data(100)
# thread=12: thread <= 10 leaves the input matrix partly uninitialized.
model = build_supervised_model(data, {"thread": 12})
path = tmp_path / "test.txt"
path.write_text("".join(f"__label__{line}\n" for line in data))
meter = model.get_meter(str(path))
for pair in (meter.score_vs_true(model.labels[0]), meter.precision_recall_curve()):
assert all(isinstance(a, np.ndarray) for a in pair)
Loading