Skip to content

Commit 69a34d7

Browse files
kshyattKatharine Hyatt
andauthored
Don't use nothing in caches (#256)
Co-authored-by: Katharine Hyatt <katharine.hyatt@ugent.be>
1 parent 7b5ec74 commit 69a34d7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

ext/MatrixAlgebraKitEnzymeExt/MatrixAlgebraKitEnzymeExt.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ for (f, pb) in (
7474
A_is_arg1 = !isa(A, Const) && has_equal_storage(A.val, arg.val[1])
7575
A_is_arg2 = !isa(A, Const) && has_equal_storage(A.val, arg.val[2])
7676
A_is_arg = A_is_arg1 || A_is_arg2
77-
cache_arg = arg.val !== ret || A_is_arg || EnzymeRules.overwritten(config)[3] ? copy.(ret) : nothing
77+
cache_arg = arg.val !== ret || A_is_arg || EnzymeRules.overwritten(config)[3] ? copy.(ret) : ret
7878
dret = if EnzymeRules.needs_shadow(config) && ((TA == Nothing && TB == Nothing) || isa(arg, Const))
7979
make_zero.(ret)
8080
elseif EnzymeRules.needs_shadow(config)
@@ -101,7 +101,7 @@ for (f, pb) in (
101101
A_is_arg1 = !isa(A, Const) && has_equal_storage(A.dval, arg.dval[1])
102102
A_is_arg2 = !isa(A, Const) && has_equal_storage(A.dval, arg.dval[2])
103103
A_is_arg = A_is_arg1 || A_is_arg2
104-
argval = something(cache_arg, arg.val)
104+
argval = cache_arg
105105
if !isa(A, Const)
106106
ΔA = A_is_arg ? make_zero(A.dval) : A.dval
107107
$pb(ΔA, Aval, argval, darg)
@@ -221,7 +221,7 @@ for f! in (:svd_compact!, :svd_full!)
221221
# if USVᴴ.val == ret, the annotation must be Duplicated or DuplicatedNoNeed
222222
# if USVᴴ isa Const, ret may still be modified further down the call graph so we should
223223
# copy it to protect ourselves
224-
cache_USVᴴ = (USVᴴ.val !== ret) || EnzymeRules.overwritten(config)[3] ? copy.(ret) : nothing
224+
cache_USVᴴ = (USVᴴ.val !== ret) || EnzymeRules.overwritten(config)[3] ? copy.(ret) : ret
225225
# the USVᴴ may be nothing for eltypes handled by GenericLinearAlgebra
226226
dret = if EnzymeRules.needs_shadow(config)
227227
((TU == TS == TVᴴ == Nothing) || isa(USVᴴ, Const)) ? make_zero(ret) : USVᴴ.dval
@@ -244,7 +244,7 @@ for f! in (:svd_compact!, :svd_full!)
244244
# A is not used in the pullback; since we have destroyed A, we insert Aval = nothing
245245
# to trigger an error in case the pushfward is modified to directly use A
246246
Aval = nothing
247-
USVᴴval = something(cache_USVᴴ, USVᴴ.val)
247+
USVᴴval = cache_USVᴴ
248248
if !isa(A, Const)
249249
svd_pullback!(A.dval, Aval, USVᴴval, dUSVᴴ)
250250
end

0 commit comments

Comments
 (0)