Skip to content

Fix squeeze dimension in test logits calculation#28

Open
JulianAssmann wants to merge 1 commit into
SAP-samples:mainfrom
JulianAssmann:fix/squeeze
Open

Fix squeeze dimension in test logits calculation#28
JulianAssmann wants to merge 1 commit into
SAP-samples:mainfrom
JulianAssmann:fix/squeeze

Conversation

@JulianAssmann

@JulianAssmann JulianAssmann commented Mar 24, 2026

Copy link
Copy Markdown

Fixes #27.

Issue
SAP_RPT_OSS_Regressor.predict() raised an error when called with a single-row DataFrame during regression tasks:

The root cause is In sap_rpt_oss/model/torch_model.py, line 361, where .squeeze() is called without specifying a dimension. When there is only one test sample, this removes all size-1 dimensions, collapsing the tensor to a 0-d scalar. The subsequent np.concatenate call then fails because it cannot concatenate zero-dimensional arrays.

Fix

# Before
test_logits = logits[test_mask].squeeze()

# After
test_logits = logits[test_mask].squeeze(-1)

Reproduce bug and verify fix

import numpy as np
import pandas as pd
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
import sap_rpt_oss

# Load data
data = fetch_california_housing()
X = pd.DataFrame(data.data, columns=data.feature_names)
y = data.target

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=500, random_state=42)

# Train model
model = sap_rpt_oss.SAP_RPT_OSS_Regressor()
model.fit(X_train, y_train)

# This works (multiple samples)
preds = model.predict(X_test.iloc[:5])
print(f"Multiple samples: {preds}")

# This works after the fix
single_pred = model.predict(X_test.iloc[[0]])
print(f"Single sample: {single_pred}")

@cla-assistant

cla-assistant Bot commented Mar 24, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant

cla-assistant Bot commented Mar 24, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-sample prediction fails with ValueError: zero-dimensional arrays cannot be concatenated

2 participants