# Strange error message when using maximum()

**URL:** <https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889>\
**Category:** General Usage\
**Tags:** question, error, vector\
**Created:** [November 21, 2024, 10:46am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889 "2024-11-21T10:46:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnldlg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnldlg/32/209465_2.png) [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Post date:** [November 21, 2024, 10:46am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/1 "2024-11-21T10:46:54Z")

</div>

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:**

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

maximum(Na)

```

**Result:**

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

```

and this error:

 ![Screenshot 2024-11-21 113624](https://global.discourse-cdn.com/julialang/original/3X/b/e/be76fba1e872289e0ccf078f3fe77d0164822b6a.png)

Why would a matrix play a role here?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [November 21, 2024, 10:52am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/2 "2024-11-21T10:52:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abraunst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraunst/32/6880_2.png) [@abraunst](https://discourse.julialang.org/u/abraunst)\
**Post date:** [November 21, 2024, 10:53am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/3 "2024-11-21T10:53:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dnldlg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnldlg/32/209465_2.png) [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Post date:** [November 21, 2024, 11:07am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/5 "2024-11-21T11:07:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [November 21, 2024, 11:11am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/6 "2024-11-21T11:11:55Z")

</div>

Load the packages in one by one.

---

<div class="post-metadata">

**Author:** ![abraunst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraunst/32/6880_2.png) [@abraunst](https://discourse.julialang.org/u/abraunst)\
**Post date:** [November 21, 2024, 11:39am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/7 "2024-11-21T11:39:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 21, 2024, 11:40am UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/8 "2024-11-21T11:40:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dnldlg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnldlg/32/209465_2.png) [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Post date:** [November 21, 2024, 1:39pm UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/9 "2024-11-21T13:39:31Z")

</div>

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

```julia
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 ❤ 😅

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 21, 2024, 1:47pm UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/10 "2024-11-21T13:47:17Z")

</div>

> [@dnldlg](#):
>
> `function identity(dim::Int64)::Matrix{Float64}`

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

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 21, 2024, 1:54pm UTC](https://discourse.julialang.org/t/strange-error-message-when-using-maximum/122889/11 "2024-11-21T13:54:12Z")

</div>

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.
