@@ -5,6 +5,16 @@ const NO_DEFAULT = NoDefault()
5
5
# A short-hand for a type commonly used in type signatures for VarInfo methods.
6
6
VarNameTuple = NTuple{N,VarName} where {N}
7
7
8
+ # TODO (mhauru) This is currently used in the transformation functions of NoDist,
9
+ # ReshapeTransform, and UnwrapSingletonTransform, and in VarInfo. We should also use it in
10
+ # SimpleVarInfo and maybe other places.
11
+ """
12
+ The type for all log probability variables.
13
+
14
+ This is Float64 on 64-bit systems and Float32 on 32-bit systems.
15
+ """
16
+ const LogProbType = float (Real)
17
+
8
18
"""
9
19
@addlogprob!(ex)
10
20
@@ -252,12 +262,16 @@ function (f::UnwrapSingletonTransform)(x)
252
262
return only (x)
253
263
end
254
264
255
- Bijectors. with_logabsdet_jacobian (f:: UnwrapSingletonTransform , x) = (f (x), 0 )
265
+ function Bijectors. with_logabsdet_jacobian (f:: UnwrapSingletonTransform , x)
266
+ return f (x), zero (LogProbType)
267
+ end
268
+
256
269
function Bijectors. with_logabsdet_jacobian (
257
270
inv_f:: Bijectors.Inverse{<:UnwrapSingletonTransform} , x
258
271
)
259
272
f = inv_f. orig
260
- return (reshape ([x], f. input_size), 0 )
273
+ result = reshape ([x], f. input_size)
274
+ return result, zero (LogProbType)
261
275
end
262
276
263
277
"""
@@ -306,18 +320,26 @@ function (inv_f::Bijectors.Inverse{<:ReshapeTransform})(x)
306
320
return inverse (x)
307
321
end
308
322
309
- Bijectors. with_logabsdet_jacobian (f:: ReshapeTransform , x) = (f (x), 0 )
323
+ function Bijectors. with_logabsdet_jacobian (f:: ReshapeTransform , x)
324
+ return f (x), zero (LogProbType)
325
+ end
310
326
311
327
function Bijectors. with_logabsdet_jacobian (inv_f:: Bijectors.Inverse{<:ReshapeTransform} , x)
312
- return ( inv_f (x), 0 )
328
+ return inv_f (x), zero (LogProbType )
313
329
end
314
330
315
331
struct ToChol <: Bijectors.Bijector
316
332
uplo:: Char
317
333
end
318
334
319
- Bijectors. with_logabsdet_jacobian (f:: ToChol , x) = (Cholesky (Matrix (x), f. uplo, 0 ), 0 )
320
- Bijectors. with_logabsdet_jacobian (:: Bijectors.Inverse{<:ToChol} , y:: Cholesky ) = (y. UL, 0 )
335
+ function Bijectors. with_logabsdet_jacobian (f:: ToChol , x)
336
+ return Cholesky (Matrix (x), f. uplo, 0 ), zero (LogProbType)
337
+ end
338
+
339
+ function Bijectors. with_logabsdet_jacobian (:: Bijectors.Inverse{<:ToChol} , y:: Cholesky )
340
+ return y. UL, zero (LogProbType)
341
+ end
342
+
321
343
function Bijectors. with_logabsdet_jacobian (:: Bijectors.Inverse{<:ToChol} , y)
322
344
return error (
323
345
" Inverse{ToChol} is only defined for Cholesky factorizations. " *
0 commit comments