@@ -336,14 +336,15 @@ function Base.copy(p::MTKParameters)
336336end 
337337
338338function  SymbolicIndexingInterface. parameter_values (p:: MTKParameters , pind:: ParameterIndex )
339+     _ducktyped_parameter_values (p, pind)
340+ end 
341+ function  _ducktyped_parameter_values (p, pind:: ParameterIndex )
339342    @unpack  portion, idx =  pind
340343    if  portion isa  SciMLStructures. Tunable
341344        return  idx isa  Int ?  p. tunable[idx] :  view (p. tunable, idx)
342345    end 
343346    i, j, k...  =  idx
344-     if  portion isa  SciMLStructures. Tunable
345-         return  isempty (k) ?  p. tunable[i][j] :  p. tunable[i][j][k... ]
346-     elseif  portion isa  SciMLStructures. Discrete
347+     if  portion isa  SciMLStructures. Discrete
347348        return  isempty (k) ?  p. discrete[i][j] :  p. discrete[i][j][k... ]
348349    elseif  portion isa  SciMLStructures. Constants
349350        return  isempty (k) ?  p. constant[i][j] :  p. constant[i][j][k... ]
@@ -435,20 +436,26 @@ function validate_parameter_type(ic::IndexCache, p, idx::ParameterIndex, val)
435436end 
436437
437438function  validate_parameter_type (ic:: IndexCache , idx:: ParameterIndex , val)
439+     stype =  get_buffer_template (ic, idx). type
440+     if  idx. portion ==  SciMLStructures. Tunable () &&  ! (idx. idx isa  Int)
441+         stype =  AbstractArray{<: stype }
442+     end 
438443    validate_parameter_type (
439-         ic, get_buffer_template (ic, idx) . type , Symbolics. Unknown (), nothing , idx, val)
444+         ic, stype , Symbolics. Unknown (), nothing , idx, val)
440445end 
441446
442447function  validate_parameter_type (ic:: IndexCache , stype, sz, sym, index, val)
443448    (; portion) =  index
444449    #  Nonnumeric parameters have to match the type
445450    if  portion ===  NONNUMERIC_PORTION
446451        val isa  stype &&  return  nothing 
447-         throw (ParameterTypeException (:validate_parameter_type , sym, stype, val))
452+         throw (ParameterTypeException (
453+             :validate_parameter_type , sym ===  nothing  ?  index :  sym, stype, val))
448454    end 
449455    #  Array parameters need array values...
450456    if  stype <:  AbstractArray  &&  ! isa (val, AbstractArray)
451-         throw (ParameterTypeException (:validate_parameter_type , sym, stype, val))
457+         throw (ParameterTypeException (
458+             :validate_parameter_type , sym ===  nothing  ?  index :  sym, stype, val))
452459    end 
453460    #  ... and must match sizes
454461    if  stype <:  AbstractArray  &&  sz !=  Symbolics. Unknown () &&  size (val) !=  sz
@@ -465,15 +472,16 @@ function validate_parameter_type(ic::IndexCache, stype, sz, sym, index, val)
465472        #  This is for duals and other complicated number types
466473        etype =  SciMLBase. parameterless_type (etype)
467474        eltype (val) <:  etype  ||  throw (ParameterTypeException (
468-             :validate_parameter_type , sym, AbstractArray{etype}, val))
475+             :validate_parameter_type , sym  ===   nothing   ?  index  :  sym , AbstractArray{etype}, val))
469476    else 
470477        #  Real check
471478        if  stype <:  Real 
472479            stype =  Real
473480        end 
474481        stype =  SciMLBase. parameterless_type (stype)
475482        val isa  stype || 
476-             throw (ParameterTypeException (:validate_parameter_type , sym, stype, val))
483+             throw (ParameterTypeException (
484+                 :validate_parameter_type , sym ===  nothing  ?  index :  sym, stype, val))
477485    end 
478486end 
479487
@@ -485,6 +493,9 @@ function indp_to_system(indp)
485493end 
486494
487495function  SymbolicIndexingInterface. remake_buffer (indp, oldbuf:: MTKParameters , idxs, vals)
496+     _remake_buffer (indp, oldbuf, idxs, vals)
497+ end 
498+ function  _remake_buffer (indp, oldbuf:: MTKParameters , idxs, vals; validate =  true )
488499    newbuf =  @set  oldbuf. tunable =  similar (oldbuf. tunable, Any)
489500    @set!  newbuf. discrete =  Tuple (similar (buf, Any) for  buf in  newbuf. discrete)
490501    @set!  newbuf. constant =  Tuple (similar (buf, Any) for  buf in  newbuf. constant)
0 commit comments