@@ -1484,6 +1484,8 @@ function _is_tuple_of_symbolics(O::Tuple)
14841484end
14851485_is_tuple_of_symbolics (O) = false
14861486
1487+ array_literal (sz:: NTuple{N, Int} , args... ) where {N} = reshape (Base. vect (args... ), sz)
1488+
14871489"""
14881490 BSImpl.Const{T}(val) where {T}
14891491
@@ -1500,7 +1502,7 @@ arrays/tuples of symbolics to symbolic expressions.
15001502This is the low-level constructor for constant expressions. It handles several special cases:
150115031. If `val` is already a `BasicSymbolic{T}`, returns it unchanged
150215042. If `val` is a `BasicSymbolic` of a different variant type, throws an error
1503- 3. If `val` is an array containing symbolic elements, creates a `Term` with `hvncat` operation
1505+ 3. If `val` is an array containing symbolic elements, creates a `Term` with [`array_literal`](@ref) operation
150415064. If `val` is a tuple containing symbolic elements, creates a `Term` with `tuple` operation
150515075. Otherwise, creates a `Const` variant wrapping the value
15061508
@@ -1520,15 +1522,15 @@ The `unsafe` flag skips hash consing for performance in internal operations.
15201522 elseif val isa BasicSymbolic{TreeReal}
15211523 error (" Cannot construct `BasicSymbolic{$T }` from `BasicSymbolic{TreeReal}`." )
15221524 elseif val isa AbstractArray && _is_array_of_symbolics (val)
1523- args = ArgsT {T} ((BSImpl. Const {T} (size (val); unsafe), BSImpl . Const {T} ( false ; unsafe) ))
1524- sizehint! (args, length (val) + 2 )
1525+ args = ArgsT {T} ((BSImpl. Const {T} (size (val); unsafe),))
1526+ sizehint! (args, length (val) + 1 )
15251527 type = Union{}
15261528 for v in val
15271529 push! (args, BSImpl. Const {T} (v))
15281530 type = promote_type (type, symtype (v))
15291531 end
15301532 shape = ShapeVecT (axes (val))
1531- return BSImpl. Term {T} (hvncat , args; type = Array{type, ndims (val)}, shape, unsafe)
1533+ return BSImpl. Term {T} (array_literal , args; type = Array{type, ndims (val)}, shape, unsafe)
15321534 elseif val isa Tuple && _is_tuple_of_symbolics (val)
15331535 args = ArgsT {T} ()
15341536 sizehint! (args, length (val))
@@ -2470,7 +2472,7 @@ function TermInterface.maketerm(::Type{BasicSymbolic{T}}, f, args, metadata; @no
24702472 @set! res. metadata = metadata
24712473 end
24722474 return res:: BasicSymbolic{T}
2473- elseif f === hvncat
2475+ elseif f === array_literal
24742476 sh = ShapeVecT ()
24752477 for dim in unwrap_const (args[1 ])
24762478 push! (sh, 1 : dim)
@@ -3998,8 +4000,8 @@ function __stable_getindex(arr::BasicSymbolic{T}, sidxs::StableIndex) where {T}
39984000 sh:: ShapeVecT = shape (arr)
39994001 @match arr begin
40004002 BSImpl. Const (; val) => return Const {T} (scalar_index (val, as_linear_idx (sh, sidxs)))
4001- BSImpl. Term (; f, args) && if f === hvncat end => begin
4002- return args[2 + as_linear_idx (sh, sidxs)]
4003+ BSImpl. Term (; f, args) && if f === array_literal end => begin
4004+ return args[1 + as_linear_idx (sh, sidxs)]
40034005 end
40044006 BSImpl. Term (; f, args) && if f isa TypeT && f <: CartesianIndex end => begin
40054007 return args[as_linear_idx (sh, sidxs)]
@@ -4069,8 +4071,8 @@ end
40694071Base. @propagate_inbounds function _getindex (:: Type{T} , arr:: BasicSymbolic{T} , idxs:: Union{BasicSymbolic{T}, Int, AbstractRange{Int}, Colon} ...) where {T}
40704072 @match arr begin
40714073 BSImpl. Const (; val) && if all (x -> ! (x isa BasicSymbolic{T}) || isconst (x), idxs) end => return Const {T} (val[unwrap_const .(idxs)... ])
4072- BSImpl. Term (; f) && if f === hvncat && all (x -> ! (x isa BasicSymbolic{T}) || isconst (x), idxs) end => begin
4073- return Const {T} (reshape (@view (arguments (arr)[3 : end ]), Tuple (size (arr)))[unwrap_const .(idxs)... ])
4074+ BSImpl. Term (; f) && if f === array_literal && all (x -> ! (x isa BasicSymbolic{T}) || isconst (x), idxs) end => begin
4075+ return Const {T} (reshape (@view (arguments (arr)[2 : end ]), Tuple (size (arr)))[unwrap_const .(idxs)... ])
40744076 end
40754077 BSImpl. Term (; f, args) && if f isa TypeT && f <: CartesianIndex end => return args[idxs... ]
40764078 BSImpl. Term (; f, args) && if f isa Operator && length (args) == 1 end => begin
0 commit comments