JuliaMath / JuliaMath/MeasureTheory.jl

@measure combinator - macros, TypeVars, and binops

Open
#9 22 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
401
Forks
31
PR merge metrics
No merged PRs in 30d

Description

I think it's close to working, but...

```julia
julia> using StatsFuns

julia> @measure Normal(μ,σ) ≃ (1/sqrt2π) * Lebesgue(X)
ERROR: UndefVarError: X not defined
Stacktrace:
[1] (::Type{Lebesgue{X}})() at /home/chad/git/Measures.jl/src/basemeasures/lebesgue.jl:4
[2] Lebesgue(::TypeVar) at /home/chad/git/Measures.jl/src/basemeasures/lebesgue.jl:6
[3] top-level scope at /home/chad/git/Measures.jl/src/macros.jl:41
```

[1] and [2] here are

```julia
struct Lebesgue{X} end
Lebesgue(X) = Lebesgue{X}()
```

Any suggestions on getting this to work properly? Here's the code the macro currently generates:

```julia
julia> using MacroTools

julia> (@macroexpand @measure Normal(μ,σ) ≃ (1/sqrt2π) * Lebesgue(X)) |> MacroTools.prettify
quote
struct Normal{P, X} <: MeasureTheory.AbstractMeasure{X}
par::P
end
function Normal(nt::NamedTuple)
P = typeof(nt)
return Normal{P, eltype(Normal{P})}(nt)
end
Normal(; kwargs...) = Normal((; kwargs...))
(baseMeasure(μ::Normal{P, X}) where {P, X}) = (1 / sqrt2π) * Lebesgue(X)
Normal(μ, σ) = Normal(; μ, σ)
((::Normal{P, X} ≪ ::typeof((1 / sqrt2π) * Lebesgue(X))) where {P, X}) = true
::typeof((1 / sqrt2π) * Lebesgue(X)) ≪ ::Normal{P, X} where {P, X} = true
end
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.