|
1 | | -@testitem "Device Eltype Functionality" setup = [SharedTestSetup] tags = [:misc] begin |
2 | | - using MLDataDevices, Random, Test |
| 1 | +using MLDataDevices, Random, Test |
3 | 2 |
|
| 3 | +@testset "Device Eltype Functionality" begin |
4 | 4 | @testset "CPU Device with Eltype" begin |
5 | 5 | # Test default behavior (missing eltype) |
6 | 6 | cpu_default = cpu_device() |
7 | 7 | @test cpu_default isa CPUDevice{Missing} |
8 | 8 |
|
9 | 9 | # Test eltype=nothing (preserve type) |
10 | | - cpu_preserve = cpu_device(; eltype=nothing) |
| 10 | + cpu_preserve = cpu_device(nothing) |
11 | 11 | @test cpu_preserve isa CPUDevice{Nothing} |
12 | 12 |
|
13 | 13 | # Test specific eltype |
14 | | - cpu_f32 = cpu_device(; eltype=Float32) |
| 14 | + cpu_f32 = cpu_device(Float32) |
15 | 15 | @test cpu_f32 isa CPUDevice{Float32} |
16 | 16 |
|
17 | | - cpu_f64 = cpu_device(; eltype=Float64) |
| 17 | + cpu_f64 = cpu_device(Float64) |
18 | 18 | @test cpu_f64 isa CPUDevice{Float64} |
19 | 19 |
|
20 | 20 | # Test invalid eltype |
21 | | - @test_throws ArgumentError cpu_device(eltype=Int) |
22 | | - @test_throws ArgumentError cpu_device(eltype=String) |
| 21 | + @test_throws MethodError cpu_device(Int) |
| 22 | + @test_throws MethodError cpu_device(String) |
23 | 23 | end |
24 | 24 |
|
25 | 25 | @testset "CPU Device Array Conversion" begin |
|
34 | 34 | @test y_f64 == x_f64 |
35 | 35 |
|
36 | 36 | # Test nothing eltype (preserve) |
37 | | - cpu_preserve = cpu_device(; eltype=nothing) |
| 37 | + cpu_preserve = cpu_device(nothing) |
38 | 38 | y_f64_preserve = cpu_preserve(x_f64) |
39 | 39 | @test eltype(y_f64_preserve) === Float64 |
40 | 40 | @test y_f64_preserve == x_f64 |
41 | 41 |
|
42 | 42 | # Test specific eltype conversion |
43 | | - cpu_f32 = cpu_device(; eltype=Float32) |
| 43 | + cpu_f32 = cpu_device(Float32) |
44 | 44 | y_f32 = cpu_f32(x_f64) |
45 | 45 | @test eltype(y_f32) === Float32 |
46 | 46 | @test y_f32 ≈ Float32.(x_f64) |
|
57 | 57 | @test y_complex ≈ ComplexF32.(x_complex) |
58 | 58 | end |
59 | 59 |
|
60 | | - @testset "GPU Device Creation with Eltype" begin |
61 | | - # Test default behavior |
62 | | - try |
63 | | - gpu_default = gpu_device(; eltype=nothing) |
64 | | - @test MLDataDevices.get_eltype(gpu_default) === Nothing |
65 | | - catch e |
66 | | - if e isa MLDataDevices.Internal.DeviceSelectionException |
67 | | - @test_skip "No functional GPU available" |
68 | | - else |
69 | | - rethrow() |
70 | | - end |
71 | | - end |
72 | | - |
73 | | - try |
74 | | - gpu_f32 = gpu_device(; eltype=Float32) |
75 | | - @test MLDataDevices.get_eltype(gpu_f32) === Float32 |
76 | | - catch e |
77 | | - if e isa MLDataDevices.Internal.DeviceSelectionException |
78 | | - @test_skip "No functional GPU available" |
79 | | - else |
80 | | - rethrow() |
81 | | - end |
82 | | - end |
83 | | - end |
84 | | - |
85 | | - @testset "Reactant Device with Eltype" begin |
86 | | - # Test eltype parameter |
87 | | - reactant_default = reactant_device(; eltype=nothing) |
88 | | - @test reactant_default isa CPUDevice{Nothing} # Falls back to CPU since Reactant not loaded |
89 | | - |
90 | | - reactant_f32 = reactant_device(; eltype=Float32) |
91 | | - @test reactant_f32 isa CPUDevice{Float32} # Falls back to CPU since Reactant not loaded |
92 | | - end |
93 | | - |
94 | | - @testset "Helper Functions" begin |
95 | | - cpu_f32 = cpu_device(; eltype=Float32) |
96 | | - cpu_f64 = cpu_device(; eltype=Float64) |
97 | | - cpu_nothing = cpu_device(; eltype=nothing) |
98 | | - |
99 | | - # Test get_eltype |
100 | | - @test MLDataDevices.get_eltype(cpu_f32) === Float32 |
101 | | - @test MLDataDevices.get_eltype(cpu_f64) === Float64 |
102 | | - @test MLDataDevices.get_eltype(cpu_nothing) === Nothing |
103 | | - |
104 | | - # Test with_eltype |
105 | | - cpu_new = MLDataDevices.with_eltype(cpu_f32, Float64) |
106 | | - @test MLDataDevices.get_eltype(cpu_new) === Float64 |
107 | | - end |
108 | | - |
109 | 60 | @testset "Device Constructor Backward Compatibility" begin |
110 | 61 | # Test that old constructors still work |
111 | 62 | cpu_old = CPUDevice() |
|
0 commit comments