JuliaLang / LinearAlgebra.jl

Julia Linear Algebra standard library
Other
17 stars 4 forks source link

normalize() fails with symbolic arguments #1045

Closed ufechner7 closed 9 months ago

ufechner7 commented 11 months ago

The following code works:

using ModelingToolkit, LinearAlgebra

@variables t pos(t)[1:3] = [0.0, 0.0,  10.0]
pos/norm(pos)

the following code crashes:

using ModelingToolkit, LinearAlgebra

@variables t pos(t)[1:3] = [0.0, 0.0,  10.0]
normalize(pos)

with the following message:

ERROR: TypeError: non-boolean (Num) used in boolean context
Stacktrace:
 [1] copyto!(dest::OffsetArrays.OffsetVector{Num, Vector{Num}}, src::Symbolics.Arr{Num, 1})
   @ Base ./abstractarray.jl:1059
 [2] copymutable_oftype(A::Symbolics.Arr{Num, 1}, ::Type{Num})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/LinearAlgebra.jl:404
 [3] normalize(a::Symbolics.Arr{Num, 1}, p::Int64)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:1881
 [4] normalize(a::Symbolics.Arr{Num, 1})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-rc2+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:1879
 [5] top-level scope
   @ REPL[3]:1

So I think there is an additional method needed for the function normalize() with a vector of symbols as parameter.

julia> versioninfo()
Julia Version 1.10.0-rc2
Commit dbb9c46795b (2023-12-03 15:25 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × AMD Ryzen 9 7950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
  Threads: 1 on 32 virtual cores
Environment:
  LD_LIBRARY_PATH = /lib:/usr/lib:/usr/local/lib
ufechner7 commented 11 months ago

There might be a fix in the works already, see: https://discourse.julialang.org/t/modelingtoolkit-and-normalize/107349/2

stevengj commented 11 months ago

Per the discussion, it seems like this needs to be fixed in Symbolics.jl, not in LinearAlgebra.