Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/array_partition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,4 @@ end

function Adapt.adapt_structure(to, ap::ArrayPartition)
ArrayPartition(map(x -> Adapt.adapt(to, x), ap.x)...)
end
end
4 changes: 2 additions & 2 deletions src/named_array_partition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ end

#Overwrite ArrayInterface zeromatrix to work with NamedArrayPartitions & implicit solvers within OrdinaryDiffEq
function ArrayInterface.zeromatrix(A::NamedArrayPartition)
B = ArrayPartition(A)
x = reduce(vcat,vec.(B.x))
B = ArrayPartition(A)
x = reduce(vcat, vec.(B.x))
x .* x' .* false
end

Expand Down
4 changes: 2 additions & 2 deletions test/basic_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ u[1, [1, 3], 2] .= [7.0, 9.0]

# 3D inner arrays (tensors) with ragged third dimension
u = VectorOfArray([zeros(2, 1, n) for n in (2, 3)])
@test size(view(u, :, :, :, 1)) == (2, 1, 2)
@test size(view(u, :, :, :, 2)) == (2, 1, 3)
@test size(view(u,:,:,:,1)) == (2, 1, 2)
@test size(view(u,:,:,:,2)) == (2, 1, 3)
# assign into a slice of the second inner array using last index Int
u[2, 1, :, 2] .= [7.0, 8.0, 9.0]
@test vec(u.u[2][2, 1, :]) == [7.0, 8.0, 9.0]
Expand Down
14 changes: 7 additions & 7 deletions test/gpu/arraypartition_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ b = ArrayPartition(([0.0f0] |> cu, [0.0f0] |> cu, [0.0f0] |> cu))

# Test adapt from ArrayPartition with CuArrays to ArrayPartition with CPU arrays

a = CuArray(Float64.([1., 2., 3., 4.]))
b = CuArray(Float64.([1., 2., 3., 4.]))
a = CuArray(Float64.([1.0, 2.0, 3.0, 4.0]))
b = CuArray(Float64.([1.0, 2.0, 3.0, 4.0]))
part_a_gpu = ArrayPartition(a, b)
part_a = adapt(Array{Float32}, part_a_gpu)

c = Float32.([1., 2., 3., 4.])
d = Float32.([1., 2., 3., 4.])
c = Float32.([1.0, 2.0, 3.0, 4.0])
d = Float32.([1.0, 2.0, 3.0, 4.0])
part_b = ArrayPartition(c, d)

@test part_a == part_b # Test equality
Expand All @@ -42,7 +42,7 @@ for i in 1:length(part_a.x)
@test typeof(sub_a) === typeof(sub_b) # Test type equality
end

x = ArrayPartition((CUDA.zeros(2),CUDA.zeros(2)))
x = ArrayPartition((CUDA.zeros(2), CUDA.zeros(2)))
@test ArrayInterface.zeromatrix(x) isa CuMatrix
@test size(ArrayInterface.zeromatrix(x)) == (4,4)
@test maximum(abs, x) == 0f0
@test size(ArrayInterface.zeromatrix(x)) == (4, 4)
@test maximum(abs, x) == 0.0f0
3 changes: 1 addition & 2 deletions test/named_array_partition_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ using RecursiveArrayTools, ArrayInterface, Test
@test typeof(x .+ x[1:end]) <: Vector # test broadcast precedence
@test all(x .== x[1:end])
@test ArrayInterface.zeromatrix(x) isa Matrix
@test size(ArrayInterface.zeromatrix(x)) == (30,30)
@test size(ArrayInterface.zeromatrix(x)) == (30, 30)
y = copy(x)
@test zero(x, (10, 20)) == zero(x) # test that ignoring dims works
@test typeof(zero(x)) <: NamedArrayPartition
@test (y .*= 2).a[1] ≈ 2 # test in-place bcast


@test length(Array(x)) == 30
@test typeof(Array(x)) <: Array
Expand Down
10 changes: 5 additions & 5 deletions test/partitions_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ end
end

# Test adapt on ArrayPartition from Float64 to Float32 arrays
a = Float64.([1., 2., 3., 4.])
b = Float64.([1., 2., 3., 4.])
a = Float64.([1.0, 2.0, 3.0, 4.0])
b = Float64.([1.0, 2.0, 3.0, 4.0])
part_a_64 = ArrayPartition(a, b)
part_a = adapt(Array{Float32}, part_a_64)

c = Float32.([1., 2., 3., 4.])
d = Float32.([1., 2., 3., 4.])
c = Float32.([1.0, 2.0, 3.0, 4.0])
d = Float32.([1.0, 2.0, 3.0, 4.0])
part_b = ArrayPartition(c, d)

@test part_a == part_b # Test equality of partitions
Expand All @@ -345,4 +345,4 @@ for i in 1:length(part_a.x)
sub_b = part_b.x[i]
@test sub_a == sub_b # Test for value equality
@test typeof(sub_a) === typeof(sub_b) # Test type equality
end
end
Loading