Skip to content
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

Test fast initialization of IndexedVarArray #38

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hellemo
Copy link
Member

@hellemo hellemo commented Feb 5, 2023

It would be nice to have faster initialization in cases where we know the nzs. Not quite happy with this solution:

  • would prefer to use immutable structs
  • better suggestion for API
  • possible to integrate with macros?
using SparseVariables, JuMP
using BenchmarkTools

sparse_keys(N) = unique((rand(1:N), rand(1:N), rand(1:N)) for _ in 1:N)
N = 100_000
D = sparse_keys(N)

function test1(N, D) # Replace data
    model = Model()
    @variable(model, x[i = 1:N, j = 1:N, k = 1:N], container = IndexedVarArray)
    SparseVariables.unsafe_initializevars!(x, D)
    return x
end

function test2(N, D) # Insert iteratively
    model = Model()
    @variable(model, x[i = 1:N, j = 1:N, k = 1:N], container = IndexedVarArray)
    @inbounds for d in D
        SparseVariables.unsafe_insertvar!(x, d...)
    end
    return x
end

function test3(N, D) # Update data with from new Dictionary
    model = Model()
    @variable(model, x[i = 1:N, j = 1:N, k = 1:N], container = IndexedVarArray)
    SparseVariables.unsafe_initializevars_alt!(x, D)
    return x
end
julia> @btime test1(N,D);
  48.202 ms (1398734 allocations: 62.89 MiB)

julia> @btime test2(N,D);
  75.165 ms (1598754 allocations: 78.49 MiB)

julia> @btime test3(N,D);
  60.305 ms (1398770 allocations: 76.68 MiB)

@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2023

Codecov Report

Base: 84.82% // Head: 81.75% // Decreases project coverage by -3.08% ⚠️

Coverage data is based on head (60b6942) compared to base (09629d9).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
- Coverage   84.82%   81.75%   -3.08%     
==========================================
  Files           4        4              
  Lines         290      296       +6     
==========================================
- Hits          246      242       -4     
- Misses         44       54      +10     
Impacted Files Coverage Δ
src/indexedarray.jl 90.47% <100.00%> (+0.57%) ⬆️
src/dictionaries.jl 77.41% <0.00%> (-8.07%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

2 participants