mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2025-01-13 22:52:34 +01:00
make nzpairs(::ConstraintMatrix) type stable
This commit is contained in:
parent
132802feeb
commit
3f2be20152
@ -83,26 +83,29 @@ Base.@propagate_inbounds function Base.getindex(
|
|||||||
return pos - neg
|
return pos - neg
|
||||||
end
|
end
|
||||||
|
|
||||||
struct NZPairsIter{T}
|
struct NZPairsIter{T,I}
|
||||||
m::ConstraintMatrix{T}
|
m::ConstraintMatrix{T,I}
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.eltype(::Type{NZPairsIter{T}}) where {T} = Pair{Int,T}
|
Base.eltype(::Type{NZPairsIter{T}}) where {T} = Pair{Int,T}
|
||||||
Base.IteratorSize(::Type{<:NZPairsIter}) = Base.SizeUnknown()
|
Base.IteratorSize(::Type{<:NZPairsIter}) = Base.SizeUnknown()
|
||||||
|
|
||||||
# TODO: iterate over (idx=>val) pairs combining vals
|
# TODO: iterate over (idx=>val) pairs combining vals
|
||||||
function Base.iterate(itr::NZPairsIter, state::Tuple{Int,Int} = (1, 1))
|
function Base.iterate(
|
||||||
|
itr::NZPairsIter,
|
||||||
|
state::Tuple{Int,Nothing} = (1, nothing),
|
||||||
|
)
|
||||||
k = iterate(itr.m.pos, state[1])
|
k = iterate(itr.m.pos, state[1])
|
||||||
isnothing(k) && return iterate(itr, state[2])
|
isnothing(k) && return iterate(itr, (nothing, 1))
|
||||||
idx, st = k
|
idx, st = k
|
||||||
return idx => itr.m.val, (st, 1)
|
return idx => itr.m.val, (st, nothing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.iterate(itr::NZPairsIter, state::Int)
|
function Base.iterate(itr::NZPairsIter, state::Tuple{Nothing,Int})
|
||||||
k = iterate(itr.m.neg, state[1])
|
k = iterate(itr.m.neg, state[2])
|
||||||
isnothing(k) && return nothing
|
isnothing(k) && return nothing
|
||||||
idx, st = k
|
idx, st = k
|
||||||
return idx => -itr.m.val, st
|
return idx => -itr.m.val, (nothing, st)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user