Skip to content

Commit

Permalink
remove unused IndexedVector
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed May 20, 2018
1 parent 151c75f commit b1e6243
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 63 deletions.
3 changes: 0 additions & 3 deletions src/JuMP.jl
Expand Up @@ -129,9 +129,6 @@ mutable struct Model <: AbstractModel
# printhook


# # storage vector for merging duplicate terms
# indexedVector::IndexedVector{Float64}

nlpdata#::NLPData

objdict::Dict{Symbol,Any} # dictionary from variable and constraint names to objects
Expand Down
60 changes: 0 additions & 60 deletions src/utils.jl
Expand Up @@ -3,66 +3,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

mutable struct IndexedVector{T}
elts::Vector{T}
nzidx::Vector{Int}
nnz::Int
empty::BitArray{1}
end

IndexedVector(::Type{T},n::Integer) where {T} = IndexedVector(zeros(T,n),zeros(Int,n),0,trues(n))

function addelt!(v::IndexedVector{T},i::Integer,val::T) where T
if val != zero(T)
if v.empty[i] # new index
v.elts[i] = val
v.nzidx[v.nnz += 1] = i
v.empty[i] = false
else
v.elts[i] += val
end
end
return nothing
end

function rmz!(v::IndexedVector{T}) where T
i = 1
while i <= v.nnz
j = v.nzidx[i]
if v.elts[j] == zero(T)
v.empty[j] = true
# If i == v.nnz then this has no effect but it would be inefficient to branch
v.nzidx[i] = v.nzidx[v.nnz]
v.nnz -= 1
else
i += 1
end
end
end

function Base.empty!(v::IndexedVector{T}) where T
elts = v.elts
nzidx = v.nzidx
empty = v.empty
for i in 1:v.nnz
elts[nzidx[i]] = zero(T)
empty[nzidx[i]] = true
end
v.nnz = 0
end

Base.length(v::IndexedVector) = length(v.elts)
function Base.resize!(v::IndexedVector, n::Integer)
if n > length(v)
@assert v.nnz == 0 # only resize empty vector
resize!(v.elts, n)
fill!(v.elts,0)
resize!(v.nzidx, n)
resize!(v.empty, n)
fill!(v.empty,true)
end
end

# lightweight unsafe view for vectors
# it seems that the only way to avoid triggering
# allocations is to have only bitstype fields, so
Expand Down

0 comments on commit b1e6243

Please sign in to comment.