Skip to content

Commit cbee0b0

Browse files
committed
more tests on BroadCast
1 parent d2ccf89 commit cbee0b0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/calculus/Jacobian.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Jacobian(S::Sum{M,N,K,C,D},x::D) where {M,N,K,C,D} =
7171
Sum(([Jacobian(a,x) for a in S.A]...),S.bufC,S.bufD,M,N)
7272
#Jacobian of Transpose
7373
Jacobian(T::Transpose{A}, x::AbstractArray) where {A <: AbstractOperator} = T
74+
#Jacobian of BroadCast
75+
Jacobian(B::A, x::AbstractArray) where {A <: BroadCast} = BroadCast(Jacobian(B.A,x),B.dim_out)
7476

7577
# Properties
7678

test/test_linear_operators_calculus.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,16 @@ y2 = zeros(dim_out)
740740
y2 .= x1
741741
@test vecnorm(y1-y2) <= 1e-12
742742

743+
m, n, l = 1, 5, 8
744+
dim_out = (m, n, l)
745+
opA1 = Scale(2.4,Eye(m))
746+
opR = BroadCast(opA1, dim_out)
747+
x1 = randn(m)
748+
y1 = test_op(opR, x1, randn(dim_out), verb)
749+
y2 = zeros(dim_out)
750+
y2 .= 2.4*x1
751+
@test vecnorm(y1-y2) <= 1e-12
752+
743753
@test is_null(opR) == is_null(opA1)
744754
@test is_eye(opR) == false
745755
@test is_diagonal(opR) == false

test/test_nonlinear_operators_calculus.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ y, grad = test_NLop(op,x,r,verb)
143143
Y = reshape(opS*x,2,2)
144144
@test vecnorm(Y-y) <1e-8
145145

146+
###testing BroadCast
147+
n,l = 4,7
148+
x = randn(n)
149+
r = randn(n,l)
150+
opS = Sigmoid(Float64,(n,),2)
151+
op = BroadCast(opS,(n,l))
152+
153+
y, grad = test_NLop(op,x,r,verb)
154+
155+
Y = (opS*x).*ones(n,l)
156+
@test vecnorm(Y-y) <1e-8
157+
158+
n,l = 1,7
159+
x = randn(n)
160+
r = randn(n,l)
161+
opS = Sigmoid(Float64,(n,),2)
162+
op = BroadCast(opS,(n,l))
163+
164+
y, grad = test_NLop(op,x,r,verb)
165+
166+
Y = (opS*x).*ones(n,l)
167+
@test vecnorm(Y-y) <1e-8
168+
146169
##testing Sum
147170
m = 5
148171
x = randn(m)

0 commit comments

Comments
 (0)