Skip to content
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

Fix trying to get pointer to None in svm/linear.pyx #5615

Merged
merged 4 commits into from
Oct 31, 2023
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/cuml/svm/linear.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ cdef class LinearSVMWrapper:
if self.dtype != np.float32 and self.dtype != np.float64:
raise TypeError('Input data type must be float32 or float64')

cdef uintptr_t Xptr = <uintptr_t>X.ptr
cdef uintptr_t yptr = <uintptr_t>y.ptr
cdef uintptr_t Xptr = <uintptr_t>X.ptr if X is not None else 0
cdef uintptr_t yptr = <uintptr_t>y.ptr if y is not None else 0
cdef uintptr_t swptr = <uintptr_t>sampleWeight.ptr \
if sampleWeight is not None else 0
cdef size_t nCols = 0
Expand Down
37 changes: 37 additions & 0 deletions python/cuml/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,43 @@ def assert_model(pickled_model, data):
pickle_save_load(tmpdir, create_mod, assert_model)


@pytest.mark.parametrize("datatype", [np.float32, np.float64])
@pytest.mark.parametrize(
"params", [{"probability": True}, {"probability": False}]
)
@pytest.mark.parametrize("multiclass", [True, False])
def test_linear_svc_pickle(tmpdir, datatype, params, multiclass):
result = {}

def create_mod():
model = cuml.svm.LinearSVC(**params)
iris = load_iris()
iris_selection = np.random.RandomState(42).choice(
[True, False], 150, replace=True, p=[0.75, 0.25]
)
X_train = iris.data[iris_selection]
y_train = iris.target[iris_selection]
if not multiclass:
y_train = (y_train > 0).astype(datatype)
data = [X_train, y_train]
result["model"] = model.fit(X_train, y_train)
return model, data

def assert_model(pickled_model, data):
if result["model"].probability:
print("Comparing probabilistic LinearSVC")
compare_probabilistic_svm(
result["model"], pickled_model, data[0], data[1], 0, 0
)
else:
print("comparing base LinearSVC")
pred_before = result["model"].predict(data[0])
pred_after = pickled_model.predict(data[0])
assert array_equal(pred_before, pred_after)

pickle_save_load(tmpdir, create_mod, assert_model)


@pytest.mark.parametrize("datatype", [np.float32, np.float64])
@pytest.mark.parametrize("nrows", [unit_param(500)])
@pytest.mark.parametrize("ncols", [unit_param(16)])
Expand Down