forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): as_float_array implementation and test for sklearn fr…
…ontend (ivy-llc#22849) Co-authored-by: Ishtiaq Hussain <[email protected]>
- Loading branch information
1 parent
bfa22ec
commit b6e52a9
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from . import multiclass | ||
from .multiclass import * | ||
from . import validation | ||
from .validation import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import ivy | ||
from ivy.functional.frontends.numpy.func_wrapper import to_ivy_arrays_and_back | ||
|
||
|
||
@to_ivy_arrays_and_back | ||
def as_float_array(X, *, copy=True, force_all_finite=True): | ||
if X.dtype in [ivy.float32, ivy.float64]: | ||
return X.copy_array() if copy else X | ||
if ("bool" in X.dtype or "int" in X.dtype or "uint" in X.dtype) and ivy.itemsize(X) <= 4: | ||
return_dtype = ivy.float32 | ||
else: | ||
return_dtype = ivy.float64 | ||
return ivy.asarray(X, dtype=return_dtype) |
28 changes: 28 additions & 0 deletions
28
ivy_tests/test_ivy/test_frontends/test_sklearn/test_utils/test_validation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ivy_tests.test_ivy.helpers as helpers | ||
from ivy_tests.test_ivy.helpers import handle_frontend_test | ||
|
||
|
||
@handle_frontend_test( | ||
fn_tree="sklearn.utils.as_float_array", | ||
dtype_and_x=helpers.dtype_and_values( | ||
available_dtypes=helpers.get_dtypes("valid"), | ||
), | ||
) | ||
def test_sklearn_as_float_array( | ||
dtype_and_x, | ||
on_device, | ||
fn_tree, | ||
frontend, | ||
test_flags, | ||
backend_fw, | ||
): | ||
dtypes, x = dtype_and_x | ||
helpers.test_frontend_function( | ||
input_dtypes=dtypes, | ||
backend_to_test=backend_fw, | ||
test_flags=test_flags, | ||
fn_tree=fn_tree, | ||
frontend=frontend, | ||
on_device=on_device, | ||
X=x[0], | ||
) |