mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-11-19 07:20:28 +01:00
fix a nasty bug with negatives in ConstraintMatrix
This commit is contained in:
parent
0127d05594
commit
4e43811ea3
@ -50,10 +50,15 @@ ConstraintMatrix(nzeros::AbstractArray{<:Integer}, n, m, val::T) where {T} =
|
||||
|
||||
Base.size(cm::ConstraintMatrix) = cm.size
|
||||
|
||||
__get_positive(cm::ConstraintMatrix, idx::Integer) =
|
||||
convert(eltype(cm), cm.val * length(searchsorted(cm.pos, idx)))
|
||||
__get_negative(cm::ConstraintMatrix, idx::Integer) =
|
||||
convert(eltype(cm), cm.val * length(searchsorted(cm.neg, idx)))
|
||||
function __get_positive(cm::ConstraintMatrix, idx::Integer)
|
||||
return convert(eltype(cm), cm.val * length(searchsorted(cm.pos, idx)))
|
||||
end
|
||||
function __get_negative(cm::ConstraintMatrix, idx::Integer)
|
||||
return convert(
|
||||
eltype(cm),
|
||||
cm.val * length(searchsorted(cm.neg, idx; rev = true)),
|
||||
)
|
||||
end
|
||||
|
||||
Base.@propagate_inbounds function Base.getindex(
|
||||
cm::ConstraintMatrix,
|
||||
|
@ -1,12 +1,17 @@
|
||||
@testset "ConstraintMatrix" begin
|
||||
@test PropertyT.ConstraintMatrix{Float64}([-1, 2, -1, 1, 4, 2, 6], 3, 2, π) isa AbstractMatrix
|
||||
@test PropertyT.ConstraintMatrix{Float64}(
|
||||
[-1, 2, -1, 1, 4, 2, 6],
|
||||
3,
|
||||
2,
|
||||
π,
|
||||
) isa AbstractMatrix
|
||||
|
||||
cm = PropertyT.ConstraintMatrix{Float64}([-1, 2, -1, 1, 4, 2, 6], 3, 2, π)
|
||||
|
||||
@test cm == Float64[
|
||||
-π π
|
||||
2π 0.0
|
||||
0.0 π
|
||||
2π 0
|
||||
0 π
|
||||
]
|
||||
|
||||
@test collect(PropertyT.nzpairs(cm)) == [
|
||||
@ -18,4 +23,7 @@
|
||||
1 => -3.141592653589793
|
||||
1 => -3.141592653589793
|
||||
]
|
||||
|
||||
@test PropertyT.ConstraintMatrix{Float64}([-9:-1; 1:9], 3, 3, 1.0) ==
|
||||
zeros(3, 3)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user