From 315396c7b257407649dec83a517ee483c99c81ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 28 Jul 2025 11:02:09 +0200 Subject: [PATCH 1/2] Use CanonicalVector from MOI --- src/dual_equality_constraints.jl | 41 +------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/dual_equality_constraints.jl b/src/dual_equality_constraints.jl index d5a74de..0ce317e 100644 --- a/src/dual_equality_constraints.jl +++ b/src/dual_equality_constraints.jl @@ -498,47 +498,8 @@ function _fill_scalar_affine_terms!( return end -struct _CanonicalVector{T} <: AbstractVector{T} - index::Int - n::Int -end - -Base.eltype(::Type{_CanonicalVector{T}}) where {T} = T - -Base.length(v::_CanonicalVector) = v.n - -Base.size(v::_CanonicalVector) = (v.n,) - -function Base.getindex(v::_CanonicalVector{T}, i::Integer) where {T} - return convert(T, i == v.index) -end - -# This is much faster than the default implementation that goes -# through all entries even if only one is nonzero. -function LinearAlgebra.dot( - x::_CanonicalVector{T}, - y::_CanonicalVector{T}, -) where {T} - return convert(T, x.index == y.index) -end - -function MOI.Utilities.triangle_dot( - x::_CanonicalVector{T}, - y::_CanonicalVector{T}, - dim::Int, - offset::Int, -) where {T} - if x.index != y.index || x.index <= offset - return zero(T) - elseif MOI.Utilities.is_diagonal_vectorized_index(x.index - offset) - return one(T) - else - return 2one(T) - end -end - function set_dot(i::Integer, s::MOI.AbstractVectorSet, T::Type) - vec = _CanonicalVector{T}(i, MOI.dimension(s)) + vec = MOI.Utilities.CanonicalVector{T}(i, MOI.dimension(s)) return MOI.Utilities.set_dot(vec, vec, s) end From 7267d0413701a4ba10ddc9f0edb1d5860c2353be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 28 Jul 2025 11:11:15 +0200 Subject: [PATCH 2/2] Remove tests --- test/Tests/test_dot.jl | 32 -------------------------------- test/runtests.jl | 1 - 2 files changed, 33 deletions(-) delete mode 100644 test/Tests/test_dot.jl diff --git a/test/Tests/test_dot.jl b/test/Tests/test_dot.jl deleted file mode 100644 index f795870..0000000 --- a/test/Tests/test_dot.jl +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (c) 2017: Guilherme Bodin, and contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -@testset "test_dot.jl" begin - a = Dualization._CanonicalVector{Int}(1, 3) - @test collect(a) == [1, 0, 0] - b = Dualization._CanonicalVector{Int}(2, 3) - @test collect(b) == [0, 1, 0] - set = MOI.PositiveSemidefiniteConeTriangle(2) - @test MOI.Utilities.set_dot(a, b, set) == 0 - @test MOI.Utilities.set_dot(a, a, set) == 1 - @test MOI.Utilities.set_dot(b, b, set) == 2 - a = Dualization._CanonicalVector{Int}(1, 4) - b = Dualization._CanonicalVector{Int}(2, 4) - c = Dualization._CanonicalVector{Int}(3, 4) - set = MOI.RootDetConeTriangle(2) - @test MOI.Utilities.set_dot(a, b, set) == 0 - @test MOI.Utilities.set_dot(b, c, set) == 0 - @test MOI.Utilities.set_dot(c, a, set) == 0 - @test MOI.Utilities.set_dot(a, a, set) == 1 - @test MOI.Utilities.set_dot(b, b, set) == 1 - @test MOI.Utilities.set_dot(c, c, set) == 2 - set = MOI.PositiveSemidefiniteConeSquare(2) - @test MOI.Utilities.set_dot(a, b, set) == 0 - @test MOI.Utilities.set_dot(b, c, set) == 0 - @test MOI.Utilities.set_dot(c, a, set) == 0 - @test MOI.Utilities.set_dot(a, a, set) == 1 - @test MOI.Utilities.set_dot(b, b, set) == 1 - @test MOI.Utilities.set_dot(c, c, set) == 1 -end diff --git a/test/runtests.jl b/test/runtests.jl index 0deb0dc..e8e8b08 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -72,7 +72,6 @@ include("Tests/test_dualize_exponential.jl") include("Tests/test_dualize_power.jl") include("Tests/test_dualize_quadratic.jl") include("Tests/test_dual_names.jl") -include("Tests/test_dot.jl") include("Tests/test_partial_dual_linear.jl") include("Tests/test_partial_dual_quadratic.jl")