File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
2929StaticArrays = " 90137ffa-7385-5640-81b9-e52037218182"
3030Statistics = " 10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3131StatsBase = " 2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
32+ StructArrays = " 09ab397b-f2b6-538f-b94a-2f83cf4a842a"
3233Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
3334Tricks = " 410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
3435
@@ -65,6 +66,7 @@ Static = "0.8, 1"
6566StaticArrays = " 1.5"
6667Statistics = " 1"
6768StatsBase = " 0.34"
69+ StructArrays = " 0.7.0"
6870Test = " 1"
6971Tricks = " 0.1"
7072julia = " 1.10"
Original file line number Diff line number Diff line change @@ -67,6 +67,33 @@ function ConstructionBase.setproperties(
6767 return constructorof (P)(merge (params (d), nt))
6868end
6969
70+ # ##############################################################################
71+ # StructArrays
72+
73+ # TODO : Can this be in an extension?
74+
75+
76+ import StructArrays
77+
78+ function StructArrays. staticschema (:: Type{P} ) where {N,P<: ParameterizedMeasure{N} }
79+ # Get the types from the NamedTuple parameter
80+ par_type = fieldtype (P, :par )
81+ # Use proper type construction for the component types
82+ types = Tuple{(fieldtype (par_type, n) for n in N). .. }
83+ # Return NamedTuple type with parameter names
84+ return NamedTuple{N,types}
85+ end
86+
87+ function StructArrays. component (m:: ParameterizedMeasure , key:: Symbol )
88+ # Extract component from the parameters NamedTuple
89+ return getfield (getfield (m, :par ), key)
90+ end
91+
92+ function StructArrays. createinstance (:: Type{P} , args... ) where {N,P<: ParameterizedMeasure{N} }
93+ # Create a new ParameterizedMeasure instance from components
94+ return constructorof (P)(NamedTuple {N} (args))
95+ end
96+
7097# ##############################################################################
7198# params
7299
You can’t perform that action at this time.
0 commit comments