opened
cadojo
username_0
When building `CTarget`s, I'm getting an error when a matrix expression has elements that are simply numbers (not variables). 

The following example shows the error I'm getting. 

```Julia
using Symbolics

@variables x[1:3]
skewsymmetric(ω) = [
  0          -ω[3]   ω[2]; 
  ω[3]        0     -ω[1]; 
 -ω[2]        ω[1]   0;
]

build_function(skewsymmetric(x), x; target = Symbolics.JuliaTarget()); # This is fine!
build_function(skewsymmetric(x), x; target = Symbolics.CTarget()); # Produces an error
```

```Julia
ERROR: type Int64 has no field args
Stacktrace:
 [1] getproperty(x::Int64, f::Symbol)
   @ Base ./Base.jl:33
 [2] coperators(expr::Int64)
   @ Symbolics ~/.julia/packages/Symbolics/L5FOZ/src/build_function.jl:380
 [3] |>(x::Int64, f::typeof(Symbolics.coperators))
   @ Base ./operators.jl:859
 [4] _build_function(target::Symbolics.CTarget, ex::Matrix{Num}, args::Vector{Num}; columnmajor::Bool, conv::Function, expression::Type, fname::Symbol, lhsname::Symbol, rhsnames::Vector{Symbol}, libpath::String, compiler::Symbol)
   @ Symbolics ~/.julia/packages/Symbolics/L5FOZ/src/build_function.jl:524
 [5] _build_function(target::Symbolics.CTarget, ex::Matrix{Num}, args::Vector{Num})
   @ Symbolics ~/.julia/packages/Symbolics/L5FOZ/src/build_function.jl:509
 [6] build_function(::Matrix{Num}, ::Vararg{Any, N} where N; target::Symbolics.CTarget, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Symbolics ~/.julia/packages/Symbolics/L5FOZ/src/build_function.jl:52
 [7] top-level scope
   @ REPL[22]:1
```

The stack trace shows the error is found at the `for e in expr.args` line below:
```Julia 
# build_function.jl:377-381

# Replace certain multiplication and power expressions so they form valid C code
# Extra factors of 1 are hopefully eliminated by the C compiler
function coperators(expr)
    for e in expr.args
        if e isa Expr
       ...
```

Happy to submit a PR for this, I think it's a quick fix, but I'm not sure how y'all want the fix to be designed. __Should we restrict `coperators` to types contain `.args` fields? Should we otherwise patch that line in `coperators`?__
ERROR: type <Int64 or Float64, etc.> has no field args
issue
created
ChrisRackauckas
username_1
Is that a Julia Expr? Symbolics doesn't assume `.args` exists, and instead supposes you should do `arguments(ex)`. So that could be one thing.

The other is that arguments aren't defined if it's just a symbol. `:(0)` has no args, while `:(0 + 0)` does. In the generated expressions we might need to special case single symbols.
comment
closed
ChrisRackauckas
username_1
issue