Strange error message when using maximum()

Hello everyone,

I encounter a strange error when using the maximum function on Julia v1.10.6. Let’s look at a variable Na, which is a vector of integers.

Example code:

println(Na)
println(typeof(Na))
println(typeof(Na[1]))

maximum(Na)

Result:

Any[5, 6, 7,  9, 10, 11]
Vector{Any}
Int64

and this error:

Why would a matrix play a role here?

Can’t reproduce. I’m guessing you modified some method in your current Julia session. Can you reproduce in a fresh REPL?

3 Likes

Cannot reproduce on 1.11. You probably have redefined maximum or some other function? Try starting with a fresh session.

2 Likes

It works if I isolate the problem, but throws this error if I import all the packages I’m using.

I personally did not overwrite the function, but could it be that one of the packages does? If so, what would be a good strategy to check this?

1 Like

Load the packages in one by one.

2 Likes

What are the packages? Generally, it would be best if you could you post a minimum working example so we are able to reproduce the problem.

3 Likes

Something is very off. Na is clearly an instance of Vector{Any}, but the stacktrace is claiming the maximum call took an instance of Vector{Int64}. Either type works on v1.10.6. Besides max being called on two Float64 matrices, nothing in the stacktrace is showing any file or module originating from a pirating package.

2 Likes

I managed to isolate the problem with the help of your comments. Within one of my self-written modules I had a function of this form

function identity(dim::Int64)::Matrix{Float64}
   # something
end

and managed to overwrite it with accidentally with Base.identity at another place in the code. That’s why it was comparing matrices in the end…

Thank you for your help and dealing with my stupidity :heart: :sweat_smile:

4 Likes

Aside: you might want the function I(dim) in the LinearAlgebra stdlib.

2 Likes

That makes sense, the piracy didn’t show up in the stacktrace because it didn’t throw an error, it made another call error. Just part of debugging I guess.