mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-26 10:35:29 +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
|
Base.size(cm::ConstraintMatrix) = cm.size
|
||||||
|
|
||||||
__get_positive(cm::ConstraintMatrix, idx::Integer) =
|
function __get_positive(cm::ConstraintMatrix, idx::Integer)
|
||||||
convert(eltype(cm), cm.val * length(searchsorted(cm.pos, idx)))
|
return convert(eltype(cm), cm.val * length(searchsorted(cm.pos, idx)))
|
||||||
__get_negative(cm::ConstraintMatrix, idx::Integer) =
|
end
|
||||||
convert(eltype(cm), cm.val * length(searchsorted(cm.neg, idx)))
|
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(
|
Base.@propagate_inbounds function Base.getindex(
|
||||||
cm::ConstraintMatrix,
|
cm::ConstraintMatrix,
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
@testset "ConstraintMatrix" begin
|
@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, π)
|
cm = PropertyT.ConstraintMatrix{Float64}([-1, 2, -1, 1, 4, 2, 6], 3, 2, π)
|
||||||
|
|
||||||
@test cm == Float64[
|
@test cm == Float64[
|
||||||
-π π
|
-π π
|
||||||
2π 0.0
|
2π 0
|
||||||
0.0 π
|
0 π
|
||||||
]
|
]
|
||||||
|
|
||||||
@test collect(PropertyT.nzpairs(cm)) == [
|
@test collect(PropertyT.nzpairs(cm)) == [
|
||||||
@ -18,4 +23,7 @@
|
|||||||
1 => -3.141592653589793
|
1 => -3.141592653589793
|
||||||
1 => -3.141592653589793
|
1 => -3.141592653589793
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@test PropertyT.ConstraintMatrix{Float64}([-9:-1; 1:9], 3, 3, 1.0) ==
|
||||||
|
zeros(3, 3)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user