Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

length(::CartesianIndices) errors due to overwritten prod() #523

Closed
rdeits opened this issue Mar 21, 2018 · 1 comment
Closed

length(::CartesianIndices) errors due to overwritten prod() #523

rdeits opened this issue Mar 21, 2018 · 1 comment

Comments

@rdeits
Copy link
Contributor

rdeits commented Mar 21, 2018

Using Compat.jl master:

julia> using Compat

julia> c = CartesianIndices((1:2,))
2-element Compat.CartesianIndices{1,Tuple{UnitRange{Int64}}}:
 CartesianIndex{1}((1,))
 CartesianIndex{1}((2,))

julia> length(c)
ERROR: MethodError: no method matching prod(::Tuple{Int64})
You may have intended to import Base.prod
Closest candidates are:
  prod(::Any, ::AbstractArray; dims) at /home/rdeits/.julia/v0.6/Compat/src/Compat.jl:1723
  prod(::AbstractArray; dims) at /home/rdeits/.julia/v0.6/Compat/src/Compat.jl:1717
Stacktrace:
 [1] length(::Compat.CartesianIndices{1,Tuple{UnitRange{Int64}}}) at /home/rdeits/.julia/v0.6/Compat/src/Compat.jl:1288

The problem is here:

for f in (:mean, :cumsum, :cumprod, :sum, :prod, :maximum, :minimum, :all, :any, :median)

where a new prod() function is declared, rather than extending Base.prod, and then that overwritten version is called here:
length(iter::CartesianIndices) = prod(size(iter))
instead of Base.prod.

Is it intentional that Compat is overwriting rather than extending those functions?

rdeits added a commit to rdeits/RigidBodyTreeInspector.jl that referenced this issue Mar 21, 2018
@martinholters
Copy link
Member

Yes, it's intentional. The call to prod needs to be prefixed with Base. Missed in #518, sorry. (Seems like we're missing a test for that length method.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants