Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CI Adapt handling of discarded fused typed memoryview #25425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
5 changes: 3 additions & 2 deletions sklearn/datasets/_svmlight_format_fast.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def _dump_svmlight_file(
bint y_is_sp,
):
cdef bint X_is_integral
cdef bint query_id_is_not_empty = query_id.size > 0
X_is_integral = X.dtype.kind == "i"
if X_is_integral:
value_pattern = "%d:%d"
Expand All @@ -198,7 +199,7 @@ def _dump_svmlight_file(
label_pattern = "%.16g"

line_pattern = "%s"
if query_id is not None:
if query_id_is_not_empty:
line_pattern += " qid:%d"
line_pattern += " %s\n"

Expand Down Expand Up @@ -246,7 +247,7 @@ def _dump_svmlight_file(
else:
labels_str = label_pattern % y[i,0]

if query_id is not None:
if query_id_is_not_empty:
feat = (labels_str, query_id[i], s)
else:
feat = (labels_str, s)
Expand Down
8 changes: 7 additions & 1 deletion sklearn/datasets/_svmlight_format_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,13 @@ def dump_svmlight_file(
if hasattr(X, "sort_indices"):
X.sort_indices()

if query_id is not None:
if query_id is None:
# NOTE: query_id is passed to Cython functions using a fused type on query_id.
# Yet as of Cython>=3.0, memory views can't be None otherwise the runtime
# would not known which concrete implementation to dispatch the Python call to.
# TODO: simplify interfaces and implementations in _svmlight_format_fast.pyx.
query_id = np.array([], dtype=np.int32)
else:
query_id = np.asarray(query_id)
if query_id.shape[0] != y.shape[0]:
raise ValueError(
Expand Down