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

Commit

Permalink
fix: don't error on detecting arrays with undefined entries
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Aug 21, 2024
1 parent 5f2c3ea commit c5533d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLDataDevices"
uuid = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "1.0.2"
version = "1.0.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
9 changes: 8 additions & 1 deletion src/internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ end

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

@eval begin
function $(op)(x::AbstractArray{T}) where {T}
recursive_array_eltype(T) &&
if recursive_array_eltype(T)
if any(!isassigned(x, i) for i in eachindex(x))
@warn $(not_assigned_msg)
return $(cpu_ret_val)
end
return mapreduce(MLDataDevices.$(op), combine_devices, x)
end
if hasmethod(parent, Tuple{typeof(x)})
parent_x = parent(x)
parent_x === x && return $(cpu_ret_val)
Expand Down
7 changes: 7 additions & 0 deletions test/misc_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ end
return_val2(x) = Val(get_device(x))
@test @inferred(return_val2(ps)) isa Val{cpu_device()}
end

@testset "undefined references array" begin
x = Matrix{Any}(undef, 10, 10)

@test get_device(x) isa CPUDevice
@test get_device_type(x) <: CPUDevice
end

0 comments on commit c5533d2

Please sign in to comment.