JuliaLang / LinearAlgebra.jl

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

StackOverflowError when using LinearAlgebra norm on "wrong" datatypes #1040

Closed TimSiebert1 closed 6 months ago

TimSiebert1 commented 1 year ago

Hey there,

Im not sure if this is really a bug, maybe it is rather a question of handling an error. I obtained an StackOverflowError when using norm from the LinearAlgebra package when applying it for example to a string. See the following code:

using LinearAlgebra
a = "s"
norm(a)

If I understand correctly, the problem occurs (always?) when I use data which is not a Number and the call trace should be the following: norm -> norm2 -> generic_norm2 -> normInf -> generic_normInf -> mapreduce -> mapfoldl -> mapfoldl_impl -> foldl_impl -> _foldr_impl -> op which is again the norm function and closes the loop.

Is it possible to get a more informative error message here? In my opinion it is quite hard to debug. In my case this all occurs when I applied call norm on a custom datatype with arithmetic operations which didn't inherit from Number.

System information:

Julia Version 1.9.3 Commit bed2cd540a1 (2023-08-24 14:43 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: macOS (arm64-apple-darwin22.4.0) CPU: 10 × Apple M2 Pro WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1) Threads: 1 on 6 virtual cores Environment: JULIA_PKG_USE_CLI_GIT = True

jd-foster commented 7 months ago

Trying handling of the specific case of AbstractChar in JuliaLang/julia#54122 , however not necessarily useful for custom datatypes.

jd-foster commented 6 months ago

@TimSiebert1 Since JuliaLang/julia#54122 has been merged, would you be willing to try out your custom datatype code with Julia nightly to test this?

TimSiebert1 commented 6 months ago

Hey @jd-foster

Unfortunately, my package works only for older Julia versions, and I can not try it on those types. However, there is now a better error message and I appreciate that. Thank you!