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
7 changes: 7 additions & 0 deletions src/named_array_partition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ end
return dest
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))
x .* x' .* false
end

# `x = find_NamedArrayPartition(x)` returns the first `NamedArrayPartition` among broadcast arguments.
find_NamedArrayPartition(bc::Base.Broadcast.Broadcasted) = find_NamedArrayPartition(bc.args)
function find_NamedArrayPartition(args::Tuple)
Expand Down
3 changes: 3 additions & 0 deletions test/named_array_partition_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ using RecursiveArrayTools, Test
@test x.a ≈ ones(10)
@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)
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
Loading