Skip to content

Commit 22caba8

Browse files
committed
Remove vecdot
The `vecdot` function was deprecated in favor of `dot` in Julia PR 27401; `dot` on matrices now treats them like vectors. The change here updates our extension of `dot` to match this behavior and deprecates `vecnorm`.
1 parent ec26062 commit 22caba8

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

src/atoms/affine/dot.jl

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
import LinearAlgebra.dot
2-
export vecdot, dot
2+
export dot
33

4+
dot(x::AbstractExpr, y::AbstractExpr) = sum(broadcast(*, x, y))
5+
dot(x::Value, y::AbstractExpr) = sum(broadcast(*, Constant(x), y))
6+
dot(x::AbstractExpr, y::Value) = sum(broadcast(*, x, Constant(y)))
47

5-
vecdot(x::AbstractExpr, y::AbstractExpr) = sum(broadcast(*, x, y))
6-
vecdot(x::Value, y::AbstractExpr) = sum(broadcast(*, Constant(x), y))
7-
vecdot(x::AbstractExpr, y::Value) = sum(broadcast(*, x, Constant(y)))
8-
9-
dot(x::AbstractExpr, y::AbstractExpr) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)
10-
dot(x::Value, y::AbstractExpr) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)
11-
dot(x::AbstractExpr, y::Value) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)
12-
13-
# tests if an array is a matrix (2D array) with both dimensions of size > 1
14-
function ismatrix(x)
15-
sz = size(x)
16-
if length(sz) != 2
17-
return false
18-
else
19-
for s in sz
20-
if s == 1
21-
return false
22-
end
23-
end
24-
end
25-
return true
8+
if isdefined(LinearAlgebra, :vecdot) # defined but deprecated
9+
import LinearAlgebra: vecdot
2610
end
11+
Base.@deprecate vecdot(x::AbstractExpr, y::AbstractExpr) dot(x, y)
12+
Base.@deprecate vecdot(x::Value, y::AbstractExpr) dot(x, y)
13+
Base.@deprecate vecdot(x::AbstractExpr, y::Value) dot(x, y)

test/test_affine.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ eye(n) = Matrix(1.0I, n, n)
6060
@test (evaluate(dot([2.0; 2.0], x)))[1] 4.4 atol=TOL
6161
end
6262

63-
@testset "vecdot atom" begin
63+
@testset "dot atom for matrix variables" begin
6464
x = Variable(2,2)
65-
p = minimize(vecdot(fill(2.0, (2,2)), x), x >= 1.1)
65+
p = minimize(dot(fill(2.0, (2,2)), x), x >= 1.1)
6666
@test vexity(p) == AffineVexity()
6767
solve!(p)
6868
@test p.optval 8.8 atol=TOL
69-
@test (evaluate(vecdot(fill(2.0, (2, 2)), x)))[1] 8.8 atol=TOL
69+
@test (evaluate(dot(fill(2.0, (2, 2)), x)))[1] 8.8 atol=TOL
7070
end
7171

7272
@testset "add atom" begin

0 commit comments

Comments
 (0)