Skip to content

Commit ea709c0

Browse files
authored
Fix diagm(x) (#402)
1 parent c97b779 commit ea709c0

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Changes in v0.13.6
2+
3+
* fix [#401](https://github.com/jump-dev/Convex.jl/issues/401) by allowing `diagm(x)`.
4+
*
15
# Changes in v0.13.5
26

37
* fix [#398](https://github.com/jump-dev/Convex.jl/issues/398) by allowing `fix!`'d variables in `quadform`.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Convex"
22
uuid = "f65535da-76fb-5f13-bab9-19810c17039a"
3-
version = "0.13.5"
3+
version = "0.13.6"
44

55
[deps]
66
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/atoms/affine/diagm.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Please read expressions.jl first.
66
#############################################################################
77

8-
import LinearAlgebra.diagm, LinearAlgebra.Diagonal
98

109
struct DiagMatrixAtom <: AbstractExpr
1110
head::Symbol
@@ -48,11 +47,12 @@ function evaluate(x::DiagMatrixAtom)
4847
return Diagonal(vec(evaluate(x.children[1])))
4948
end
5049

51-
function diagm((d, x)::Pair{<:Integer, <:AbstractExpr})
50+
function LinearAlgebra.diagm((d, x)::Pair{<:Integer, <:AbstractExpr})
5251
d == 0 || throw(ArgumentError("only the main diagonal is supported"))
5352
return DiagMatrixAtom(x)
5453
end
55-
Diagonal(x::AbstractExpr) = DiagMatrixAtom(x)
54+
LinearAlgebra.diagm(x::AbstractExpr) = DiagMatrixAtom(x)
55+
LinearAlgebra.Diagonal(x::AbstractExpr) = DiagMatrixAtom(x)
5656

5757
function conic_form!(x::DiagMatrixAtom, unique_conic_forms::UniqueConicForms)
5858
if !has_conic_form(unique_conic_forms, x)

test/test_utilities.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,9 @@ using Convex: AbstractExpr, ConicObj
437437
add_constraints!(p, [c, c2])
438438
@test length(p.constraints) == 2
439439
end
440+
441+
@testset "`diagm` (#401)" begin
442+
x = Variable(3)
443+
@test diagm(x) isa AbstractExpr
444+
end
440445
end

0 commit comments

Comments
 (0)