@@ -7,14 +7,15 @@ subtypes, as we know the full set that might be encountered.
7
7
Thus we can avoid any ambiguities.
8
8
9
9
Notice:
10
- The precidence goes: (:Wirtinger , :Casted, :Zero, :DNE, :One, :AbstractThunk, :Any)
10
+ The precidence goes: (:AbstractWirtinger , :Casted, :Zero, :DNE, :One, :AbstractThunk, :Any)
11
11
Thus each of the @eval loops creating definitions of + and *
12
12
defines the combination this type with all types of lower precidence.
13
13
This means each eval loops is 1 item smaller than the previous.
14
14
==#
15
15
16
16
17
- function Base.:* (a:: Wirtinger , b:: Wirtinger )
17
+ function Base.:* (a:: Union{Complex,AbstractWirtinger} ,
18
+ b:: Union{Complex,AbstractWirtinger} )
18
19
error ("""
19
20
Cannot multiply two Wirtinger objects; this error likely means a
20
21
`WirtingerRule` was inappropriately defined somewhere. Multiplication
@@ -32,18 +33,33 @@ function Base.:*(a::Wirtinger, b::Wirtinger)
32
33
""" )
33
34
end
34
35
35
- function Base.:+ (a:: Wirtinger , b:: Wirtinger )
36
- return Wirtinger (+ (a. primal, b. primal), a. conjugate + b. conjugate)
36
+ function Base.:+ (a:: AbstractWirtinger , b:: AbstractWirtinger )
37
+ return Wirtinger (wirtinger_primal (a) + wirtinger_primal (b),
38
+ wirtinger_conjugate (a) + wirtinger_conjugate (b))
37
39
end
38
40
39
- for T in (:Casted , :Zero , :DNE , :One , :AbstractThunk , :Any )
40
- @eval Base.:+ (a:: Wirtinger , b:: $T ) = a + Wirtinger (b, Zero ())
41
- @eval Base.:+ (a:: $T , b:: Wirtinger ) = Wirtinger (a, Zero ()) + b
41
+ Base.:+ (a:: ComplexGradient , b:: ComplexGradient ) = ComplexGradient (a. val + b. val)
42
+
43
+ for T in (:Casted , :Zero , :DNE , :One , :AbstractThunk )
44
+ @eval Base.:+ (a:: AbstractWirtinger , b:: $T ) = a + Wirtinger (b, Zero ())
45
+ @eval Base.:+ (a:: $T , b:: AbstractWirtinger ) = Wirtinger (a, Zero ()) + b
42
46
43
47
@eval Base.:* (a:: Wirtinger , b:: $T ) = Wirtinger (a. primal * b, a. conjugate * b)
44
48
@eval Base.:* (a:: $T , b:: Wirtinger ) = Wirtinger (a * b. primal, a * b. conjugate)
49
+
50
+ @eval Base.:* (a:: ComplexGradient , b:: $T ) = ComplexGradient (a. val * b)
51
+ @eval Base.:* (a:: $T , b:: ComplexGradient ) = ComplexGradient (a * b. val)
45
52
end
46
53
54
+ Base.:+ (a:: AbstractWirtinger , b) = a + Wirtinger (b, Zero ())
55
+ Base.:+ (a, b:: AbstractWirtinger ) = Wirtinger (a, Zero ()) + b
56
+
57
+ Base.:* (a:: Wirtinger , b:: Real ) = Wirtinger (a. primal * b, a. conjugate * b)
58
+ Base.:* (a:: Real , b:: Wirtinger ) = Wirtinger (a * b. primal, a * b. conjugate)
59
+
60
+ Base.:* (a:: ComplexGradient , b:: Real ) = ComplexGradient (a. val * b)
61
+ Base.:* (a:: Real , b:: ComplexGradient ) = ComplexGradient (a * b. val)
62
+
47
63
48
64
Base.:+ (a:: Casted , b:: Casted ) = Casted (broadcasted (+ , a. value, b. value))
49
65
Base.:* (a:: Casted , b:: Casted ) = Casted (broadcasted (* , a. value, b. value))
0 commit comments