Skip to content

Commit

Permalink
Remove vecdot
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ararslan committed Nov 8, 2018
1 parent ec26062 commit 22caba8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
31 changes: 9 additions & 22 deletions src/atoms/affine/dot.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import LinearAlgebra.dot
export vecdot, dot
export dot

dot(x::AbstractExpr, y::AbstractExpr) = sum(broadcast(*, x, y))
dot(x::Value, y::AbstractExpr) = sum(broadcast(*, Constant(x), y))
dot(x::AbstractExpr, y::Value) = sum(broadcast(*, x, Constant(y)))

vecdot(x::AbstractExpr, y::AbstractExpr) = sum(broadcast(*, x, y))
vecdot(x::Value, y::AbstractExpr) = sum(broadcast(*, Constant(x), y))
vecdot(x::AbstractExpr, y::Value) = sum(broadcast(*, x, Constant(y)))

dot(x::AbstractExpr, y::AbstractExpr) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)
dot(x::Value, y::AbstractExpr) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)
dot(x::AbstractExpr, y::Value) = (ismatrix(x) || ismatrix(y)) ? error("dot not implemented for matrices. perhaps you're looking for vecdot?") : vecdot(x, y)

# tests if an array is a matrix (2D array) with both dimensions of size > 1
function ismatrix(x)
sz = size(x)
if length(sz) != 2
return false
else
for s in sz
if s == 1
return false
end
end
end
return true
if isdefined(LinearAlgebra, :vecdot) # defined but deprecated
import LinearAlgebra: vecdot
end
Base.@deprecate vecdot(x::AbstractExpr, y::AbstractExpr) dot(x, y)
Base.@deprecate vecdot(x::Value, y::AbstractExpr) dot(x, y)
Base.@deprecate vecdot(x::AbstractExpr, y::Value) dot(x, y)
6 changes: 3 additions & 3 deletions test/test_affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ eye(n) = Matrix(1.0I, n, n)
@test (evaluate(dot([2.0; 2.0], x)))[1] 4.4 atol=TOL
end

@testset "vecdot atom" begin
@testset "dot atom for matrix variables" begin
x = Variable(2,2)
p = minimize(vecdot(fill(2.0, (2,2)), x), x >= 1.1)
p = minimize(dot(fill(2.0, (2,2)), x), x >= 1.1)
@test vexity(p) == AffineVexity()
solve!(p)
@test p.optval 8.8 atol=TOL
@test (evaluate(vecdot(fill(2.0, (2, 2)), x)))[1] 8.8 atol=TOL
@test (evaluate(dot(fill(2.0, (2, 2)), x)))[1] 8.8 atol=TOL
end

@testset "add atom" begin
Expand Down

0 comments on commit 22caba8

Please sign in to comment.