Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 140c02b

Browse files
committed
fix: don't error on detecting arrays with undefined entries
1 parent 5f2c3ea commit 140c02b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLDataDevices"
22
uuid = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
33
authors = ["Avik Pal <[email protected]> and contributors"]
4-
version = "1.0.2"
4+
version = "1.0.3"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/internal.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ end
118118

119119
for op in (:get_device, :get_device_type)
120120
cpu_ret_val = op == :get_device ? CPUDevice() : CPUDevice
121+
not_assigned_msg = "AbstractArray has some undefined references. Giving up, returning \
122+
$(cpu_ret_val)..."
121123

122124
@eval begin
123125
function $(op)(x::AbstractArray{T}) where {T}
124-
recursive_array_eltype(T) &&
126+
if recursive_array_eltype(T)
127+
if any(!isassigned(x, i) for i in eachindex(x))
128+
@warn $(not_assigned_msg)
129+
return $(cpu_ret_val)
130+
end
125131
return mapreduce(MLDataDevices.$(op), combine_devices, x)
132+
end
126133
if hasmethod(parent, Tuple{typeof(x)})
127134
parent_x = parent(x)
128135
parent_x === x && return $(cpu_ret_val)

test/misc_tests.jl

+7
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ end
148148
return_val2(x) = Val(get_device(x))
149149
@test @inferred(return_val2(ps)) isa Val{cpu_device()}
150150
end
151+
152+
@testset "undefined references array" begin
153+
x = Matrix{Any}(undef, 10, 10)
154+
155+
@test get_device(x) isa CPUDevice
156+
@test get_device_type(x) <: CPUDevice
157+
end

0 commit comments

Comments
 (0)