Skip to content

Commit 5eead9f

Browse files
committed
add test for BBB
1 parent f2d43ae commit 5eead9f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/test_ad.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using SparseDiffTools
22
using ForwardDiff: Dual, jacobian
33
using SparseArrays, Test
44
using LinearAlgebra
5+
using BlockBandedMatrices
56

67
fcalls = 0
78
function f(dx,x)
@@ -61,3 +62,22 @@ forwarddiff_color_jacobian!(_denseJ1, f, x, jac_cache)
6162
_Jt = similar(Tridiagonal(J))
6263
forwarddiff_color_jacobian!(_Jt, f, x, colorvec = repeat(1:3,10), sparsity = _Jt)
6364
@test _Jt J
65+
66+
#https://github.com/JuliaDiffEq/DiffEqDiffTools.jl/issues/67#issuecomment-516871956
67+
function f(out, x)
68+
x = reshape(x, 100, 100)
69+
out = reshape(out, 100, 100)
70+
for i in 1:100
71+
for j in 1:100
72+
out[i, j] = x[i, j] + x[max(i -1, 1), j] + x[min(i+1, size(x, 1)), j] + x[i, max(j-1, 1)] + x[i, min(j+1, size(x, 2))]
73+
end
74+
end
75+
return vec(out)
76+
end
77+
x = rand(10000)
78+
J = BandedBlockBandedMatrix(Ones(10000, 10000), (fill(100, 100), fill(100, 100)), (1, 1), (1, 1))
79+
Jsparse = sparse(J)
80+
colors = matrix_colors(J)
81+
forwarddiff_color_jacobian!(J, f, x, colorvec=colors)
82+
forwarddiff_color_jacobian!(Jsparse, f, x, colorvec=colors)
83+
@test J Jsparse

0 commit comments

Comments
 (0)