3030
3131struct Hadamard{M, C, V <: VCAT{M} } <: NonLinearOperator
3232 A:: V
33- mid :: C
34- mid2 :: C
35- function Hadamard (A:: V , mid :: C , mid2 :: C ) where {M, C, V <: VCAT{M} }
33+ buf :: C
34+ buf2 :: C
35+ function Hadamard (A:: V , buf :: C , buf2 :: C ) where {M, C, V <: VCAT{M} }
3636 any ([ai != size (A,1 )[1 ] for ai in size (A,1 )]) &&
3737 throw (DimensionMismatch (" cannot compose operators" ))
3838
39- new {M, C, V} (A,mid,mid2 )
39+ new {M, C, V} (A,buf,buf2 )
4040 end
4141end
4242
4343struct HadamardJacobian{M, C, V <: VCAT{M} } <: LinearOperator
4444 A:: V
45- mid :: C
46- mid2 :: C
47- function HadamardJacobian (A:: V ,mid :: C ,mid2 :: C ) where {M, C, V <: VCAT{M} }
48- new {M, C, V} (A,mid,mid2 )
45+ buf :: C
46+ buf2 :: C
47+ function HadamardJacobian (A:: V ,buf :: C ,buf2 :: C ) where {M, C, V <: VCAT{M} }
48+ new {M, C, V} (A,buf,buf2 )
4949 end
5050end
5151
@@ -57,32 +57,32 @@ function Hadamard(L1::AbstractOperator,L2::AbstractOperator)
5757
5858 V = VCAT (A,B)
5959
60- mid = zeros .(codomainType (V), size (V,1 ))
61- mid2 = zeros .(codomainType (V), size (V,1 ))
60+ buf = zeros .(codomainType (V), size (V,1 ))
61+ buf2 = zeros .(codomainType (V), size (V,1 ))
6262
63- Hadamard (V,mid,mid2 )
63+ Hadamard (V,buf,buf2 )
6464end
6565
6666# Mappings
6767function A_mul_B! (y, H:: Hadamard{M,C,V} , b) where {M,C,V}
68- A_mul_B! (H. mid ,H. A,b)
68+ A_mul_B! (H. buf ,H. A,b)
6969
70- y .= H. mid [1 ]
71- for i = 2 : length (H. mid )
72- y .*= H. mid [i]
70+ y .= H. buf [1 ]
71+ for i = 2 : length (H. buf )
72+ y .*= H. buf [i]
7373 end
7474end
7575
7676# Jacobian
7777Jacobian (A:: H , x:: D ) where {M, D<: Tuple , C, V, H <: Hadamard{M,C,V} } =
78- HadamardJacobian (Jacobian (A. A,x),A. mid ,A. mid2 )
78+ HadamardJacobian (Jacobian (A. A,x),A. buf ,A. buf2 )
7979
8080function Ac_mul_B! (y, J:: HadamardJacobian{M,C,V} , b) where {M,C,V}
81- for i = 1 : length (J. mid )
82- c = (J. mid [1 : i- 1 ]. .. ,J. mid [i+ 1 : end ]. .. ,b)
83- J. mid2 [i] .= (.* )(c... )
81+ for i = 1 : length (J. buf )
82+ c = (J. buf [1 : i- 1 ]. .. ,J. buf [i+ 1 : end ]. .. ,b)
83+ J. buf2 [i] .= (.* )(c... )
8484 end
85- Ac_mul_B! (y, J. A, J. mid2 )
85+ Ac_mul_B! (y, J. A, J. buf2 )
8686
8787end
8888
@@ -104,5 +104,7 @@ import Base: permute
104104
105105function permute (H:: Hadamard , p:: AbstractVector{Int} )
106106 A = VCAT ([permute (a,p) for a in H. A. A]. .. )
107- Hadamard (A,H. mid ,H. mid2 )
107+ Hadamard (A,H. buf ,H. buf2 )
108108end
109+
110+ remove_displacement (N:: Hadamard ) = Hadamard (remove_displacement (N. A), N. buf, N. buf2)
0 commit comments