Skip to content

Fix type instability due to mapslices in colorvec partial generation #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2020

Conversation

ChrisRackauckas
Copy link
Member

using BenchmarkTools, SparseArrays, SparseDiffTools, ForwardDiff
function f!(H, x)
    for n in 1:length(H)
        if isodd(n)
            H[n] = 2*x[1]
        else
            H[n] = 3*x[2]
        end
    end
end
H = zeros(10000)
x = 5.0 * ones(200)
f!(H, x)

pattern = sparse(vcat(collect(1:2:10000), collect(2:2:10000)), vcat(repeat([1], 5000), repeat([2], 5000)), 1, length(H), length(x))
jac = Float64.(sparse(pattern))
colors = matrix_colors(jac)
@btime forwarddiff_color_jacobian!(jac, f!, x, colorvec = colors);

goes from 9.993 ms (136398 allocations: 4.46 MiB) to 605.200 μs (696 allocations: 284.89 KiB)

@ChrisRackauckas
Copy link
Member Author

Tested locally due to SparsityDetection bug and passes, so merging.

@ChrisRackauckas ChrisRackauckas merged commit b8ee652 into master Apr 5, 2020
@ChrisRackauckas ChrisRackauckas deleted the speed branch April 5, 2020 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant