11
22
3- abstract type DataSet{DS} end
4-
5- getproperty (ds:: DS , k:: Symbol ) where {DS<: DataSet{<:DataSet} } =
6- hasfield (DS, k) ? getfield (ds, k) : getproperty (getfield (ds, :_super ), k)
7- setproperty! (ds:: DS , k:: Symbol , v) where {DS<: DataSet{<:DataSet} } =
8- hasfield (DS, k) ? setfield! (ds, k, v) : setproperty! (getfield (ds, :_super ), k, v)
9- propertynames (ds:: DS ) where {DS<: DataSet } = propertynames (DS)
10- propertynames (:: Type{DS} ) where {DS′<: DataSet , DS<: DataSet{DS′} } =
11- union (propertynames (DS′), fieldnames (DS))
12- propertynames (:: Type{DS} ) where {DS<: DataSet{Nothing} } = fieldnames (DS)
13-
14- function new_dataset (:: Type{DS} ; kwargs... ) where {DS′<: DataSet , DS<: DataSet{DS′} }
15- kw = Dict (k => v for (k,v) in kwargs if k in fieldnames (DS))
16- kw′ = Dict (k => v for (k,v) in kwargs if ! (k in fieldnames (DS)))
17- DS (; kw... , _super= new_dataset (DS′; kw′... ))
18- end
19-
20- function new_dataset (:: Type{DS} ; kwargs... ) where {DS<: DataSet{Nothing} }
21- DS (; kwargs... )
22- end
3+ abstract type DataSet end
234
24- copy (ds:: DS ) where {DS<: DataSet } =
25- DS (((k== :_super ? copy (v) : v) for (k,v) in pairs (fields (ds))). .. )
5+ copy (ds:: DS ) where {DS<: DataSet } = DS (fields (ds)... )
266
277hash (ds:: DataSet , h:: UInt64 ) = foldr (hash, (typeof (ds), fieldvalues (ds)... ), init= h)
288
@@ -35,10 +15,6 @@ function show(io::IO, ds::DataSet)
3515end
3616
3717
38- # needed until fix to https://github.com/FluxML/Zygote.jl/issues/685
39- Zygote. grad_mut (ds:: DataSet ) = Ref {Any} ((;(propertynames (ds) .=> nothing ). .. ))
40-
41-
4218# util for distributing a singleton global dataset to workers
4319"""
4420 set_distributed_dataset(ds)
@@ -68,7 +44,7 @@ _distributed_dataset_hash = nothing
6844
6945
7046# Stores variables needed to construct the posterior
71- @kwdef mutable struct BaseDataSet <: DataSet{Nothing}
47+ @kwdef mutable struct BaseDataSet <: DataSet
7248 d # data
7349 Cϕ # ϕ covariance
7450 Cf # unlensed field covariance
0 commit comments