@@ -335,28 +335,39 @@ Return an array of values where the `i`th element corresponds to the value of `v
335
335
in `varmap`. Does not perform symbolic substitution in the values of `varmap`.
336
336
337
337
Keyword arguments:
338
- - `tofloat`: Convert values to floating point numbers using `float`.
339
- - `container_type`: The type of container to use for the values.
340
- - `toterm`: The `toterm` method to use for converting symbolics.
341
- - `promotetoconcrete`: whether the promote to a concrete buffer (respecting
342
- `tofloat`). Defaults to `container_type <: AbstractArray`.
343
- - `check`: Error if any variables in `vars` do not have a mapping in `varmap`. Uses
344
- [`missingvars`](@ref) to perform the check.
345
- - `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
346
- `promotetoconcrete` is set to `false`.
347
- - `is_initializeprob, guesses`: Used to determine whether the system is missing guesses.
338
+ - `container_type`: The type of the returned container.
339
+ - `allow_symbolic`: Whether the returned container of values can have symbolic expressions.
340
+ - `buffer_eltype`: The `eltype` of the returned container if `!allow_symbolic`. If
341
+ `Nothing`, automatically promotes the values in the container to a common `eltype`.
342
+ - `tofloat`: Whether to promote values to floating point numbers if
343
+ `buffer_eltype == Nothing`.
344
+ - `use_union`: Whether to allow using a `Union` as the `eltype` if
345
+ `buffer_eltype == Nothing`.
346
+ - `toterm`: The `toterm` function for canonicalizing keys of `varmap`. A value of `nothing`
347
+ disables this process.
348
+ - `check`: Whether to check if all of `vars` are keys of `varmap`.
349
+ - `is_initializeprob`: Whether an initialization problem is being constructed. Used for
350
+ better error messages.
348
351
"""
349
352
function better_varmap_to_vars (varmap:: AbstractDict , vars:: Vector ;
350
- tofloat = true , container_type = Array, floatT = Nothing,
351
- toterm = default_toterm, promotetoconcrete = nothing , check = true ,
352
- allow_symbolic = false , is_initializeprob = false )
353
+ tofloat = true , use_union = false , container_type = Array, buffer_eltype = Nothing,
354
+ toterm = default_toterm, check = true , allow_symbolic = false ,
355
+ is_initializeprob = false )
353
356
isempty (vars) && return nothing
354
357
355
358
varmap = recursive_unwrap (varmap)
356
- add_toterms! (varmap; toterm)
359
+ if toterm != = nothing
360
+ add_toterms! (varmap; toterm)
361
+ end
357
362
if check
358
363
missing_vars = missingvars (varmap, vars; toterm)
359
- isempty (missing_vars) || throw (MissingVariablesError (missing_vars))
364
+ if ! isempty (missing_vars)
365
+ if is_initializeprob
366
+ throw (MissingGuessError (collect (missing_vars), collect (missing_vars)))
367
+ else
368
+ throw (MissingVariablesError (missing_vars))
369
+ end
370
+ end
360
371
end
361
372
vals = map (x -> varmap[x], vars)
362
373
if ! allow_symbolic
@@ -372,20 +383,17 @@ function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
372
383
is_initializeprob ? throw (MissingGuessError (missingsyms, missingvals)) :
373
384
throw (UnexpectedSymbolicValueInVarmap (missingsyms[1 ], missingvals[1 ]))
374
385
end
375
- if tofloat && ! (floatT == Nothing)
376
- vals = floatT .(vals)
386
+ if buffer_eltype == Nothing
387
+ vals = promote_to_concrete (vals; tofloat, use_union)
388
+ else
389
+ vals = buffer_eltype .(vals)
377
390
end
378
391
end
379
392
380
- if container_type <: Union{AbstractDict, Tuple, Nothing, SciMLBase.NullParameters}
393
+ if container_type <: Union{AbstractDict, Nothing, SciMLBase.NullParameters}
381
394
container_type = Array
382
395
end
383
396
384
- promotetoconcrete === nothing && (promotetoconcrete = container_type <: AbstractArray )
385
- if promotetoconcrete && ! allow_symbolic
386
- vals = promote_to_concrete (vals; tofloat = tofloat, use_union = false )
387
- end
388
-
389
397
if isempty (vals)
390
398
return nothing
391
399
elseif container_type <: Tuple
0 commit comments