File tree Expand file tree Collapse file tree 2 files changed +17
-28
lines changed Expand file tree Collapse file tree 2 files changed +17
-28
lines changed Original file line number Diff line number Diff line change 1
1
export Half
2
2
3
3
struct Half{M} <: AbstractMeasure
4
- μ:: M
4
+ parent:: M
5
+ end
6
+
7
+ function Base. show (io:: IO , μ:: Half )
8
+ print (io, " Half" )
9
+ show (io, μ. parent)
10
+ end
11
+
12
+ unhalf (μ:: Half ) = μ. parent
13
+
14
+ basemeasure (μ:: Half ) = basemeasure (μ. parent)
15
+
16
+ function Base. rand (rng:: AbstractRNG , T:: Type , μ:: Half )
17
+ return abs (rand (rng, T, unhalf (μ)))
5
18
end
Original file line number Diff line number Diff line change @@ -245,36 +245,12 @@ end
245
245
246
246
function _half (__module__, ex)
247
247
@match ex begin
248
- :($ dist ( $ (args ... )) ) => begin
248
+ :($ dist) => begin
249
249
halfdist = esc (Symbol (:Half , dist))
250
250
251
251
quote
252
- struct $ halfdist{N,T} <: ParameterizedMeasure{N}
253
- par :: NamedTuple{N,T}
254
- end
255
-
256
- unhalf (μ:: $halfdist ) = $ dist (getfield (μ, :par ))
257
-
258
- function MeasureBase. basemeasure (μ:: $halfdist )
259
- b = basemeasure (unhalf (μ))
260
- @assert basemeasure (b) == Lebesgue (ℝ)
261
- lw = b. logweight
262
- return WeightedMeasure (logtwo + lw, Lebesgue (ℝ₊))
263
- end
264
-
265
- function MeasureBase. logdensity (μ:: $halfdist , x)
266
- return logdensity (unhalf (μ), x)
267
- end
268
-
269
- function Base. rand (rng:: AbstractRNG , T:: Type , μ:: $halfdist )
270
- return abs (rand (rng, T, unhalf (μ)))
271
- end
272
-
273
- function decompose (μ:: $halfdist )
274
- return Half ($ dist)
275
- end
276
-
277
- (:: $halfdist ≪ :: Lebesgue{ℝ₊} ) = true
252
+ $ halfdist (args... ) = Half ($ dist (args... ))
253
+ $ halfdist (;kwargs... ) = Half ($ dist (;kwargs... ))
278
254
end
279
255
end
280
256
end
You can’t perform that action at this time.
0 commit comments