Skip to content

Commit cd3f11e

Browse files
authored
Merge pull request #365 from JuliaOpt/conv
Fix `conv` docs; add test of the definition
2 parents e4bb30b + 6e29025 commit cd3f11e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/src/operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LP solver.
5656
| `tr(x)` | $\mathrm{tr} \left(X \right)$ | affine | increasing | none |
5757
| `partialtrace(x,sys,dims)` | Partial trace | affine | increasing | none |
5858
| `partialtranspose(x,sys,dims)` | Partial transpose | affine | increasing | none |
59-
| `conv(h,x)` | $h \in \mathbb{R}^m$ $x \in \mathbb{R}^m$ $h\star x \in \mathbb{R}^{m+n-1}$ entry $i$ is given by $\sum_{j=1}^m h_jx_{i-j}$ | affine | increasing if $h\ge 0$ decreasing if $h\le 0$ not monotonic otherwise | PR: $h$ is constant |
59+
| `conv(h,x)` | $h \in \mathbb{R}^m$, $x \in \mathbb{R}^n$, $h\star x \in \mathbb{R}^{m+n-1}$; entry $i$ is given by $\sum_{j=1}^m h_jx_{i-j+1}$ with $x_k=0$ for $k$ out of bounds | affine | increasing if $h\ge 0$ decreasing if $h\le 0$ not monotonic otherwise | PR: $h$ is constant |
6060
| `min(x,y)` | $\min(x,y)$ | concave | increasing | none |
6161
| `max(x,y)` | $\max(x,y)$ | convex | increasing | none |
6262
| `pos(x)` | $\max(x,0)$ | convex | increasing | none |

test/definitions.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function _conv(h, x)
2+
m = length(h)
3+
n = length(x)
4+
zero_pad_x(i) = 1 <= i <= n ? x[i] : 0
5+
[ sum(h[j]*zero_pad_x(i-j+1) for j = 1:m) for i = 1:m+n-1 ]
6+
end
7+
8+
@testset "Conv (issue #364)" begin
9+
n = 3
10+
m = 11
11+
h = rand(m)
12+
x = rand(n)
13+
hvar = Variable(m)
14+
hvar.value = h
15+
@test evaluate(conv(hvar, x)) _conv(h, x)
16+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Random.seed!(2)
2626
end
2727
end
2828

29+
@testset "Definitions" begin
30+
include("definitions.jl")
31+
end
32+
2933
@testset "Convex" begin
3034
include("test_utilities.jl")
3135
include("deprecations.jl")

0 commit comments

Comments
 (0)