|
36 | 36 |
|
37 | 37 | (::Type{P})(;kwargs...) where {P <: ParameterizedMeasure} = P(NamedTuple(kwargs))
|
38 | 38 |
|
| 39 | +function ConstructionBase.setproperties(d::P, nt::NamedTuple) where {P<:ParameterizedMeasure} |
| 40 | + return constructorof(P)(merge(params(d), nt)) |
| 41 | +end |
| 42 | + |
| 43 | +############################################################################### |
| 44 | +# params |
| 45 | + |
39 | 46 | export params
|
40 | 47 |
|
41 |
| -params(::Type{PM}) where {N, PM<:ParameterizedMeasure{N}} = N |
| 48 | +params(μ::ParameterizedMeasure) = getfield(μ, :par) |
42 | 49 |
|
43 |
| -function params(::Type{M}, constraints::NamedTuple{N2}) where {N1, N2, M<: ParameterizedMeasure{N1}} |
44 |
| - tuple((k for k in N1 if k ∉ N2)...) |
| 50 | +function params(μ::AbstractMeasure, constraints::NamedTuple{C}) where {N1, N2, M<: ParameterizedMeasure{N1}} |
| 51 | + NamedTuple{paramnames(μ, constraints)}(params(μ)) |
45 | 52 | end
|
46 | 53 |
|
| 54 | +params(μ::AbstractMeasure) = NamedTuple() |
47 | 55 |
|
48 |
| -params(μ) = () |
| 56 | +############################################################################### |
| 57 | +# paramnames |
49 | 58 |
|
| 59 | +export paramnames |
50 | 60 |
|
51 |
| -function ConstructionBase.setproperties(d::P, nt::NamedTuple) where {P<:ParameterizedMeasure} |
52 |
| - return constructorof(P)(merge(params(d), nt)) |
| 61 | +paramnames(μ) = paramnames(typeof(μ)) |
| 62 | + |
| 63 | +paramnames(::Type{PM}) where {N, PM<:ParameterizedMeasure{N}} = N |
| 64 | + |
| 65 | +paramnames(μ::AbstractMeasure) = propertynames(μ) |
| 66 | + |
| 67 | +params(::Type{PM}) where {N, PM<:ParameterizedMeasure{N}} = N |
| 68 | + |
| 69 | +function paramnames(μ, constraints::NamedTuple{N}) where {N} |
| 70 | + tuple((k for k in paramnames(μ) if k ∉ N)...) |
53 | 71 | end
|
0 commit comments