Skip to content

Commit

Permalink
add Dict and NamedTuple methods for params
Browse files Browse the repository at this point in the history
  • Loading branch information
briochemc committed Feb 13, 2020
1 parent f082bca commit 84c59bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AIBECS"
uuid = "ace601d6-714c-11e9-04e5-89b7fad23838"
authors = ["Benoit Pasquier <pasquieb@uci.edu>"]
version = "0.4.10"
version = "0.4.11"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down Expand Up @@ -30,18 +30,18 @@ UnitfulRecipes = "42071c24-d89e-48dd-8a24-8a12d9b8861f"
[compat]
BSON = "0.2"
DataDeps = "0.7"
DataFrames = "0.19"
DataFrames = "0.20"
DiffEqBase = "6"
Distances = "0.8"
Distributions = "0.21"
Distributions = "0.22"
FieldMetadata = "0.1"
Flatten = "0.2"
Flatten = "0.3"
ForwardDiff = "0.10"
Interpolations = "0.12"
MetadataArrays = "0.1"
OceanGrids = "0.1"
Parameters = "0.12"
RecipesBase = "0.7"
RecipesBase = "0.8"
Reexport = "0.2"
Unitful = "1"
UnitfulAstro = "1"
Expand Down
15 changes: 15 additions & 0 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,21 @@ function (::Type{T})(;kwargs...) where {T <: AbstractParameters}
return T([f keys(kwargs) ? value(f, kwargs[f]) : initial_value(T, f) for f in fieldnames(T)]...)
end

#===============================
Writing to savable formats
===============================#

function Base.Dict(p::T, s=symbols(p)) where {T<:AbstractParameters}
v = [getfield(p,s) for s in s]
u = [units(p,s) for s in s]
return Dict([(s,v*u) for (s,v,u) in zip(s,v,u)])
end
function Base.NamedTuple(p::T, s=symbols(p)) where {T<:AbstractParameters}
v = [getfield(p,s) for s in s]
u = [units(p,s) for s in s]
return (; zip(s, v .* u)...)
end

#=====================
mismatch of parameters
=====================#
Expand Down

2 comments on commit 84c59bd

@briochemc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/9397

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.11 -m "<description of version>" 84c59bd7c9b0c11e6a5ac308f47158715524c9e2
git push origin v0.4.11

Also, note the warning: Version 0.4.11 skips over 0.4.10
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.