Skip to content

Commit

Permalink
WO for checking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samir-nasibli committed Sep 30, 2024
1 parent aa14417 commit 05473c5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
20 changes: 11 additions & 9 deletions onedal/datatypes/_data_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
import dpnp


def _apply_and_pass(func, *args, **kwargs):
def _apply_and_pass(func, *args):
if len(args) == 1:
return func(args[0], **kwargs)
return tuple(map(func, args, kwargs))


def from_table(*args, sua_iface=None, xp=None):
return _apply_and_pass(convert_one_from_table, *args, sua_iface=sua_iface, xp=xp)
return func(args[0])
return tuple(map(func, args))


# TODO:
Expand All @@ -47,6 +43,8 @@ def from_table(*args, sua_iface=None, xp=None):
# sparse for sua data.
# TODO:
# update it for each of the datafrmae format.
# TODO:
# update func use with args and kwargs with _apply_and_pass.
def convert_one_from_table(table, sua_iface=None, xp=None):
# Currently only `__sycl_usm_array_interface__` protocol used to
# convert into dpnp/dpctl tensors.
Expand All @@ -68,8 +66,12 @@ def convert_one_to_table(arg, sua_iface=None):
return _backend.to_table(arg)


def to_table(*args, sua_iface=None):
return _apply_and_pass(convert_one_to_table, *args, sua_iface=sua_iface)
def from_table(*args):
return _apply_and_pass(convert_one_from_table, *args)


def to_table(*args):
return _apply_and_pass(convert_one_to_table, *args)


if _is_dpc_backend:
Expand Down
10 changes: 8 additions & 2 deletions onedal/datatypes/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
from onedal import _backend
from onedal._device_offload import dpctl_available, dpnp_available
from onedal.datatypes import from_table, to_table

# TODO:
# re-impl and used from_table, to_table instead.
from onedal.datatypes._data_conversion import convert_one_from_table, convert_one_to_table
from onedal.primitives import linear_kernel
from onedal.tests.utils._dataframes_support import (
_convert_to_dataframe,
Expand Down Expand Up @@ -211,11 +215,13 @@ def test_input_sua_iface_zero_copy(dataframe, queue, order, dtype):

sua_iface, X_dp_namespace, _ = _get_sycl_namespace(X_dp)

X_table = to_table(X_dp, sua_iface=sua_iface)
X_table = convert_one_to_table(X_dp, sua_iface=sua_iface)

assert hasattr(X_table, "__sycl_usm_array_interface__")

X_dp_from_table = from_table(X_table, sua_iface=sua_iface, xp=X_dp_namespace)
X_dp_from_table = convert_one_from_table(
X_table, sua_iface=sua_iface, xp=X_dp_namespace
)

_check_attributes_for_zero_copy(X_dp, X_dp_from_table, order)

Expand Down
31 changes: 19 additions & 12 deletions sklearnex/tests/test_memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,27 @@ def gen_functions(functions):


if dpctl_available:
from onedal.datatypes import from_table, to_table
# TODO:
# use from_table, to_table.
from onedal.datatypes._data_conversion import (
convert_one_from_table,
convert_one_to_table,
)

class DummyEstimatorWithTableConversions(BaseEstimator):

# __name__ = 'DummyEstimatorWithTableConversions'

def fit(self, X, y=None):
_, sua_iface, _ = _get_sycl_namespace(X)
X_table = to_table(X, sua_iface=sua_iface)
y_table = to_table(y, sua_iface=sua_iface)
sua_iface, _, _ = _get_sycl_namespace(X)
X_table = convert_one_to_table(X, sua_iface=sua_iface)
y_table = convert_one_to_table(y, sua_iface=sua_iface)
return self

def predict(self, X):
xp, sua_iface, _ = _get_sycl_namespace(X)
X_table = to_table(X, sua_iface=sua_iface)
returned_X = from_table(X_table, sua_iface=sua_iface, xp=xp)
sua_iface, xp, _ = _get_sycl_namespace(X)
X_table = convert_one_to_table(X, sua_iface=sua_iface)
returned_X = convert_one_from_table(X_table, sua_iface=sua_iface, xp=xp)
return returned_X

DUMMY_ESTIMATOR_WITH_TABLE_CONVERSIONS = {
Expand Down Expand Up @@ -209,14 +214,16 @@ def split_train_inference(kf, x, y, estimator, queue=None):
return mem_tracks


def _kfold_function_template(
estimator, dataframe, data_shape, queue=None, func=None, get_data_func=None
):
# TODO:
# def _kfold_function_template(estimator, dataframe, data_shape, queue=None, func=None, get_data_func=None):
# add custom get_data_func.
def _kfold_function_template(estimator, dataframe, data_shape, queue=None, func=None):
tracemalloc.start()

n_samples, n_features = data_shape
get_data_func = get_data_func if get_data_func else gen_clsf_data
X, y, data_memory_size = get_data_func(n_samples, n_features)
# get_data_func = get_data_func if get_data_func else gen_clsf_data
# X, y, data_memory_size = get_data_func(n_samples, n_features)
X, y, data_memory_size = gen_clsf_data(n_samples, n_features)
kf = KFold(n_splits=N_SPLITS)
if func:
X = func(X)
Expand Down

0 comments on commit 05473c5

Please sign in to comment.