Skip to content

Commit dc5fe84

Browse files
committed
actually export constructors
1 parent 7107427 commit dc5fe84

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changelog
22
=========
33

4+
Version 0.2.7.1
5+
---------------
6+
7+
*June 1, 2025*
8+
9+
<https://github.com/mstksg/backprop/releases/tag/v0.2.7.1>
10+
11+
* Actually export internal constructors and utilities in
12+
`Numeric.Backprop.Internal`.
13+
414
Version 0.2.7.0
515
---------------
616

backprop.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22
name: backprop
3-
version: 0.2.7.0
3+
version: 0.2.7.1
44
synopsis: Heterogeneous automatic differentation
55
description:
66
Write your functions to compute your result, and the library will

src/Numeric/Backprop/Internal.hs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
--
3636
-- @since 0.2.7.0
3737
module Numeric.Backprop.Internal (
38-
BVar,
39-
W,
38+
-- * Exported for re-use
39+
BVar (..),
40+
W (..),
4041
backpropWithN,
4142
evalBPN,
4243
constVar,
@@ -66,6 +67,23 @@ module Numeric.Backprop.Internal (
6667
-- * Debug
6768
debugSTN,
6869
debugIR,
70+
71+
-- * Only used internally
72+
TapeNode (..),
73+
SomeTapeNode (..),
74+
BRef (..),
75+
Runner (..),
76+
initWengert,
77+
insertNode,
78+
bvConst,
79+
forceBVar,
80+
forceInpRef,
81+
forceSomeTapeNode,
82+
forceTapeNode,
83+
fillWengert,
84+
bumpMaybe,
85+
initRunner,
86+
gradRunner,
6987
) where
7088

7189
import Control.DeepSeq
@@ -207,17 +225,20 @@ ofNum = OF (const 1)
207225
--
208226
-- See "Numeric.Backprop#liftops" and documentation for
209227
-- 'Numeric.Backprop.liftOp' for more information.
210-
data BVar s a = BV
211-
{ _bvRef :: !(BRef s)
212-
, _bvVal :: !a
213-
}
228+
data BVar s a
229+
= -- | @since 0.2.7.1
230+
BV
231+
{ _bvRef :: !(BRef s)
232+
, _bvVal :: !a
233+
}
214234

215235
-- | @since 0.1.5.1
216236
deriving instance Typeable (BVar s a)
217237

218238
-- | @since 0.2.6.3
219239
instance X.IsoHKD (BVar s) a
220240

241+
-- | @since 0.2.7.1
221242
data BRef (s :: Type)
222243
= BRInp !Int
223244
| BRIx !Int
@@ -240,6 +261,7 @@ forceBVar :: BVar s a -> ()
240261
forceBVar (BV r !_) = force r `seq` ()
241262
{-# INLINE forceBVar #-}
242263

264+
-- | @since 0.2.7.1
243265
data InpRef :: Type -> Type where
244266
IR ::
245267
{ _irIx :: !(BVar s b)
@@ -248,6 +270,7 @@ data InpRef :: Type -> Type where
248270
} ->
249271
InpRef a
250272

273+
-- | @since 0.2.7.1
251274
forceInpRef :: InpRef a -> ()
252275
forceInpRef (IR v !_ !_) = forceBVar v `seq` ()
253276
{-# INLINE forceInpRef #-}
@@ -256,23 +279,27 @@ forceInpRef (IR v !_ !_) = forceBVar v `seq` ()
256279
debugIR :: InpRef a -> String
257280
debugIR IR{..} = show (_bvRef _irIx)
258281

282+
-- | @since 0.2.7.1
259283
data TapeNode :: Type -> Type where
260284
TN ::
261285
{ _tnInputs :: !(Rec InpRef as)
262286
, _tnGrad :: !(a -> Rec Identity as)
263287
} ->
264288
TapeNode a
265289

290+
-- | @since 0.2.7.1
266291
forceTapeNode :: TapeNode a -> ()
267292
forceTapeNode (TN inps !_) = VR.rfoldMap forceInpRef inps `seq` ()
268293
{-# INLINE forceTapeNode #-}
269294

295+
-- | @since 0.2.7.1
270296
data SomeTapeNode :: Type where
271297
STN ::
272298
{ _stnNode :: !(TapeNode a)
273299
} ->
274300
SomeTapeNode
275301

302+
-- | @since 0.2.7.1
276303
forceSomeTapeNode :: SomeTapeNode -> ()
277304
forceSomeTapeNode (STN n) = forceTapeNode n
278305

@@ -285,12 +312,16 @@ debugSTN (STN TN{..}) = show . VR.rfoldMap ((: []) . debugIR) $ _tnInputs
285312
--
286313
-- For the end user, one can just imagine @'Reifies' s 'W'@ as a required
287314
-- constraint on @s@ that allows backpropagation to work.
288-
newtype W = W {wRef :: IORef (Int, [SomeTapeNode])}
315+
newtype W
316+
= -- | @since 0.2.7.1
317+
W {wRef :: IORef (Int, [SomeTapeNode])}
289318

319+
-- | @since 0.2.7.1
290320
initWengert :: IO W
291321
initWengert = W <$> newIORef (0, [])
292322
{-# INLINE initWengert #-}
293323

324+
-- | @since 0.2.7.1
294325
insertNode ::
295326
TapeNode a ->
296327
-- | val
@@ -659,11 +690,13 @@ coerceVar ::
659690
BVar s b
660691
coerceVar v@(BV r x) = forceBVar v `seq` BV r (coerce x)
661692

693+
-- | @since 0.2.7.1
662694
data Runner s = R
663695
{ _rDelta :: !(MV.MVector s (Maybe Any))
664696
, _rInputs :: !(MV.MVector s (Maybe Any))
665697
}
666698

699+
-- | @since 0.2.7.1
667700
initRunner ::
668701
(Int, [SomeTapeNode]) ->
669702
(Int, [Maybe Any]) ->
@@ -677,6 +710,7 @@ initRunner (n, stns) (nx, xs) = do
677710
return $ R delts inps
678711
{-# INLINE initRunner #-}
679712

713+
-- | @since 0.2.7.1
680714
gradRunner ::
681715
forall b s.
682716
() =>
@@ -709,6 +743,7 @@ gradRunner o R{..} (n, stns) = do
709743
{-# INLINE propagate #-}
710744
{-# INLINE gradRunner #-}
711745

746+
-- | @since 0.2.7.1
712747
bumpMaybe ::
713748
-- | val
714749
a ->

0 commit comments

Comments
 (0)