Potentially unsafe cast in sklearn.utils.multiclass.type_of_target

### Discussed in https://github.com/scikit-learn/scikit-learn/discussions/25835

<div type='discussions-op-text'>

<sup>Originally posted by **thomasryck** March 13, 2023</sup>
Hi

I was using the method type_of_target from the multiclass file.
And I had some warnings because of the following [line](https://github.com/scikit-learn/scikit-learn/blob/e305e800a419e766a312174159e15b071c3fe994/sklearn/utils/multiclass.py#L380).
Indeed as there is a cast into int32, and I have some int64 and float64 arrays, the cast is not safe.
I was asking myself if it could be a could idea to modify the test and to test by taking the floor of the array in place of doing a cast.
I do not know if it is really better, for now I just think that it could avoid not safe cast (that are not risky in that case).
And I do not know what is the best regarding time and memory.</div>

COMMENT:
I did some really quick tests concerning the implementation of this test:

I tried with float and integer matrices of size (30000,20000) and (3, 2)

The first results correspond to the float matrices :

```
import numpy as np

def test_is_real_float_floor():
    arr = np.random.rand(30000,20000)
    if (np.floor(arr) == arr).all():
        pass

def test_is_real_float():
    arr = np.random.rand(30000,20000)
    if (arr % 1 == 0).all():
        pass
```

For (30000, 20000) matrices :

```
python -mtimeit -n 10 -s'import bench_sk' 'bench_sk.test_is_real_float()'
10 loops, best of 5: 11.2 sec per loop
python -mtimeit -n 10 -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
10 loops, best of 5: 8.33 sec per loop
```
For (3, 2) matrices :

```
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
50000 loops, best of 5: 4.01 usec per loop
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float()'
50000 loops, best of 5: 6.95 usec per loop
```

For the second batch of results I changed

> np.random.rand(30000,20000)

by 

> np.random.randint(10, size=(30000,20000))


For (30000, 20000) matrices :

```
python -mtimeit -n 10 -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
10 loops, best of 5: 12.5 sec per loop
python -mtimeit -n 10 -s'import bench_sk' 'bench_sk.test_is_real_float()'
10 loops, best of 5: 19 sec per loop

```
For (3, 2) matrices :

```
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
20000 loops, best of 5: 12 usec per loop
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float()'
20000 loops, best of 5: 11.4 usec per loop
```

For (300, 200) matrices :

```
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float()'
200 loops, best of 5: 1.63 msec per loop
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
200 loops, best of 5: 1.17 msec per loop
```

For (3000, 2000) matrices :

```
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float_floor()'
2 loops, best of 5: 126 msec per loop
python -mtimeit -s'import bench_sk' 'bench_sk.test_is_real_float()'
2 loops, best of 5: 183 msec per loop
```

So I will create a pull request with the floor implementation.

Labels: Bug