Skip to content

Commit

Permalink
Verify and comment that addTarget gets duplicable arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Jan 26, 2025
1 parent 0e9bb16 commit 8494084
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/HordeAd/Core/Delta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ addRepM a b = case (a, b) of
(MTKScalar ta, MTKScalar tb) -> MTKScalar $ ta + tb
(MTKR ta, MTKR tb) | STKR _ STKScalar{} <- stensorKind @y -> MTKR $ ta + tb
(MTKR ta, MTKR tb) -> MTKR $ addTarget stensorKind ta tb
-- target has a ShareTensor instance, so ta and tb don't need
-- to be duplicable
(MTKScalarDummy, _) -> b
(_, MTKScalarDummy) -> a
(MTKRDummy{}, _) -> b
Expand Down Expand Up @@ -1132,6 +1134,8 @@ evalRev !s !c d0 = case d0 of
$ case DMap.lookup n $ nMap s of
Just _ ->
let addc x = RepAD $ addTarget stensorKind c (unRepAD x)
-- target has a ShareTensor instance, so addTarget arguments
-- don't need to be duplicable
in s {dMap = DMap.adjust addc n $ dMap s}
Nothing ->
let cd = RepAD c
Expand Down
2 changes: 2 additions & 0 deletions src/HordeAd/Core/OpsConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ instance BaseTensor RepN where
let l = runravelToList t
sh = shrTail $ rshape t
in foldr (addTarget stensorKind) (constantTarget 0 (FTKR sh x)) l
-- RepN has a ShareTensor instance, so addTarget arguments
-- don't need to be duplicable
rsum0 t = case tftk stensorKind t of
FTKR _ FTKScalar -> -- optimized
RepN . Nested.rscalar . Nested.rsumAllPrim . unRepN $ t
Expand Down

0 comments on commit 8494084

Please sign in to comment.