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

Base.has_fast_linear_indexing needs a method for Ref #41055

Closed
chengchingwen opened this issue Jun 2, 2021 · 2 comments · Fixed by #41072
Closed

Base.has_fast_linear_indexing needs a method for Ref #41055

chengchingwen opened this issue Jun 2, 2021 · 2 comments · Fixed by #41072

Comments

@chengchingwen
Copy link
Member

has_fast_linear_indexingfor Broadcasted check all the arguments,

julia/base/reducedim.jl

Lines 194 to 198 in 58ffe7e

has_fast_linear_indexing(a::AbstractArrayOrBroadcasted) = false
has_fast_linear_indexing(a::Array) = true
has_fast_linear_indexing(::Number) = true # for Broadcasted
has_fast_linear_indexing(bc::Broadcast.Broadcasted) =
all(has_fast_linear_indexing, bc.args)

but broadcasting literal_pow has Base.RefValue{typeof(^)}(^) and Base.RefValue{Val{2}}(Val{2}()) in its argument, which cause MethodError

MWE:

using LazyArrays
bc = @~ x .^ 2 # use LazyArrays to get the Broadcasted object
sum(bc, dims=1) # MethodError for has_fast_linear_indexing(::Base.RefValue{typeof(^)})

versioninfo:

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7800X CPU @ 3.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake-avx512)
Environment:
  JULIA_NUM_THREADS = 8
@stevengj
Copy link
Member

stevengj commented Jun 3, 2021

Sounds like it need a method for RefValue? i.e. just add

has_fast_linear_indexing(bc::Ref) = true

(Note that if I add the above method, or just change your test case to bc = @~ x .+ 2 to avoid literal_pow, then sum(bc, dims=1) gives me a different MethodError, this time for reducedim_init on a Broadcasted object. But that's an unrelated problem—sum(bc, dims=1, init=0.0) succeeds. I see you already filed that as #41054.)

@stevengj stevengj changed the title Broadcast literal_pow break Base.has_fast_linear_indexing Base.has_fast_linear_indexing needs a method for Ref Jun 3, 2021
@stevengj
Copy link
Member

stevengj commented Jun 3, 2021

(It doesn't seem related to literal_pow specifically, so I changed the issue title.)

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

Successfully merging a pull request may close this issue.

2 participants