Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/Sets/Line2D/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
if m == 2
@inbounds if block[1] == 1 && block[2] == 2
return L # no projection
elseif block[1] == 2 && block[2] == 1
return Line2D(L.a[block], L.b) # swap a vector
else
throw(ArgumentError("invalid projection to $block"))
end
elseif m == 1
# projection to dimension i
cdims = constrained_dimensions(L)
if length(cdims) == 1
@inbounds if cdims[1] == block[1]
# L: aᵢxᵢ = b where aᵢ ≠ 0
return Singleton([L.b / L.a[cdims[1]]])
else
# L: aⱼxⱼ = b where i ≠ j
return Universe{N}(1)
end
# block[1] == 2 && block[2] == 1
return Line2D(L.a[block], L.b) # swap a vector
end
# projection to 1 dimension
cdims = constrained_dimensions(L)
if length(cdims) == 1
@inbounds if cdims[1] == block[1]
# L: aᵢxᵢ = b where aᵢ ≠ 0
return Singleton([L.b / L.a[cdims[1]]])
else
# L is constrained in both dimensions
@assert length(cdims) == 2
# L: aⱼxⱼ = b where i ≠ j
return Universe{N}(1)
end
else
throw(ArgumentError("cannot project a two-dimensional line to $m dimensions"))
end
# L is constrained in both dimensions
@assert length(cdims) == 2
return Universe{N}(1)
end

"""
Expand Down
4 changes: 4 additions & 0 deletions src/Validation/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ function validate_index_vector(v::AbstractVector{Int}, X::LazySet; fun::Function
"for dimension $n but received the vector $v"))
end
end
if length(unique(v)) < length(v)
throw(ArgumentError("`$(string(fun))` requires an index vector " *
"without duplicates but received the vector $v"))
end
return true
end
2 changes: 2 additions & 0 deletions test/Sets/EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ for N in @tN([Float64, Float32, Rational{Int}])
@test_throws DimensionMismatch permute(E, [1])
@test_throws DimensionMismatch permute(E, [1, -1])
@test_throws DimensionMismatch permute(E, [1, 3])
@test_throws ArgumentError permute(E, [1, 1])
E2 = permute(E, [2, 1])
@test isidentical(E, E2)

# project
@test_throws DimensionMismatch project(E, [1, 2, 3])
@test_throws DimensionMismatch project(E, [1, -1])
@test_throws DimensionMismatch project(E, [1, 3])
@test_throws ArgumentError project(E, [1, 1])
E2 = project(E, [2])
@test E2 isa EmptySet{N} && dim(E2) == 1

Expand Down
2 changes: 2 additions & 0 deletions test/Sets/Universe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ for N in @tN([Float64, Float32, Rational{Int}])
@test_throws DimensionMismatch permute(U, [1])
@test_throws DimensionMismatch permute(U, [1, -1])
@test_throws DimensionMismatch permute(U, [1, 3])
@test_throws ArgumentError permute(U, [1, 1])
U2 = permute(U, [2, 1])
@test isidentical(U, U2)

# project
@test_throws DimensionMismatch project(U, [1, 2, 3])
@test_throws DimensionMismatch project(U, [1, -1])
@test_throws DimensionMismatch project(U, [1, 3])
@test_throws ArgumentError project(U, [1, 1])
U2 = project(U, [2])
@test U2 isa Universe{N} && dim(U2) == 1

Expand Down
Loading