711
711
$(TYPEDEF)
712
712
713
713
A callable struct which applies `p_constructor` to possibly nested arrays. It also
714
- ensures that views (including nested ones) are concretized.
714
+ ensures that views (including nested ones) are concretized. This is implemented manually
715
+ of using `narrow_buffer_type` to preserve type-stability.
715
716
"""
716
717
struct PConstructorApplicator{F}
717
718
p_constructor:: F
@@ -721,10 +722,18 @@ function (pca::PConstructorApplicator)(x::AbstractArray)
721
722
pca. p_constructor (x)
722
723
end
723
724
725
+ function (pca:: PConstructorApplicator )(x:: AbstractArray{Bool} )
726
+ pca. p_constructor (BitArray (x))
727
+ end
728
+
724
729
function (pca:: PConstructorApplicator{typeof(identity)} )(x:: SubArray )
725
730
collect (x)
726
731
end
727
732
733
+ function (pca:: PConstructorApplicator{typeof(identity)} )(x:: SubArray{Bool} )
734
+ BitArray (x)
735
+ end
736
+
728
737
function (pca:: PConstructorApplicator{typeof(identity)} )(x:: SubArray{<:AbstractArray} )
729
738
collect (pca .(x))
730
739
end
@@ -749,6 +758,7 @@ takes a value provider of `srcsys` and a value provider of `dstsys` and returns
749
758
"""
750
759
function get_mtkparameters_reconstructor (srcsys:: AbstractSystem , dstsys:: AbstractSystem ;
751
760
initials = false , unwrap_initials = false , p_constructor = identity)
761
+ _p_constructor = p_constructor
752
762
p_constructor = PConstructorApplicator (p_constructor)
753
763
# if we call `getu` on this (and it were able to handle empty tuples) we get the
754
764
# fields of `MTKParameters` except caches.
@@ -802,14 +812,24 @@ function get_mtkparameters_reconstructor(srcsys::AbstractSystem, dstsys::Abstrac
802
812
Base. Fix1 (broadcast, p_constructor) ∘
803
813
getu (srcsys, syms[3 ])
804
814
end
805
- rest_getters = map (Base. tail (Base. tail (Base. tail (syms)))) do buf
806
- if buf == ()
807
- return Returns (())
808
- else
809
- return Base. Fix1 (broadcast, p_constructor) ∘ getu (srcsys, buf)
810
- end
815
+ const_getter = if syms[4 ] == ()
816
+ Returns (())
817
+ else
818
+ Base. Fix1 (broadcast, p_constructor) ∘ getu (srcsys, syms[4 ])
811
819
end
812
- getters = (tunable_getter, initials_getter, discs_getter, rest_getters... )
820
+ nonnumeric_getter = if syms[5 ] == ()
821
+ Returns (())
822
+ else
823
+ ic = get_index_cache (dstsys)
824
+ buftypes = Tuple (map (ic. nonnumeric_buffer_sizes) do bufsize
825
+ Vector{bufsize. type}
826
+ end )
827
+ # nonnumerics retain the assigned buffer type without narrowing
828
+ Base. Fix1 (broadcast, _p_constructor) ∘
829
+ Base. Fix1 (Broadcast. BroadcastFunction (call), buftypes) ∘ getu (srcsys, syms[5 ])
830
+ end
831
+ getters = (
832
+ tunable_getter, initials_getter, discs_getter, const_getter, nonnumeric_getter)
813
833
getter = let getters = getters
814
834
function _getter (valp, initprob)
815
835
oldcache = parameter_values (initprob). caches
@@ -822,6 +842,10 @@ function get_mtkparameters_reconstructor(srcsys::AbstractSystem, dstsys::Abstrac
822
842
return getter
823
843
end
824
844
845
+ function call (f, args... )
846
+ f (args... )
847
+ end
848
+
825
849
"""
826
850
$(TYPEDSIGNATURES)
827
851
0 commit comments