Skip to content

Commit

Permalink
Provide Base.oneunit()
Browse files Browse the repository at this point in the history
```
julia> euclidean(a, b)
ERROR: MethodError: no method matching VariableRef(::AffExpr)

Closest candidates are:
  (::Type{GenericVariableRef{T}} where T)(::Any, ::Any)
   @ JuMP ~/.julia/packages/JuMP/h0lrf/src/variables.jl:251
  GenericVariableRef{T}(::ConstraintRef{GenericModel{T}, <:MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex}}) where T
   @ JuMP ~/.julia/packages/JuMP/h0lrf/src/variables.jl:520
  GenericVariableRef{T}(::GenericModel{T}) where T
   @ JuMP ~/.julia/packages/JuMP/h0lrf/src/variables.jl:494

Stacktrace:
 [1] oneunit(#unused#::Type{VariableRef})
   @ Base ./number.jl:370
 [2] _eval_start(d::Euclidean, #unused#::Type{VariableRef}, #unused#::Type{VariableRef}, #unused#::Nothing)
   @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:320
 [3] _eval_start(d::Euclidean, #unused#::Type{VariableRef}, #unused#::Type{VariableRef})
   @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:318
 [4] eval_start(d::Euclidean, a::VariableRef, b::VariableRef)
   @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:317
 [5] _evaluate(d::Euclidean, a::VariableRef, b::VariableRef, #unused#::Nothing)
   @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:236
 [6] (::Euclidean)(a::VariableRef, b::VariableRef)
   @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:328
 [7] top-level scope
   @ REPL[8]:1

```
  • Loading branch information
LebedevRI committed Nov 26, 2023
1 parent 705ae68 commit 10812cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/aff_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ Base.zero(a::GenericAffExpr) = zero(typeof(a))
function Base.one(::Type{GenericAffExpr{C,V}}) where {C,V}
return GenericAffExpr{C,V}(one(C), OrderedDict{V,C}())
end
function Base.oneunit(::Type{GenericAffExpr{C,V}}) where {C,V}
return GenericAffExpr{C,V}(oneunit(C), OrderedDict{V,C}())

Check warning on line 207 in src/aff_expr.jl

View check run for this annotation

Codecov / codecov/patch

src/aff_expr.jl#L206-L207

Added lines #L206 - L207 were not covered by tests
end

Base.one(a::GenericAffExpr) = one(typeof(a))
Base.oneunit(a::GenericAffExpr) = oneunit(typeof(a))

Check warning on line 211 in src/aff_expr.jl

View check run for this annotation

Codecov / codecov/patch

src/aff_expr.jl#L211

Added line #L211 was not covered by tests

Base.copy(a::GenericAffExpr) = GenericAffExpr(copy(a.constant), copy(a.terms))

Expand Down
4 changes: 4 additions & 0 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,14 @@ function Base.zero(::Type{V}) where {V<:AbstractVariableRef}
end

Base.one(v::AbstractVariableRef) = one(typeof(v))
Base.oneunit(v::AbstractVariableRef) = oneunit(typeof(v))

Check warning on line 363 in src/variables.jl

View check run for this annotation

Codecov / codecov/patch

src/variables.jl#L363

Added line #L363 was not covered by tests

function Base.one(::Type{V}) where {V<:AbstractVariableRef}
return one(GenericAffExpr{value_type(V),V})
end
function Base.oneunit(::Type{V}) where {V<:AbstractVariableRef}
return oneunit(GenericAffExpr{value_type(V),V})

Check warning on line 369 in src/variables.jl

View check run for this annotation

Codecov / codecov/patch

src/variables.jl#L368-L369

Added lines #L368 - L369 were not covered by tests
end

"""
coefficient(v1::GenericVariableRef{T}, v2::GenericVariableRef{T}) where {T}
Expand Down

0 comments on commit 10812cc

Please sign in to comment.